Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
cname: ethberlin.ooo
cname: 2022.ethberlin.org
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "node --test --experimental-test-coverage src/data/editions.test.mjs",
"deploy": "echo 'https://2022.ethberlin.org' > ./build/CNAME && gh-pages -d build"
},
"dependencies": {
Expand Down
124 changes: 124 additions & 0 deletions src/components/EditionCounter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* SPDX-FileCopyrightText: 2026 Department of Decentralization
* SPDX-License-Identifier: Unlicense
*
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <https://unlicense.org>
*/

/**
* The edition counter: one digit per ETHBerlin edition under the logo, drawn
* like an LCD display, and a readout that names the edition a digit stands
* for. The other editions' digits link their sites; this site's digit is
* always lit. Facts and strings come from `src/data/editions.mjs`.
*
* @module components/EditionCounter
* @import { Edition } from "../data/editions.mjs"
*/

import React, { useState } from "react";
import { editions, editionUrl, linkText, readout } from "../data/editions.mjs";
import "../styles/edition-counter.css";

/**
* This site's edition, which the readout names while no digit is lit.
*
* @type {Readonly<Edition>}
*/
const current = /** @type {Readonly<Edition>} */ (
editions.find((edition) => edition.current)
);

/**
* The parts of one digit cell: the digit, the hidden link text, and the unlit
* segments. The ghost 8 comes last, so the cell's text reads digit, name and
* year for search engines and screen readers.
*
* @param {object} props Component props.
* @param {Readonly<Edition>} props.edition The edition the cell stands for.
* @returns {JSX.Element} The three parts.
*/
function DigitFace({ edition }) {
return (
<>
<span className="edition-digit__value">{edition.digit}</span>
<span className="sr-only">{` ${linkText(edition)} `}</span>
<span className="edition-digit__ghost" aria-hidden="true">
8
</span>
</>
);
}

/**
* The edition counter. One piece of state, the edition whose digit the
* pointer or keyboard focus is on, lights that digit and switches the readout
* to it, so a digit is lit exactly when the readout names it. The readout is
* one element whose text and colour change: hover adds, removes and reveals
* no element.
*
* @param {object} props Component props.
* @param {boolean} [props.compact] The mobile variant: smaller digits, the
* readout to their right, and no hover or focus state.
* @param {string} [props.className] Classes that place the counter, added to
* its own.
* @returns {JSX.Element} The counter.
*/
export default function EditionCounter({ compact = false, className = "" }) {
const [active, setActive] = useState(
/** @type {Readonly<Edition> | null} */ (null),
);
const layout = compact
? "edition-counter edition-counter--compact flex items-center gap-3 mt-2.5"
: "edition-counter flex flex-col gap-1.5";
return (
<div className={className ? `${layout} ${className}` : layout}>
<div
className={
compact
? "flex gap-2 font-digi text-2xl leading-none"
: "flex gap-[10px] font-digi text-[28px] leading-none"
}
>
{editions.map((edition) =>
edition.current ? (
<span
key={edition.digit}
className="edition-digit"
aria-current="page"
>
<DigitFace edition={edition} />
</span>
) : (
<a
key={edition.digit}
className={
active === edition ? "edition-digit is-lit" : "edition-digit"
}
href={editionUrl(edition)}
target="_blank"
rel="noreferrer"
aria-keyshortcuts={edition.digit}
onMouseEnter={compact ? undefined : () => setActive(edition)}
onMouseLeave={compact ? undefined : () => setActive(null)}
onFocus={compact ? undefined : () => setActive(edition)}
onBlur={compact ? undefined : () => setActive(null)}
>
<DigitFace edition={edition} />
</a>
),
)}
</div>
<div
className={
active
? "edition-counter__readout font-w95 text-sm is-lit"
: "edition-counter__readout font-w95 text-sm"
}
aria-hidden="true"
>
{readout(active ?? current)}
</div>
</div>
);
}
18 changes: 11 additions & 7 deletions src/components/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from "react";
import EditionCounter from "./EditionCounter";
import EthBerlinLogo from "./EthBerlinLogo";
import EthDiamond from "./EthDiamond";
import Seo from "./seo";
Expand Down Expand Up @@ -28,13 +29,16 @@ const Layout = ({ children, showEthDiamond }) => {
<div className="sm:hidden text-berlin-yellow my-8 mx-4">
{/* Header */}
<div className="flex justify-between">
<a style={{ textDecoration: "none" }} href="/">
<EthBerlinLogo
className=""
titleClassName="text-4xl"
subtitleClassName={`text-lg `}
/>
</a>
<div>
<a style={{ textDecoration: "none" }} href="/">
<EthBerlinLogo
className=""
titleClassName="text-4xl"
subtitleClassName={`text-lg `}
/>
</a>
<EditionCounter compact />
</div>
<div className=" flex flex-col flex-grow-0 font-w95 text-berlin-yellow text-2xl leading-3 justify-center">
<button
className="p-2 blur-text-smaller"
Expand Down
2 changes: 2 additions & 0 deletions src/components/Sidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import EditionCounter from "./EditionCounter";
import EthBerlinLogo from "./EthBerlinLogo";

const Sidebar = ({ className, hideLogo }) => {
Expand All @@ -13,6 +14,7 @@ const Sidebar = ({ className, hideLogo }) => {
>
<EthBerlinLogo titleClassName="text-5xl" subtitleClassName="" />
</a>
<EditionCounter className="absolute top-[124px] left-6" />
{/* 5.5rem to align with the Latout main content box */}
<nav className="flex flex-col mt-[5.5rem] text-xl text-left">
<a className="my-2" href="/about">
Expand Down
116 changes: 116 additions & 0 deletions src/data/editions.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* SPDX-FileCopyrightText: 2026 Department of Decentralization
* SPDX-License-Identifier: Unlicense
*
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <https://unlicense.org>
*/

/**
* The four ETHBerlin editions of the edition counter, and every string the
* counter and its keyboard keys use. Each edition's facts are written here
* once; links, readouts, link texts and the key map are made from them.
*
* @module data/editions
*/

/**
* One ETHBerlin edition.
*
* @typedef {object} Edition
* @property {string} digit The edition's digit in the counter, which is also
* its keyboard key.
* @property {string} name Edition name, as the edition's own site titles
* itself.
* @property {number} year Year the edition took place.
* @property {string} host Host name of the edition's site.
* @property {boolean} current Whether this site is the edition's site.
*/

/**
* The editions in counter order. The names come from each edition's own site:
* the `<title>` of `ethb3rlin/1` and `ethb3rlin/2`, this site's name, and the
* `siteMetadata.title` of `ethb3rlin/4`.
*
* @type {ReadonlyArray<Readonly<Edition>>}
*/
export const editions = Object.freeze(
[
{
digit: "1",
name: "ETHBerlin",
year: 2018,
host: "2018.ethberlin.org",
current: false,
},
{
digit: "2",
name: "ETHBerlin ZWEI",
year: 2019,
host: "2019.ethberlin.org",
current: false,
},
{
digit: "3",
name: "ETHBerlin³",
year: 2022,
host: "2022.ethberlin.org",
current: true,
},
{
digit: "4",
name: "ETHBerlin04",
year: 2024,
host: "ethberlin.org",
current: false,
},
].map((edition) => Object.freeze(edition)),
);

/**
* An edition's link target: its site, without a trailing slash.
*
* @param {Readonly<Edition>} edition An edition.
* @returns {string} For example `https://2019.ethberlin.org`.
*/
export function editionUrl(edition) {
return `https://${edition.host}`;
}

/**
* The counter's readout for an edition: its name and year.
*
* @param {Readonly<Edition>} edition An edition.
* @returns {string} For example `ETHBerlin ZWEI · 2019`.
*/
export function readout(edition) {
return `${edition.name} · ${edition.year}`;
}

/**
* The visually hidden text after an edition's digit, which search engines and
* screen readers read as the link's text. This site's edition says so.
*
* @param {Readonly<Edition>} edition An edition.
* @returns {string} For example `ETHBerlin ZWEI 2019`, or
* `ETHBerlin³ 2022, this site` for this site's edition.
*/
export function linkText(edition) {
const text = `${edition.name} ${edition.year}`;
return edition.current ? `${text}, this site` : text;
}

/**
* The keyboard keys of the other editions, each mapped to that edition's
* link. `src/html.js` writes this map into its key handler at build time.
*
* @returns {Record<string, string>} For example
* `{ "1": "https://2018.ethberlin.org", ... }`, without this site's key.
*/
export function editionKeys() {
return Object.fromEntries(
editions
.filter((edition) => !edition.current)
.map((edition) => [edition.digit, editionUrl(edition)]),
);
}
81 changes: 81 additions & 0 deletions src/data/editions.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* SPDX-FileCopyrightText: 2026 Department of Decentralization
* SPDX-License-Identifier: Unlicense
*
* This is free and unencumbered software released into the public domain.
* For more information, please refer to <https://unlicense.org>
*/

/**
* Unit tests for `editions.mjs`: the facts, and every string the edition
* counter and its keyboard keys use. Run with `npm test`.
*
* @module data/editions.test
*/

import assert from "node:assert/strict";
import { test } from "node:test";
import {
editionKeys,
editions,
editionUrl,
linkText,
readout,
} from "./editions.mjs";

test("lists the four editions in counter order, frozen", () => {
assert.deepEqual(
editions.map((edition) => edition.digit),
["1", "2", "3", "4"],
);
assert.ok(Object.isFrozen(editions));
assert.ok(editions.every((edition) => Object.isFrozen(edition)));
});

test("marks this site's edition, and only that one, as current", () => {
assert.deepEqual(
editions
.filter((edition) => edition.current)
.map((edition) => edition.name),
["ETHBerlin³"],
);
});

test("links each edition's site without a trailing slash", () => {
assert.deepEqual(editions.map(editionUrl), [
"https://2018.ethberlin.org",
"https://2019.ethberlin.org",
"https://2022.ethberlin.org",
"https://ethberlin.org",
]);
});

test("readouts name the edition and its year", () => {
assert.deepEqual(editions.map(readout), [
"ETHBerlin · 2018",
"ETHBerlin ZWEI · 2019",
"ETHBerlin³ · 2022",
"ETHBerlin04 · 2024",
]);
});

test("link texts name the edition and its year; this site says so", () => {
assert.deepEqual(editions.map(linkText), [
"ETHBerlin 2018",
"ETHBerlin ZWEI 2019",
"ETHBerlin³ 2022, this site",
"ETHBerlin04 2024",
]);
});

test("keys 1, 2 and 4 map to the other editions' links; 3 has none", () => {
assert.deepEqual(editionKeys(), {
1: "https://2018.ethberlin.org",
2: "https://2019.ethberlin.org",
4: "https://ethberlin.org",
});
assert.equal(
JSON.stringify(editionKeys()),
'{"1":"https://2018.ethberlin.org","2":"https://2019.ethberlin.org","4":"https://ethberlin.org"}',
);
});
Loading
Loading