diff --git a/DESIGN.md b/DESIGN.md index b9f6213..cf45a39 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -1,97 +1,82 @@ # Design -One page, built by `build.py` from `site.json`. The page has one vertical axis: the left edge of -the weave in the header. Every section starts its text there. +One design system for the four sites: machine-made, openfluids, BoringQuantSystems and type. This generator builds +the first three; the type site copies the same `src/system.css`. The stylesheet is the specification: its header +comment lists the scale, the spacing, the grid and the four uses of the accent. A house sets only its six colours, +its face, its banner, its bar-2 labels and its groups (`site.json`). -## Grid +## Page -- Two columns on screens 720 px and wider. The left column ends at `--split` (34.091% of the - width). The right column holds the content. Below 720 px, one column. -- Maximum width 1280 px. Side margins 16, 24 and 32 px. -- Spacing scale: 4, 8, 16, 24, 32, 48, 64, 96, 128 px. Sections are 96 or 128 px apart. -- Every section starts with a faint row of dots across the full width (see Rows of dots). -- Below 720 px the header is one column: the mark, the name, the lines and the weave, cropped to its right part so it fills the width. +From top to bottom, the same on every house: -## Type +1. Bar 1: the four sites, in the same order and face everywhere. The current site is marked, not linked. +2. Bar 2: the house logo (the mark on machine-made, the organisation avatar elsewhere) and one link per group, + then GitHub. It sticks to the top; its bottom line appears after the first scroll. +3. The banner, in the h1, with the house name as its alt text. It loads first. +4. The house line, in the house face. +5. Latest: the newest release of each repository, distinct repositories, newest first, at most three. +6. The groups: a label (the 3 x 3 section mark and the title) and the plates. A plate is the repository banner as + a link, one line (with a site or docs link when the project has one) and the live facts: language, latest + release or "unreleased", last commit. +7. The houses: the other two houses and the type site, each with its banner, its line and its newest release. +8. The footer: the four sites on one line. -- machine-made Weft for the top bar, the group labels and the footer, and for the text of machine-made.github.io; - machine-made Sans for the text of openfluids.github.io; machine-made Warp for the text of - boringquantsystems.github.io. All are machine-made typefaces (github.com/machine-made/type, SIL Open Font - License 1.1), served from `docs/fonts/` with `font-display: swap`. Each page preloads the regular face of - Weft and of its text font. -- The fonts are the full variable woff2 files of the 0.2.0 releases, copied unchanged: Weft wght 100 to 900 - and FRAG 0 to 100, Sans wght 200 to 800 (README, Fonts). -- Weft has one advance for every glyph, 750 units, and narrow ink, so it sets wide. Mono type has - negative tracking: -0.08 em on the name, -0.06 em on headings, -0.03 em on project names and - small text. Sans has a narrow word space, so reading text has 0.05 em of word spacing. -- The name has FRAG 12: ink-trap notches, inside the range that the type repository proves for - text (0 to 15). All other text has FRAG 0. -- Scale 1.25 on a 17 px base: 13.6, 17, 21.25, 26.6 px. The name is fluid: 30 to 48 px on small screens, 24 to 52 px beside the weave. -- Sentence case. No capitals for emphasis. -- Body copy is capped at 34rem (the larger intro at 36rem), so a line has fewer than 70 characters. - `shots.py` counts the longest line at every width and fails at 70 or more. +The 404 page has the same bars and footer, "Not found" in the house face and a link home. GitHub Pages serves it +at any depth, so its addresses start at the site root. -## Colour +## Grid and spacing -- Light: white ground, black type, grey 595959 for small text, grey D9D9D9 for rules. -- Dark: black ground, white type, grey A6A6A6, grey 2E2E2E. -- One accent, red E5251C, the same in both schemes. It appears twice: the red square in the - mark and the red cell in the weave. It never colours text. -- The weave, the mark and the rows of dots follow the system scheme through a media query inside - the SVG. +- 12 columns, 24 px gutter, content 1200 px at most. Side margins 16, 24 and 32 px. +- A row puts its label in columns 1 to 3 and its content in columns 4 to 12; below 860 px both take the full width. +- Plates: three columns, two below 1000 px, one below 520 px. Images are 3:1. +- Spacing: 4, 8, 12, 16, 24, 32, 48, 64, 96 px (`--sp-1` to `--sp-9`), nothing else. -## Mark +## Type -A 3 by 3 grid of squares. The centre square is red. It is the favicon, it stands above the name -in the header and it is the avatar: on white, with about 18% padding. `card.py` draws it for the -site and for `brand.py`, so they match. +- Weft for the bars, the labels, the facts and the footer. Sans for all reading text. The house line in the house + face: Weft on machine-made, Heddle on openfluids, Warp on BoringQuantSystems. +- One scale, ratio 1.25 on 16 px: steps -1 to 5 (12.8 to 48.8 px). The house line is fluid between steps 2 and 3. +- The fonts are machine-made, version 0.2.0 (README, Fonts). Each page ships a subset of each font it uses, with + every variation axis and every feature the style asks for, and preloads the house face. +- Weights stay inside the range of the variable font, so no weight is faked. No italic. -## Hero: how the weave is made +## Colour + +Six colours per house: ground, surface, line, text, muted, accent. Text on the ground and on the surface is at +least 7:1, muted text at least 4.5:1, the accent at least 3:1 on the ground. The accent has four uses: the bar-1 +marker, the bar-2 marker, the centre cell of the section mark, the link underline. It never colours text. -The weave is a Jacquard cloth. Each thread is set by a draft, as on a Jacquard loom. +| House | Ground | Surface | Line | Text | Muted | Accent | +| --- | --- | --- | --- | --- | --- | --- | +| machine-made | #0a0a0b | #141416 | #26262a | #ecebe6 | #8b8b90 | #e5251c | +| openfluids | #0d1116 | #141a21 | #252c33 | #e6eef2 | #8395a0 | #5cc8d6 | +| BoringQuantSystems | #050507 | #0e0e11 | #1f1f23 | #ecebe6 | #8b8b90 | #3ddc97 | -1. Seed. SHA-256 of the name; the first 8 bytes seed a splitmix64 generator. The same name - always gives the same cloth. There is no other source of randomness. -2. Frame. 1408 by 469 px. A thread cell is 4 px, so the cloth is 352 by 116 threads. The cloth - starts at x = 480 px. The left third of the frame stays empty for the name. -3. Motif. A pixel is 4 by 4 threads. The cloth is 58 by 29 pixels. The generator picks a half - tile of 3 to 7 pixels and a distance rule (square, diamond or octagon). Rings 1 to 3 pixels - wide alternate between two levels; a 1 pixel ring of a third level appears one time in three; - one pixel in 16 flips. The tile is mirrored on both axes about the centre of the cloth. -4. Draft. Level 0 is weft-faced satin: a warp thread is up one time in 5 or 8. Level 2 is the - complement, warp-faced. Level 1 is a twill. Satin step and twill width come from the seed. -5. Drawing. Each level is one SVG pattern that holds one repeat of its draft: warp threads in - ink, weft threads in light grey. The motif masks are merged rectangles that use the patterns. -6. Red cell. The generator picks a 2 by 2 pixel block of one level and draws it from the same - draft, with red threads. There is at most one. +## Images -Result: about 4 KB per hero. The same input gives identical bytes. +Every plate and banner ships as AVIF and JPEG at two widths (352 and 704 px for a plate, 704 and 1408 px for a +banner) with `srcset` and `sizes`; images below the fold load lazily. `og.jpg` is the banner on the house ground at +1200 by 630. Icons: the mark (`mark.svg`) on machine-made, the organisation avatar elsewhere, and a 180 px touch icon. -## Rows of dots +## Mark -The punched card is a detail, not the identity. Each section rule is one faint row of dots that -encodes the section title, and the footer rule encodes the site name. 7 slots a character, one -empty slot between characters, 8 px a slot. A big dot is a 1 bit and a small dot is a 0 bit; the -top slot is the high bit of the 7-bit ASCII code. The row is decorative: `aria-hidden`, empty -alt, in the rule colour, with no accent. It is cropped on a narrow screen, not scaled. -`check_site.py` reads the dots back and compares the text. +A 3 by 3 grid of squares. The centre square is red. It is the favicon of machine-made, the logo in its bar 2 and, +small, the section mark before every label. `card.py` draws it for the site and for `brand.py`, so they match. ## Profile hero -The GitHub profile hero (`brand.py`) is the one place the whole card shows: the header of the -site with the square mark, the name and the lines on the left, and a punched card on the right. -The card has seven rows and one column per character, a cut top-left corner, holes for the 1 -bits, and one red dot in the lowest 1 bit of the last column. It encodes "Made by machines. -Proven for machines." (38 columns). The caption, in small mono, says so. +The GitHub profile hero (`brand.py`) is the one place the whole punched card shows: the square mark, the name and +the lines on the left, and a punched card on the right. The card has seven rows and one column per character, a +cut top-left corner, holes for the 1 bits, and one red dot in the lowest 1 bit of the last column. It encodes +"Made by machines. Proven for machines." (38 columns). The caption, in small mono, says so. ## Quality bar -- Semantic HTML: header, main, sections with h2, lists, footer. One h1. -- Skip link first. Visible focus ring. Alt text on every image. -- Contrast: black on white 21:1, grey 595959 on white 7:1, white on black 21:1, grey A6A6A6 on - black 8.6:1. The gate computes these. -- No script. No tracking. External requests: none. `check_site.py` fails on any external - stylesheet, font, preload or css url, and `shots.py` fails when the page asks for any file - outside `docs/`. -- No horizontal scroll from 320 px to 1920 px. `shots.py` measures it at 320, 360, 375, 720, 1000, - 1440 and 1920 px, in light and dark. +- Semantic HTML: bars, main, sections with h2, lists, footer. One h1, no skipped heading level. +- Skip link first. Visible focus ring in the accent. Alt text on the banner; every other image is decorative and its + link carries the name. +- No script. No tracking. No external request: `check_site.py` fails on any external stylesheet, font, preload or + CSS url, and `shots.py` fails when the page asks for a file outside the site. +- No horizontal scroll from 320 px to 1920 px, and no element past the right edge outside a scrolling box. +- No glyph drawn in a system font, at 390 and 1280 px, on the home page and the 404 page. +- Every link at least 44 px high at 390 px. diff --git a/README.md b/README.md index 4aa0ba0..3d24736 100644 --- a/README.md +++ b/README.md @@ -1,96 +1,102 @@ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) -`machine-made.github.io` is the machine-made website: one page and one `llms.txt`, built from `site.json`. +`machine-made.github.io` is the machine-made website and the generator of the three house sites (machine-made, +openfluids, BoringQuantSystems): one page, a 404 page and one `llms.txt` per house, built from `site.json` and the +live GitHub facts of each project. > **Status: live at https://machine-made.github.io/.** ## Build +The build cuts font subsets (fontTools, brotli) and encodes images (Pillow), so it runs under `uv` with pinned +versions; the browser checks need Playwright. `gh` must be signed in: the build reads the GitHub API. + ``` -python3 build.py # writes docs/ -python3 check_site.py # prints OK, or one line per failure -python3 check_site.py --self-test # breaks a copy of docs/ and checks that each break is caught -sh gate.sh # build twice and compare, self-tests, check, forbidden words -python3 shots.py # screenshots at 390 and 1280 px and the layout, font and tap-target checks; needs Playwright +UV="uv run --with fonttools==4.68.0 --with brotli==1.2.1 --with pillow==13.0.0" +python3 fetch.py facts.json # the GitHub facts of every project; fails on any API error +$UV python3 build.py --data facts.json # writes docs/; without --data it runs fetch.py itself +$UV python3 check_site.py --data facts.json # prints OK, or one line per failure +$UV python3 check_site.py --data facts.json --self-test # breaks a copy of docs/ and checks that each break is caught +uv run --with playwright==1.65.1 python3 shots.py --chrome PATH --axe axe.min.js # shots and the browser checks +sh gate.sh # one fetch, every house built twice and compared, self-tests, checks, browser checks, forbidden words python3 brand.py --fonts brand-fonts # the profile hero and the avatar in brand/; needs Playwright, fontTools, brotli MM_FONTS=brand-fonts sh gate.sh # the gate, with brand/ built twice and compared ``` -`build.py`, `card.py` and `check_site.py` use only the Python 3.11 standard library. The build is -deterministic: the same source tree gives the same bytes. +`gate.sh` reads `MM_CHROME` (the browser for `shots.py`), `MM_AXE` (axe.min.js; runs axe-core on every page) and +`MM_SHOTS=0` (skip the browser checks). A failed fetch stops the build before any file is written, so a stale page +cannot ship. The build is deterministic: the same source tree and the same facts file give the same bytes. ## Files | Path | Holds | | --- | --- | -| `site.json` | The content: name, line, subtitle line, the project groups, papers, lab log entries, houses | -| `card.py` | The marks: the square logo, the punched card of the profile hero and the rows of dots. The palette | -| `build.py` | The generator: page, style, `llms.txt`, the weave; uses `card.py` | +| `site.json` | The machine-made house: name, owner, line, the six colours and the face, the groups with their bar-2 labels, the four sites, redirects | +| `src/system.css` | The one stylesheet of the four sites: tokens and components. `build.py` writes it into each page without its comments | +| `fetch.py` | The GitHub facts: language, latest release, releases and last commit of every project, and the newest release of each type family | +| `build.py` | The generator: the home page, the 404 page, `llms.txt`, font subsets, image variants, `og.jpg`, icons | +| `card.py` | The marks: the square logo and the punched card of the profile hero. The palette | | `brand.py` | The GitHub profile hero and the avatar, drawn from `card.py` and `brand-fonts/`. Writes `brand/` | -| `fonts/` | The machine-made web fonts (Weft, Sans, Warp 0.2.0) and their licences. `build.py` copies the fonts each site uses to `docs/fonts/` | -| `brand-fonts/` | The 0.1 cut of Weft and Sans that `brand.py` draws the hero from, with their licences. Only `brand.py` reads it; the sites do not ship it | +| `fonts/` | The machine-made web fonts (Weft, Sans, Heddle, Warp 0.2.0), their licences and `SOURCES.json` | +| `brand-fonts/` | The 0.1 cut of Weft and Sans that `brand.py` draws the hero from, with their licences. Only `brand.py` reads it | | `brand/` | The profile hero (light and dark: SVG, PNG, PNG @2x) and `avatar.png`. Do not edit by hand | -| `src/style.css` | The style. `build.py` adds the colours and writes `docs/style.css` | +| `img/org/` | The banner of each house (1408 x 469) and the avatar of openfluids and BoringQuantSystems (360 x 360) | +| `img/repo/` | The banner of each project (704 x 235) | | `check_site.py` | The checks for the built site | | `gate.sh` | The gate | -| `shots.py` | Screenshots at 390 px and 1280 px, the scroll check, the line-length check, the font, plate-geometry and tap-target checks. Writes `shots/` | -| `DESIGN.md` | The grid, the type, the colour, the mark, the weave and the rows of dots | -| `docs/` | The built site. Do not edit by hand | +| `shots.py` | Screenshots at 390 and 1280 px and the browser checks (README, Build; the docstring lists them). Writes `shots/` | +| `DESIGN.md` | The page, the grid, the type, the colour, the images and the mark | +| `docs/` | The built machine-made site. Do not edit by hand | | `houses//site.json` | A house site from this same generator: openfluids, boringquantsystems | | `houses//allow.json` | That house's public list, kept apart from its `site.json`: the checks pass only when both agree | | `publish.sh` | Builds one house into the `docs/` of its own Pages repository. `gate.sh` builds and checks every house | ## Houses -One generator, one look, one tab row for every house. A house site is its `site.json` and its -`allow.json` in `houses/`. `gate.sh` builds each house twice, compares the bytes and runs its -checks. `publish.sh` writes the built site into the house's own Pages repository; that change -lands there through a pull request. +One generator, one design, one bar 1 for every house. A house site is its `site.json` and its `allow.json` in +`houses/`. Each page shows the other two houses and the type site in its houses row, so a build reads the +`site.json` of every house. `gate.sh` builds each house twice from one fetch, compares the bytes and runs its +checks. `publish.sh` writes the built site into the house's own Pages repository; that change lands there through a +pull request. ## Fonts Every page is set in machine-made typefaces only, from [machine-made/type](https://github.com/machine-made/type) -(https://machine-made.github.io/type/), all at version 0.2.0. machine-made Weft sets the top bar, the labels and -the footer on every site, and the text of machine-made.github.io. machine-made Sans sets the text of -openfluids.github.io. machine-made Warp sets the text of boringquantsystems.github.io. machine-made Sans is -based on Plus Jakarta Sans (see its licence file). All are under the SIL Open Font License 1.1; the licences -are `fonts/mm-weft-OFL.txt`, `fonts/mm-sans-OFL.txt` and `fonts/mm-warp-OFL.txt`, and the build ships each next to -its fonts in `docs/fonts/`. - -`fonts/` holds the woff2 files of the 0.2.0 releases, unchanged: each file has the SHA-256 digest that the release -publishes for its asset, and the type site serves the same bytes. The build copies them; it does not cut or change -them. `check_site.py` pins the SHA-256 of each file and fails on a page that declares another font family, loads another font file, or ships a -machine-made file that is not the 0.2.0 one. To update, copy the new files into `fonts/`, change the hashes in -`FONT_SPECS` of `check_site.py` and the table below. +(https://machine-made.github.io/type/), all at version 0.2.0. Weft sets the bars, the labels, the facts and the +footer; Sans sets the reading text; the house line is in the house face (Weft, Heddle or Warp). machine-made Sans is +based on Plus Jakarta Sans (see its licence file). All are under the SIL Open Font License 1.1; the build ships the +licence of each font it uses next to it in `docs/fonts/`. + +`fonts/` holds the release files, unchanged; `fonts/SOURCES.json` records the release, the asset, the size and the +SHA-256 of each, and `check_site.py` pins the same hashes in `SOURCES`. The build cuts one subset per font and page: +the characters of the page (and their capitals, since labels are set in capitals), every layout feature that still +acts on them and every variation axis. The build fails when a subset loses an axis or a feature the style uses +(ss01, tabular, old-style and proportional figures, small capitals, kerning); `check_site.py` checks the same on the +files in `docs/fonts/`, and that every character the page sets in a font is in its subset. To update, copy the new +release files into `fonts/` and change `SOURCES.json`, `SOURCES` in `check_site.py` and the table below. | File | Family, version | Release asset (machine-made/type) | Bytes | SHA-256 | | --- | --- | --- | --- | --- | | `fonts/mm-weft.woff2` | machine-made Weft 0.2.0, variable (wght 100 to 900, FRAG 0 to 100) | `weft-v0.2.0`, `MachineMadeWeft.FRAG.wght.woff2` | 77,208 | `9115be68c727ae8c707eed1097f878fd7e7bd54fa75bd70b099e94e4e5e71e85` | | `fonts/mm-sans.woff2` | machine-made Sans 0.2.0, variable (wght 200 to 800) | `sans-v0.2.0`, `MachineMadeSans.wght.woff2` | 73,236 | `8ec52cf1b8a799dcda3aab4cf967d681cbd8bffd3f4cb581ed4e5ffa72e0864e` | +| `fonts/mm-heddle.woff2` | machine-made Heddle 0.2.0, variable (wght 100 to 900, wdth 70 to 140) | `heddle-v0.2.0`, `MachineMadeHeddle.wdth.wght.woff2` | 77,600 | `3f7d0bde0d436dc800abc9b9c760938f38f19c627cc3378bb199032c3a6ec0e1` | | `fonts/mm-warp-regular.woff2` | machine-made Warp 0.2.0, Regular | `warp-v0.2.0`, `MachineMadeWarp-Regular.woff2` | 82,732 | `035042b467e6c138666b2e6b3b3a38eeb8d6dc3602ac4354f1e335e425101481` | -| `fonts/mm-warp-italic.woff2` | machine-made Warp 0.2.0, Italic | `warp-v0.2.0`, `MachineMadeWarp-Italic.woff2` | 67,688 | `4eb9d3abbff429bfc6130fb82790876e8416fe65bab69f11e2d7c35d693d6d53` | - -Sans is loaded as roman only: no page uses italic. Warp has no bold in use. The page sets no bold and no -italic, so no face is faked. `shots.py` checks the computed family, weight and style of every text element. -The files are the full fonts, not a cut. `brand/` was drawn from the 0.1 cut of Weft and Sans, which stays in -`brand-fonts/` so that `brand.py` still reproduces `brand/`. Rebuilding `brand/` from the 0.2.0 fonts changes the -profile images and is a separate change. +`brand/` was drawn from the 0.1 cut of Weft and Sans, which stays in `brand-fonts/` so that `brand.py` still +reproduces `brand/`. Rebuilding `brand/` from the 0.2.0 fonts changes the profile images and is a separate change. ## Rules -- The page shows the name, the line, the subtitle line, the public projects. -- Only public repositories are named or linked. A new public project needs an entry in - `site.json` and in `PUBLIC_REPOS` in `check_site.py`. -- `check_site.py --deny FILE`, or `MM_DENY_FILE=FILE sh gate.sh`, also rejects any name listed - in FILE. Keep FILE outside this repository. -- The Lab log section lists each entry with a status, like Papers. `LOG` in `check_site.py` is the - allowed list. Drafts of posts and the data behind them do not go in this repository. An entry - appears here only after the owner has approved its text. +- The page shows the house line, the public projects with their live facts, Latest and the houses. +- Only public repositories are named or linked. A new public project needs an entry in `site.json` and in the + house's `allow.json`. `homebrew-tap` is never listed. +- `check_site.py --deny FILE`, or `MM_DENY_FILE=FILE sh gate.sh`, also rejects any name listed in FILE. Keep FILE + outside this repository. - No script, no tracking, no personal names, no costs. ## Licence Apache-2.0. See [LICENSE](LICENSE). -The fonts in `fonts/` stay under the SIL Open Font License 1.1. See `fonts/mm-sans-OFL.txt`, `fonts/mm-warp-OFL.txt` and `fonts/mm-weft-OFL.txt`. +The fonts in `fonts/` stay under the SIL Open Font License 1.1. See `fonts/mm-heddle-OFL.txt`, `fonts/mm-sans-OFL.txt`, +`fonts/mm-warp-OFL.txt` and `fonts/mm-weft-OFL.txt`. diff --git a/STATUS.md b/STATUS.md index f110f3d..99ca672 100644 --- a/STATUS.md +++ b/STATUS.md @@ -7,7 +7,7 @@ | Line | identity | | Visibility | public | | Stage | live | -| Gate now | `sh gate.sh` passes; `MM_FONTS=brand-fonts sh gate.sh` needs a Playwright browser and was not run for this change | +| Gate now | `sh gate.sh` passes with `MM_CHROME` and `MM_AXE` set (one fetch, three houses, self-tests, browser checks); `MM_FONTS=brand-fonts sh gate.sh` was not run for this change | | Next task | Update the fonts when machine-made/type releases a new version | | Blocked by | nothing | | Last green CI | none yet | @@ -16,24 +16,20 @@ ## Proven - Live at https://machine-made.github.io/, served by GitHub Pages from `docs/` on main. - Checked on 2026-11-19 with `shots.py` on the built site: the page loads machine-made Weft from `docs/fonts/`. -- Two builds give byte-identical files, fonts included. -- `check_site.py` passes: the HTML parses, every local link and image resolves, the banner has - alt text and each plate image is decorative (alt="") beside a named link, contrast is at least 4.5:1 for text and 3:1 for accent marks, one accent colour, and only the public projects and the two houses are linked. The old /chaos-atlas/ path forwards to https://openfluids.github.io/chaos-atlas/ and /dynachaos/ to https://github.com/openfluids/dynachaos. -- The page makes no external request. Every site uses machine-made fonts only, version 0.2.0: Weft, and Sans or Warp - for the text of openfluids and BoringQuantSystems. They are files in `docs/fonts/` with their licences. - `check_site.py` fails on any external stylesheet, preload, font or css url, on a font family or file that is not - machine-made, on a machine-made file that is not the 0.2.0 one (SHA-256), on an `@font-face` without - `font-display: swap`, and on bold or italic that no loaded face provides. `shots.py` records every request and - fails on one outside `docs/`. -- `fonts/` holds the release files unchanged (README, Fonts). -- The header shows the weave and the square mark, with one red accent. Every row of dots encodes its - section title; the checker reads the dots back and compares the text. -- `brand/` was drawn by `brand.py` from the 0.1 cut, now in `brand-fonts/`. The brand gate - (`MM_FONTS=brand-fonts sh gate.sh`) was last run before the 0.2.0 change and was not run for it. -- Screenshots at 1280 px and 390 px, in the site's own fonts (`shots.py` checks that the fonts the - text uses loaded). No horizontal scroll from 320 px to 1920 px. Longest line of copy under 70 - characters. +- The three house sites share one design system, `src/system.css`, from the approved design of 19 Nov: two bars, + the banner, the house line, Latest, the plates with live GitHub facts, the houses row, the footer, a 404 page. +- One GitHub fetch per gate; two builds of every house from it give byte-identical files, fonts and images included. + A failed fetch stops the build before any file is written. +- `check_site.py` passes on every house: the HTML parses, every local link, image and srcset resolves, the facts, + Latest and the houses row match the fetched data, contrast is at least 7:1 for text and 4.5:1 for muted text on + the ground and the surface, every size is a step of the type scale and every spacing a token of the spacing + scale, only the public projects and the four sites are linked. The old /chaos-atlas/ path forwards to + https://openfluids.github.io/chaos-atlas/ and /dynachaos/ to https://github.com/openfluids/dynachaos. +- Every site uses machine-made fonts only, version 0.2.0, as subsets cut from the release files that `fonts/SOURCES.json` + and `check_site.py` pin by SHA-256; every subset keeps its axes and the features the style uses. +- `shots.py` passes on every house: no sideways scroll from 320 to 1920 px, no glyph in a system font, no facts line + wraps at 1280 px, every link at least 44 px high at 390 px, axe-core 0 violations on the home page and the 404 page. +- `brand/` was drawn by `brand.py` from the 0.1 cut, now in `brand-fonts/`. ## Open risks @@ -41,6 +37,7 @@ cut, kept in `brand-fonts/`; `brand/` was not rebuilt (README, Fonts). - Weft has no hinting. Small mono text (project names, footer) can look soft on Windows at low resolution. -- Weft covers Latin-1 only. A project name or line with other letters falls back to the system - monospace for those letters. +- Weft covers Latin-1 only. A project name or line with other letters would fall back to a system font; + `shots.py` fails on that. +- The facts are as fresh as the last build: the site changes only when someone builds and publishes it. - There is no CI in this repository. The gate (`sh gate.sh`) runs by hand before each merge. diff --git a/allow.json b/allow.json index 71d8552..8d399bd 100644 --- a/allow.json +++ b/allow.json @@ -2,13 +2,14 @@ "owner": "machine-made", "self": "machine-made", "line": "A home-built, asynchronous factory for scientific software.", - "blurb": "In 1804 the Jacquard loom wove patterns read from punched cards. The pattern came from a person; the cloth came from the machine. The name and the mark come from those cards.", "theme": { "ground": "#0a0a0b", + "surface": "#141416", + "line": "#26262a", "text": "#ecebe6", "muted": "#8b8b90", "accent": "#e5251c", - "font": "machine-made Weft" + "face": "weft" }, "sites": [ [ diff --git a/brand.py b/brand.py index 692b384..daeaff2 100644 --- a/brand.py +++ b/brand.py @@ -147,7 +147,7 @@ def main() -> None: parser.add_argument("--fonts", type=Path, required=True) parser.add_argument("--out", type=Path, default=ROOT / "brand") args = parser.parse_args() - site = build.load_site() + site = build.load_site(ROOT / "site.json") args.out.mkdir(parents=True, exist_ok=True) jobs: list[tuple[str, str, int, int]] = [] modes: tuple[card.Mode, ...] = ("light", "dark") diff --git a/build.py b/build.py index 975a595..16e3aa1 100644 --- a/build.py +++ b/build.py @@ -1,110 +1,87 @@ #!/usr/bin/env python3 -"""Build a house website: site.json in, docs/ out. Standard library only. +"""Build a house website: site.json and the GitHub facts in, docs/ out. -The page is the house banner, the house line beside one paragraph on the name, and the projects as -plates (the repository banner as a link to the repository, and one line), under small group labels. + uv run --with fonttools==4.68.0 --with brotli==1.2.1 --with pillow==13.0.0 python3 build.py [--site DIR] [--data FILE] + +--site DIR the folder that holds site.json; the site goes to DIR/docs. Default: this repository (machine-made). +--data FILE the GitHub facts that fetch.py wrote. Without it, build.py runs fetch.py first; a failed fetch stops + the build, so a stale page cannot ship. + +The page is the one design system of the four sites (src/system.css): bar 1 (the four sites), bar 2 (the house +logo and its sections), the banner, the house line, Latest, the project plates under their group labels, the +houses row and the footer. Every plate carries its live facts: language, latest release, last commit. The build +writes index.html, 404.html, llms.txt, the social image og.jpg, the icons, the image variants (AVIF and JPEG at +two widths) and a subset of each font with every feature and axis kept. """ +import datetime import html +import io import json import re +import subprocess import sys +import tempfile +from html.parser import HTMLParser from pathlib import Path -from typing import Any, NoReturn, TypedDict +from typing import TYPE_CHECKING, Any, NoReturn import card +if TYPE_CHECKING: + from fontTools.ttLib import TTFont + from PIL import Image + ROOT = Path(__file__).resolve().parent # The site being built: its site.json and its docs/. --site DIR builds another house from this generator. SITE = ROOT DOCS = SITE / "docs" +FONTS = ROOT / "fonts" +IMAGES = ROOT / "img" +SYSTEM_CSS = ROOT / "src" / "system.css" FILE_NAME = re.compile(r"[a-z0-9][a-z0-9._-]*") REPO_NAME = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*") COLOUR = re.compile(r"#[0-9a-f]{6}") # The word of the small link after a description: the project's own site, or its documentation. SITE_LABELS = ("site", "docs") -FONTS = ROOT / "fonts" -IMAGES = ROOT / "img" -# The banner of the house, 1408 x 469, and the banner of a repository, 704 x 235: the same images as -# the GitHub profile of the organisation and the repository. +# The banner of a house, 1408 x 469, and the banner of a repository, 704 x 235: the same images as the GitHub +# profile of the organisation and the repository. Each ships as AVIF and JPEG at two widths. BANNER_SIZE = (1408, 469) PLATE_SIZE = (704, 235) -# The three sites, in the order of the top bar and the footer. +BANNER_WIDTHS = (704, 1408) +PLATE_WIDTHS = (352, 704) +OG_SIZE = (1200, 630) +ICON, TOUCH, AVATAR = 64, 180, 56 +# The three sites, in the order of bar 1 and the footer. The type site comes last on every house. BAR = ("machine-made", "openfluids", "BoringQuantSystems") -# The top bar and the footer end with the type site, on every house. TYPE_BAR = ("type", "https://machine-made.github.io/type/") -# One type scale for the three houses: the base size and the size of the house line, in px. -SIZE, LINE_SIZE = 16, 24 -# The typefaces of the sites, all machine-made (https://machine-made.github.io/type/), version 0.2.0. Weft sets -# the top bar, the labels and the footer on every house; a house sets its text in Weft, Sans or Warp. Each face -# is a file in fonts/ that build.py copies to docs/fonts/, with the licence of the family. -# family -> faces (file stem, font-weight, font-style), licence file, font stack (generic fallbacks only), and the -# word spacing of reading text (Sans has a narrow word space). -WEFT, SANS, WARP = "machine-made Weft", "machine-made Sans", "machine-made Warp" - - -class Family(TypedDict): - faces: tuple[tuple[str, str, str], ...] - licence: str - stack: str - spacing: str - - -FAMILIES: dict[str, Family] = { - WEFT: { - "faces": (("mm-weft", "100 900", "normal"),), "licence": "mm-weft-OFL.txt", - "stack": '"machine-made Weft", ui-monospace, monospace', "spacing": "normal", - }, - SANS: { - "faces": (("mm-sans", "200 800", "normal"),), "licence": "mm-sans-OFL.txt", - "stack": '"machine-made Sans", system-ui, sans-serif', "spacing": "0.05em", - }, - WARP: { - "faces": (("mm-warp-regular", "400", "normal"), ("mm-warp-italic", "400", "italic")), - "licence": "mm-warp-OFL.txt", "stack": '"machine-made Warp", serif', "spacing": "normal", - }, +TYPE_LINE = "Four typefaces, made by code." +# The house faces and the fonts: file in fonts/, CSS family, the @font-face descriptors. Every page loads Weft +# (bars, labels, facts) and Sans (reading text); the house line is set in the house face. +FACES = ("weft", "heddle", "warp") +FONT_FILES = {"weft": "mm-weft", "sans": "mm-sans", "heddle": "mm-heddle", "warp": "mm-warp-regular"} +FAMILY_CSS = { + "weft": ('"mm Weft"', "font-weight:100 900"), + "sans": ('"mm Sans"', "font-weight:200 800"), + "heddle": ('"mm Heddle"', "font-weight:100 900;font-stretch:70% 140%"), + "warp": ('"mm Warp"', "font-weight:400"), } - - -def families_of(site: dict[str, Any]) -> list[str]: - """The font families the house loads: Weft first, then its own text face when that is not Weft.""" - own = site["theme"]["font"] - return [WEFT] + ([own] if own != WEFT else []) - - -def font_files_of(site: dict[str, Any]) -> list[str]: - """The files in fonts/ that the house ships: each face of each family, and the licence of the family.""" - return [ - name for fam in families_of(site) - for name in (*(f"{stem}.woff2" for stem, _, _ in FAMILIES[fam]["faces"]), FAMILIES[fam]["licence"]) - ] - - -def edge_of(ground: str) -> str: - """The 1 px edge of an image: the ground lightened by 10 per cent of the way to white.""" - parts = (int(ground[i : i + 2], 16) for i in (1, 3, 5)) - return "#" + "".join(f"{round(c + (255 - c) * 0.10):02x}" for c in parts) - - -def rem(px: int) -> str: - return f"{px / 16:g}rem" - - -def root_css(site: dict[str, Any]) -> str: - theme = site["theme"] - faces = "".join( - f'@font-face{{font-family:"{fam}";src:url(fonts/{stem}.woff2) format("woff2");' - f"font-weight:{weight};font-style:{style};font-display:swap}}\n" - for fam in families_of(site) - for stem, weight, style in FAMILIES[fam]["faces"] - ) - values = ( - f"--bg:{theme['ground']};--fg:{theme['text']};--muted:{theme['muted']};--accent:{theme['accent']};" - f"--edge:{edge_of(theme['ground'])};--font:{FAMILIES[theme['font']]['stack']};" - f"--mono:{FAMILIES[WEFT]['stack']};--ws:{FAMILIES[theme['font']]['spacing']};--fs:{rem(SIZE)};--ls:{rem(LINE_SIZE)};" - ) - return f"{faces}:root{{{values}}}\n" +# Characters every subset keeps: digits for dates and versions, the space, the middle dot that the style draws +# between facts and the dash of the 404 title. +KEEP = "0123456789 ยทโ€“" +# The OpenType features the style asks for (ss01, tabular, old-style and proportional figures, small capitals) +# and kerning. A subset keeps every feature that still has a glyph to act on; these must survive. +USED_FEATURES = {"ss01", "tnum", "onum", "pnum", "smcp", "c2sc", "kern"} +THEME_KEYS = ("ground", "surface", "line", "text", "muted", "accent") +# Contrast floors, WCAG 2 ratios: text and muted on the ground and on the surface; the accent marks only. +PAIRS = (("text", "ground", 7.0), ("muted", "ground", 4.5), ("text", "surface", 7.0), ("muted", "surface", 4.5), ("accent", "ground", 3.0)) +PLATE_SIZES = "(min-width: 1264px) 282px, (min-width: 1000px) 22vw, (min-width: 520px) 46vw, calc(100vw - 32px)" +BANNER_SIZES = "(min-width: 1264px) 1200px, calc(100vw - 32px)" +MONTHS = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split() +NEVER = {"homebrew-tap"} +# Ids of the built-in sections of every page; a group title may not take them (its id is g-). +RESERVED_IDS = {"latest", "houses"} def fail(message: str, fix: str) -> NoReturn: @@ -116,43 +93,56 @@ def printable_ascii(text: str) -> bool: return bool(text.strip()) and all(32 <= ord(c) < 127 for c in text) -def load_site() -> dict[str, Any]: - path = SITE / "site.json" +def luminance(colour: str) -> float: + channels = [int(colour[i : i + 2], 16) / 255 for i in (1, 3, 5)] + channels = [c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4 for c in channels] + return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2] + + +def contrast(a: str, b: str) -> float: + la, lb = sorted((luminance(a), luminance(b)), reverse=True) + return (la + 0.05) / (lb + 0.05) + + +def load_site(path: Path) -> dict[str, Any]: try: site: dict[str, Any] = json.loads(path.read_text(encoding="utf-8")) except (OSError, json.JSONDecodeError) as exc: - fail(f"cannot read site.json: {exc}", "Fix site.json so that it is valid JSON.") + fail(f"cannot read {path.name}: {exc}", "Fix site.json so that it is valid JSON.") def need(obj: object, key: str, kind: type, where: str) -> None: if not isinstance(obj, dict) or type(obj.get(key)) is not kind: fail(f"{where}.{key} is missing or has the wrong type", f"Set {where}.{key} in site.json.") - for key, kind in ( - ("name", str), ("owner", str), ("line", str), ("blurb", str), ("theme", dict), ("groups", list), - ("nav", list), - ): + for key, kind in (("name", str), ("owner", str), ("line", str), ("theme", dict), ("groups", list), ("nav", list)): need(site, key, kind, "site") + if "blurb" in site: + fail("site.blurb is set", "Remove blurb: the house line stands alone (the approved design, 19 Nov).") if not FILE_NAME.fullmatch(site["name"]) or ".." in site["name"]: fail( "site.name cannot be used as a file name", "Use lower-case letters, digits, dot, dash or underscore; start with a letter or digit; no '..'.", ) - for key in ("line", "blurb"): - if not printable_ascii(site[key]): - fail(f"site.{key} is empty or not printable ASCII", f"Write site.{key} in printable ASCII.") + if not REPO_NAME.fullmatch(site["owner"]): + fail("site.owner is not an owner name", "Use letters, digits, dot, dash or underscore.") + if not printable_ascii(site["line"]): + fail("site.line is empty or not printable ASCII", "Write site.line in printable ASCII.") title = site.get("title", site["name"]) if not isinstance(title, str) or title.lower() != site["name"] or not title.isascii(): fail("site.title must be the name with capitals only", "Write site.title as site.name with some letters in capitals, or leave it out.") theme = site["theme"] - for key in ("ground", "text", "muted", "accent"): + for key in THEME_KEYS: need(theme, key, str, "site.theme") if not COLOUR.fullmatch(theme[key]): fail(f"site.theme.{key} is not #rrggbb", "Write each colour as lower-case #rrggbb with no alpha.") - need(theme, "font", str, "site.theme") - if theme["font"] not in FAMILIES: - fail(f"site.theme.font {theme['font']!r} is not a font of the generator", f"Use one of: {', '.join(FAMILIES)}.") - if {"size", "line_size"} & set(theme): - fail("site.theme sets a type size", "Remove size and line_size: the three houses share one type scale.") + need(theme, "face", str, "site.theme") + if theme["face"] not in FACES: + fail(f"site.theme.face {theme['face']!r} is not a house face", f"Use one of: {', '.join(FACES)}.") + if set(theme) - {*THEME_KEYS, "face"}: + fail(f"site.theme sets {', '.join(sorted(set(theme) - {*THEME_KEYS, 'face'}))}", "A house sets only its six colours and its face; the type scale is shared.") + for fg, bg, floor in PAIRS: + if contrast(theme[fg], theme[bg]) < floor: + fail(f"site.theme {fg} on {bg} is {contrast(theme[fg], theme[bg]):.2f}, below {floor}", "Pick colours that pass the contrast floors.") if not site["groups"]: fail("site.groups is empty", "List at least one group of projects.") slugs: set[str] = set() @@ -160,9 +150,14 @@ def need(obj: object, key: str, kind: type, where: str) -> None: for g, group in enumerate(site["groups"]): where = f"groups[{g}]" need(group, "title", str, where) + need(group, "nav", str, where) need(group, "projects", list, where) if not slug(group["title"]) or slug(group["title"]) in slugs or not group["title"].isascii(): fail(f"{where}.title gives no unique id", "Give each group its own title of ASCII letters and digits.") + if slug(group["title"]) in RESERVED_IDS: + fail(f"{where}.title {group['title']!r} takes the id of a built-in section", "Pick another title: Latest and the houses row are on every page.") + if not printable_ascii(group["nav"]) or len(group["nav"]) > 12: + fail(f"{where}.nav is not a short label", "Give each group a bar-2 label of at most 12 ASCII characters.") slugs.add(slug(group["title"])) if not group["projects"]: fail(f"{where} has no projects", "Remove the group or list a project in it.") @@ -171,6 +166,8 @@ def need(obj: object, key: str, kind: type, where: str) -> None: need(item, key, str, f"{where}.projects[{i}]") if not REPO_NAME.fullmatch(item["repo"]) or ".." in item["repo"]: fail(f"{where}.projects[{i}].repo is not a repository name", "Use letters, digits, dot, dash or underscore; start with a letter or digit; no '..'.") + if item["repo"] in NEVER: + fail(f"{where}.projects[{i}] is {item['repo']}", f"{item['repo']} is never listed.") if not printable_ascii(item["line"]): fail(f"{where}.projects[{i}].line is empty or not printable ASCII", "Write the line in printable ASCII.") for key in ("owner", "site", "site_label"): @@ -201,7 +198,9 @@ def need(obj: object, key: str, kind: type, where: str) -> None: fail("the last nav entry must be the type site", f"Give {TYPE_BAR[0]} the url {TYPE_BAR[1]} and no self.") for t in nav: if not str(t.get("url", "")).startswith("https://"): - fail(f"nav {t.get('name')} has no https url", "Give each entry of the top bar an https url.") + fail(f"nav {t.get('name')} has no https url", "Give each entry of bar 1 an https url.") + if next(t["name"] for t in nav if t.get("self")) != title: + fail("the nav entry marked self is not this site", "Mark this site's own entry with self.") redirects = site.get("redirects", {}) if not isinstance(redirects, dict) or not all( isinstance(k, str) and isinstance(v, str) and FILE_NAME.fullmatch(k) and ".." not in k @@ -209,7 +208,7 @@ def need(obj: object, key: str, kind: type, where: str) -> None: for k, v in redirects.items() ): fail("site.redirects must map a folder name to an https URL", "Use names like chaos-atlas and plain https URLs.") - if set(redirects) & ({"fonts", "img", "index.html", "style.css", "mark.svg", "llms.txt"} | set(repos)): + if set(redirects) & ({"fonts", "img", "index.html", "404.html", "og.jpg", "mark.svg", "llms.txt"} | set(repos)): fail("a redirect folder clashes with a site folder or a project", "Pick another folder name.") return site @@ -222,100 +221,317 @@ def esc(text: str) -> str: return html.escape(text, quote=True) -def repo_url(site: dict[str, Any], item: dict[str, str]) -> str: - return f"https://github.com/{item.get('owner', site['owner'])}/{item['repo']}" - - def display_name(site: dict[str, Any]) -> str: """The name as people read it: site.title when set (the name with capitals), else site.name.""" return str(site.get("title", site["name"])) -def plate(site: dict[str, Any], item: dict[str, str]) -> str: - """One plate: the repository banner as a link to the repository, and one line under it. The image has - no alt text and the link carries the repository name. A project with a site or documentation gets a - small link, "site" or "docs", after the line.""" - name, url = item["repo"], repo_url(site, item) - img = f'' +def full_name(site: dict[str, Any], item: dict[str, str]) -> str: + return f"{item.get('owner', site['owner'])}/{item['repo']}" + + +def houses() -> dict[str, dict[str, Any]]: + """The other houses, by display name, from site.json and houses/*/site.json of this generator.""" + found = {} + for path in [ROOT / "site.json", *sorted((ROOT / "houses").glob("*/site.json"))]: + other = load_site(path) + found[display_name(other)] = other + if set(found) != set(BAR): + fail(f"the generator holds the houses {sorted(found)}", f"Keep exactly {', '.join(BAR)} in site.json and houses/.") + return found + + +# ------------------------------------------------------------------ the GitHub facts +def load_data(path: Path, sites: list[dict[str, Any]]) -> dict[str, Any]: + try: + data: dict[str, Any] = json.loads(path.read_text(encoding="utf-8")) + datetime.date.fromisoformat(data["fetched"]) + except (OSError, ValueError, KeyError, TypeError) as exc: + fail(f"cannot read the GitHub facts {path}: {exc.__class__.__name__}", "Run python3 fetch.py FILE and pass --data FILE.") + for site in sites: + for group in site["groups"]: + for item in group["projects"]: + if full_name(site, item) not in data.get("repos", {}): + fail(f"the GitHub facts have no entry for {full_name(site, item)}", "Run fetch.py again: the data file is older than site.json.") + if set(data.get("families", {})) != {"weft", "sans", "heddle", "warp"}: + fail("the GitHub facts have no release of every type family", "Run fetch.py again.") + return data + + +def date_text(iso: str, fetched: str) -> str: + """'14 Nov', with the year when it is not the year of the fetch. The fetch date, not the clock, keeps two + builds from one data file equal.""" + d = datetime.date.fromisoformat(iso[:10]) + year = datetime.date.fromisoformat(fetched).year + return f"{d.day} {MONTHS[d.month - 1]}" + ("" if d.year == year else f" {d.year}") + + +def time_html(iso: str, fetched: str) -> str: + return f'' + + +def facts(parts: list[str]) -> str: + return '

' + "".join(f"{p}" for p in parts) + "

" + + +def repo_facts(data: dict[str, Any], full: str) -> str: + r = data["repos"][full] + parts = [esc(r["lang"])] if r["lang"] else [] + parts.append(esc(r["release"]["tagName"]) if r["release"] else "unreleased") + parts.append(time_html(r["commit"], data["fetched"])) + return facts(parts) + + +def house_releases(site: dict[str, Any], data: dict[str, Any]) -> list[tuple[str, str, dict[str, str]]]: + """The newest release of each repository of the house, newest first: one entry per repository.""" + found = [] + for group in site["groups"]: + for item in group["projects"]: + releases = data["repos"][full_name(site, item)]["releases"] + if releases: + newest = max(releases, key=lambda r: r["publishedAt"]) + found.append((newest["publishedAt"], item["repo"], newest)) + return sorted(found, key=lambda x: (x[0], x[1]), reverse=True) + + +def family_releases(data: dict[str, Any]) -> list[tuple[str, str, dict[str, str]]]: + found = [(v["publishedAt"], k.capitalize(), v) for k, v in data["families"].items()] + return sorted(found, key=lambda x: (x[0], x[1]), reverse=True) + + +# ------------------------------------------------------------------ components +# The section mark before each label: the 3 x 3 cells, the centre one in the accent. +MK = ( + '" +) +RED_CELL = ' class="r"' +# The machine-made logo in bar 2: the mark, its centre cell in the accent. +LOGO_MARK = ( + '" +) + + +def picture(prefix: str, stem: str, widths: tuple[int, int], size: tuple[int, int], alt: str, sizes: str, lazy: bool = True) -> str: + """AVIF with a JPEG fallback, two widths each. Below the fold the image loads lazily; the banner loads first.""" + load = 'loading="lazy" decoding="async"' if lazy else 'decoding="async" fetchpriority="high"' + avif = ", ".join(f"{prefix}img/{stem}-{w}.avif {w}w" for w in widths) + jpeg = ", ".join(f"{prefix}img/{stem}-{w}.jpg {w}w" for w in widths) + return ( + f'' + f'{esc(alt)}' + ) + + +def label(text: str, ident: str) -> str: + return f'

{MK}{esc(text)}

' + + +def row(ident: str, text: str, inner: str, cls: str = "row") -> str: + return f'
{label(text, ident)}{inner}
' + + +def plate(site: dict[str, Any], item: dict[str, str], data: dict[str, Any], prefix: str) -> str: + """One plate: the repository banner as a link to the repository (named by aria-label, empty alt text), one line + under it with an optional site or docs link, and the live facts.""" + full = full_name(site, item) more = "" if "site" in item: - label = item.get("site_label", "site") - more = f' {label}' + word = item.get("site_label", "site") + more = f' {word}' return ( - f'
  • {img}' - f'{esc(item["line"])}{more}
  • ' + f'
  • ' + f'{picture(prefix, item["repo"], PLATE_WIDTHS, PLATE_SIZE, "", PLATE_SIZES)}' + f'

    {esc(item["line"])}{more}

    {repo_facts(data, full)}
  • ' ) -def page_html(site: dict[str, Any]) -> str: - shown = display_name(site) - sections = "\n".join( - f'
    \n

    {esc(g["title"])}

    \n' - f'
      \n' + "\n".join(plate(site, p) for p in g["projects"]) + "\n
    \n
    " - for g in site["groups"] - ) - preload = "\n".join( - f'' - for fam in families_of(site) +def latest(site: dict[str, Any], data: dict[str, Any]) -> str: + """The newest releases of the house: distinct repositories, newest first, at most three.""" + items = house_releases(site, data)[:3] + if len({repo for _, repo, _ in items}) != len(items): + fail("Latest repeats a repository", "Report this: house_releases must give one entry per repository.") + if not items: + return "" + lis = "".join( + f'
  • {esc(repo)}{facts([esc(r["tagName"]), time_html(r["publishedAt"], data["fetched"])])}
  • ' + for _, repo, r in items ) - # The current site is marked and is not a link; every other entry links to its site. - bar = "\n".join( - f'{esc(t["name"])}' if t.get("self") else f'{esc(t["name"])}' + return row("g-latest", "Latest", f'
      {lis}
    ', "row tight") + + +def houses_row(site: dict[str, Any], others: dict[str, dict[str, Any]], data: dict[str, Any], prefix: str) -> str: + """The other two houses and the type site: banner, house line and the newest release.""" + lis = [] + for t in site["nav"]: + if t.get("self"): + continue + if t["name"] == TYPE_BAR[0]: + img = picture(prefix, "type", PLATE_WIDTHS, PLATE_SIZE, "", PLATE_SIZES) + _, fam, r = family_releases(data)[0] + fx = facts([f'{esc(fam)} {esc(r["tagName"].split("-")[-1])}', time_html(r["publishedAt"], data["fetched"])]) + caption = TYPE_LINE + else: + other = others[t["name"]] + img = picture(prefix, f"banner-{other['name']}", BANNER_WIDTHS, BANNER_SIZE, "", PLATE_SIZES) + releases = house_releases(other, data) + if releases: + _, repo, r = releases[0] + fx = facts([f"{esc(repo)} {esc(r['tagName'])}", time_html(r["publishedAt"], data["fetched"])]) + else: + fx = facts(["unreleased"]) + caption = other["line"] + lis.append( + f'
  • {img}' + f'

    {esc(caption)}

    {fx}
  • ' + ) + return row("g-houses", "The houses", f'
      {"".join(lis)}
    ') + + +def bar1(site: dict[str, Any]) -> str: + lis = "".join( + f'
  • {esc(t["name"])}
  • ' if t.get("self") else f'
  • {esc(t["name"])}
  • ' for t in site["nav"] ) - # The footer reads as one line: the same four names as the top bar, each a link. The style draws the dot - # after each link but the last, so a dot never wraps away from its name. - footer = " ".join(f'{esc(t["name"])}' for t in site["nav"]) - home = next(t["url"] for t in site["nav"] if t.get("self")) - social = "\n".join( + return f'' + + +def bar2(site: dict[str, Any], root: str) -> str: + """The house logo (a link home) and the sections of the page, then the organisation on GitHub. root is "" on + the home page and "/" on the 404 page.""" + secs = "".join(f'{esc(g["nav"])}' for g in site["groups"]) + secs += f'GitHub' + shown = display_name(site) + if site["name"] == "machine-made": + logo = LOGO_MARK + else: + logo = f'' + return ( + f'
    ' + f'
    ' + ) + + +def footer(site: dict[str, Any]) -> str: + """One line: the four sites, each a link. The style draws the dot before each name.""" + return '" + + +def line_html(site: dict[str, Any], tag: str = "p", text: str | None = None) -> str: + """The house line in the house face. A hyphenated word never breaks; in Warp, capitals are small capitals.""" + face = site["theme"]["face"] + t = esc(site["line"] if text is None else text) + t = re.sub(r"\b\w+(?:-\w+)+\b", lambda w: '' + w.group(0) + "", t) + if face == "warp": + t = re.sub(r"\b[A-Z]{2,}\b", lambda w: '' + w.group(0) + "", t) + return f'<{tag} class="line {face}">{t}' + + +def home_url(site: dict[str, Any]) -> str: + return next(t["url"] for t in site["nav"] if t.get("self")) + + +def head(site: dict[str, Any], title: str, prefix: str, preload: str) -> str: + theme = site["theme"] + shown = display_name(site) + home = home_url(site) + if site["name"] == "machine-made": + icon = f'' + else: + icon = f'' + social = "".join( f'' for attr, key, value in ( ("property", "og:type", "website"), ("property", "og:title", shown), ("property", "og:description", site["line"]), ("property", "og:url", home), - ("property", "og:image", f"{home.rstrip('/')}/img/banner.jpg"), - ("property", "og:image:width", str(BANNER_SIZE[0])), - ("property", "og:image:height", str(BANNER_SIZE[1])), + ("property", "og:image", f"{home}og.jpg"), + ("property", "og:image:width", str(OG_SIZE[0])), + ("property", "og:image:height", str(OG_SIZE[1])), ("property", "og:image:alt", shown), ("name", "twitter:card", "summary_large_image"), ) ) - return f""" - - - - -{esc(shown)} - - - - -{social} -{preload} - - - - -
    - -

    -
    -
    -
    -

    {esc(site['line'])}

    -

    {esc(site['blurb'])}

    -
    -{sections} -
    -
    -

    {footer}

    -
    - - -""" + return ( + '\n' + '' + f'{esc(title)}' + f'' + f'{icon}{social}{preload}' + ) + + +def styles(site: dict[str, Any], prefix: str, system: str) -> str: + """Two style blocks: the font faces and the house tokens, then the one system stylesheet. The style is written + into the page: a linked file cost 0.3 s of render time on the Lighthouse phone run.""" + faces = "".join( + f'@font-face{{font-family:{FAMILY_CSS[f][0]};src:url({prefix}fonts/{f}.woff2) format("woff2");{FAMILY_CSS[f][1]};font-style:normal;font-display:swap}}' + for f in uses(site) + ) + tokens = ":root{" + ";".join(f"--{k}:{site['theme'][k]}" for k in THEME_KEYS) + "}" + return f"" + + +def uses(site: dict[str, Any]) -> list[str]: + """The fonts a house page loads: Weft and Sans, and the house face when it is not Weft.""" + face = site["theme"]["face"] + return ["weft", "sans"] + ([face] if face != "weft" else []) + + +def system_css() -> str: + """src/system.css without its comments: the page ships the rules, the source file keeps the notes.""" + text = SYSTEM_CSS.read_text(encoding="utf-8") + if not text.isascii(): + fail("src/system.css is not ASCII", "Write characters as CSS escapes.") + text = re.sub(r"/\*.*?\*/", "", text, flags=re.S) + return "\n".join(line.rstrip() for line in text.splitlines() if line.strip()) + "\n" + + +def page_html(site: dict[str, Any], others: dict[str, dict[str, Any]], data: dict[str, Any], system: str) -> str: + shown = display_name(site) + face = site["theme"]["face"] + sections = "".join( + row(f"g-{slug(g['title'])}", g["title"], '
      ' + "".join(plate(site, p, data, "") for p in g["projects"]) + "
    ") + for g in site["groups"] + ) + preload = ( + f'' + f'' + ) + banner = f'

    {picture("", "banner-" + site["name"], BANNER_WIDTHS, BANNER_SIZE, shown, BANNER_SIZES, lazy=False)}

    ' + body = banner + line_html(site) + latest(site, data) + sections + houses_row(site, others, data, "") + return ( + head(site, shown, "", preload) + styles(site, "", system) + "\n" + f'{bar1(site)}{bar2(site, "")}' + f'
    {body}
    {footer(site)}\n' + ) + + +def not_found_html(site: dict[str, Any], system: str) -> str: + """The 404 page. GitHub Pages serves it at any depth, so every address in it starts at the site root.""" + shown = display_name(site) + face = site["theme"]["face"] + preload = f'' + body = ( + f'

    Not found

    This page does not exist.

    ' + f'

    Back to {esc(shown)}

    ' + ) + return ( + head(site, f"Not found โ€“ {shown}", "/", preload).replace("โ€“", "–") + styles(site, "/", system) + "\n" + f'{bar1(site)}{bar2(site, "/")}' + f'
    {body}
    {footer(site)}\n' + ) def redirect_html(name: str, url: str) -> str: @@ -338,70 +554,235 @@ def redirect_html(name: str, url: str) -> str: def llms_txt(site: dict[str, Any]) -> str: def entry(p: dict[str, str]) -> str: extra = f" ([{p.get('site_label', 'site')}]({p['site']}))" if "site" in p else "" - return f"- [{p['repo']}]({repo_url(site, p)}): {p['line']}{extra}" + return f"- [{p['repo']}](https://github.com/{full_name(site, p)}): {p['line']}{extra}" - groups = "\n\n".join( - f"## {g['title']}\n\n" + "\n".join(entry(p) for p in g["projects"]) for g in site["groups"] - ) + groups = "\n\n".join(f"## {g['title']}\n\n" + "\n".join(entry(p) for p in g["projects"]) for g in site["groups"]) sites = "\n".join(f"- [{t['name']}]({t['url']})" for t in site["nav"]) - return f"# {display_name(site)}\n\n> {site['line']}\n\n{site['blurb']}\n\n{groups}\n\n## Sites\n\n{sites}\n" - - -def read_bytes(path: Path, what: str) -> bytes: - """A file the build copies. A missing file stops the build.""" - if not path.is_file(): - fail(f"{what} is missing", "Restore the file in the generator repository.") - return path.read_bytes() - - -def write(path: Path, text: str) -> None: + return f"# {display_name(site)}\n\n> {site['line']}\n\n{groups}\n\n## Sites\n\n{sites}\n" + + +# ------------------------------------------------------------------ fonts +class FaceText(HTMLParser): + """The text inside any element whose class names the face.""" + + VOID = {"img", "input", "br", "meta", "link", "source", "rect", "hr"} + + def __init__(self, face: str) -> None: + super().__init__(convert_charrefs=True) + self.face, self.stack, self.out = face, [], set() + + def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None: + if tag not in self.VOID: + self.stack.append(self.face in (dict(attrs).get("class") or "").split()) + + def handle_endtag(self, tag: str) -> None: + if tag not in self.VOID and self.stack: + self.stack.pop() + + def handle_data(self, data: str) -> None: + if any(self.stack): + self.out |= set(data) + + +def strip_code(page: str) -> str: + return re.sub(r"<(script|style)[^>]*>.*?", " ", page, flags=re.S) + + +def visible_text(page: str) -> str: + page = strip_code(page) + page = re.sub(r'(?:aria-label|alt|placeholder|title|content)="([^"]*)"', lambda m: " " + m.group(1) + " ", page) + return html.unescape(re.sub(r"<[^>]+>", " ", page)) + + +def face_text(page: str, face: str) -> set[str]: + parser = FaceText(face) + parser.feed(strip_code(page)) + return parser.out + + +def font_meta(font: "TTFont") -> tuple[list[tuple[str, float, float]], set[str]]: + axes = [(a.axisTag, a.minValue, a.maxValue) for a in font["fvar"].axes] if "fvar" in font else [] + feats = {r.FeatureTag for t in ("GSUB", "GPOS") if t in font for r in font[t].table.FeatureList.FeatureRecord} + return axes, feats + + +def subset_fonts(site: dict[str, Any], pages: list[str]) -> dict[str, bytes]: + """One subset per font: the characters of the two pages (and their capitals: labels are set in capitals by the + style). Weft and Sans keep the text of the whole page; the house face keeps only the text set in it. Every + layout feature and every variation axis is kept, and the build fails if one is lost.""" + from fontTools import subset as fts + + text = "".join(visible_text(p) for p in pages) + KEEP + text = "".join(sorted(set(text + text.upper()))) + out = {} + for f in uses(site): + source = FONTS / f"{FONT_FILES[f]}.woff2" + if not source.is_file(): + fail(f"fonts/{source.name} is missing", "Restore the font file in the generator repository.") + chars = text + if f in ("heddle", "warp"): + keep = set(KEEP) + for p in pages: + keep |= face_text(p, f) + chars = "".join(sorted(keep)) + opts = fts.Options() + opts.flavor = "woff2" + opts.layout_features = ["*"] + opts.hinting = False + opts.desubroutinize = True + opts.name_IDs = ["*"] + font = fts.load_font(str(source), opts) + before = font_meta(font) + sub = fts.Subsetter(opts) + sub.populate(text=chars) + sub.subset(font) + after = font_meta(font) + lost = (before[1] & USED_FEATURES) - after[1] + if after[0] != before[0] or lost: + fail(f"the subset of {source.name} lost an axis or the features {sorted(lost)}", "Keep layout_features ['*'] in subset_fonts.") + buf = io.BytesIO() + fts.save_font(font, buf, opts) + out[f"fonts/{f}.woff2"] = buf.getvalue() + return out + + +# ------------------------------------------------------------------ images +def rgb(colour: str) -> tuple[int, int, int]: + return tuple(int(colour[i : i + 2], 16) for i in (1, 3, 5)) # type: ignore[return-value] + + +def variants(source: Path, stem: str, widths: tuple[int, int], cache: dict[Path, Any]) -> dict[str, bytes]: + from PIL import Image + + if source not in cache: + cache[source] = Image.open(source).convert("RGB") + im = cache[source] + out = {} + for w in widths: + r = im if w == im.width else im.resize((w, round(im.height * w / im.width)), Image.LANCZOS) + for ext, opts in (("avif", {"quality": 62, "speed": 4}), ("jpg", {"quality": 82, "optimize": True, "progressive": True})): + buf = io.BytesIO() + r.save(buf, format="AVIF" if ext == "avif" else "JPEG", **opts) + out[f"img/{stem}-{w}.{ext}"] = buf.getvalue() + return out + + +def images(site: dict[str, Any], others: dict[str, dict[str, Any]]) -> dict[str, bytes]: + from PIL import Image, ImageDraw + + def need(path: Path) -> Path: + if not path.is_file(): + fail(f"{path.relative_to(ROOT)} is missing", "Restore the image in the generator repository.") + return path + + cache: dict[Path, Any] = {} + out = {} + plates = {p["repo"] for g in site["groups"] for p in g["projects"]} | {"type"} + for repo in sorted(plates): + out |= variants(need(IMAGES / "repo" / f"{repo}.jpg"), repo, PLATE_WIDTHS, cache) + for other in [site, *(others[n] for n in BAR if n != display_name(site))]: + out |= variants(need(IMAGES / "org" / f"{other['name']}.jpg"), f"banner-{other['name']}", BANNER_WIDTHS, cache) + ground = rgb(site["theme"]["ground"]) + # og.jpg: the banner at full width, centred on the house ground. + banner = cache[IMAGES / "org" / f"{site['name']}.jpg"] + scaled = banner.resize((OG_SIZE[0], round(banner.height * OG_SIZE[0] / banner.width)), Image.LANCZOS) + og = Image.new("RGB", OG_SIZE, ground) + og.paste(scaled, (0, (OG_SIZE[1] - scaled.height) // 2)) + buf = io.BytesIO() + og.save(buf, format="JPEG", quality=84, optimize=True, progressive=True) + out["og.jpg"] = buf.getvalue() + + def png(im: "Image.Image") -> bytes: + b = io.BytesIO() + im.save(b, format="PNG", optimize=True) + return b.getvalue() + + if site["name"] == "machine-made": + # The touch icon: the mark on the ground, drawn at twice the size and scaled down. + big = TOUCH * 2 + im = Image.new("RGB", (big, big), ground) + draw = ImageDraw.Draw(im) + pad, unit = big * 0.2, big * 0.6 / 30 + for on, x, y in card.mark_cells(): + colour = card.RED if on else site["theme"]["text"] + draw.rectangle([pad + x * unit, pad + y * unit, pad + (x + 8) * unit - 1, pad + (y + 8) * unit - 1], fill=colour) + out["img/touch.png"] = png(im.resize((TOUCH, TOUCH), Image.LANCZOS)) + else: + # The avatar of the organisation on the house ground: favicon, touch icon and the bar-2 logo. + avatar = Image.open(need(IMAGES / "org" / f"{site['name']}-avatar.png")).convert("RGBA") + flat = Image.alpha_composite(Image.new("RGBA", avatar.size, (*ground, 255)), avatar).convert("RGB") + for size, rel in ((ICON, "img/icon.png"), (TOUCH, "img/touch.png"), (AVATAR, "img/avatar.png")): + out[rel] = png(flat.resize((size, size), Image.LANCZOS)) + return out + + +# ------------------------------------------------------------------ main +def write(path: Path, blob: bytes) -> None: path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(text, encoding="utf-8", newline="\n") - - -def parse_site(argv: list[str]) -> Path: - """--site DIR: the folder that holds site.json; the page goes to DIR/docs. Default: this repository.""" - if not argv: - return ROOT - if len(argv) != 2 or argv[0] != "--site": - fail(f"unknown arguments: {' '.join(argv)}", "Run python3 build.py, or python3 build.py --site DIR.") - site = Path(argv[1]).resolve() - if not (site / "site.json").is_file(): - fail(f"{argv[1]}/site.json is missing", "Point --site at a folder that holds a site.json.") - return site + path.write_bytes(blob) + + +def parse_args(argv: list[str]) -> tuple[Path, Path | None]: + site, data = ROOT, None + args = list(argv) + while args: + flag = args.pop(0) + if flag not in ("--site", "--data") or not args: + fail(f"unknown arguments: {' '.join(argv)}", "Run python3 build.py [--site DIR] [--data FILE].") + value = Path(args.pop(0)).resolve() + if flag == "--site": + if not (value / "site.json").is_file(): + fail(f"{value}/site.json is missing", "Point --site at a folder that holds a site.json.") + site = value + else: + data = value + return site, data + + +def fetched(data_path: Path | None, tmp: Path) -> Path: + if data_path is not None: + return data_path + out = tmp / "data.json" + done = subprocess.run([sys.executable, str(ROOT / "fetch.py"), str(out)], check=False) + if done.returncode != 0: + fail("the GitHub fetch failed", "Fix the fetch (gh auth status, network) and build again; no page was written.") + return out def main() -> None: global SITE, DOCS # noqa: PLW0603 -- the build state, set once from the command line - SITE = parse_site(sys.argv[1:]) - DOCS = SITE / "docs" - site = load_site() - texts = { - "index.html": page_html(site), - "style.css": root_css(site) + (ROOT / "src" / "style.css").read_text(encoding="utf-8"), - "mark.svg": card.mark_svg(), - "llms.txt": llms_txt(site), - } + site_dir, data_path = parse_args(sys.argv[1:]) + SITE, DOCS = site_dir, site_dir / "docs" + site = load_site(SITE / "site.json") + others = houses() + if not SYSTEM_CSS.is_file(): + fail("src/system.css is missing", "Restore the stylesheet in the generator repository.") + system = system_css() + with tempfile.TemporaryDirectory() as tmp: + data = load_data(fetched(data_path, Path(tmp)), [site, *others.values()]) + page = page_html(site, others, data, system) + missing = not_found_html(site, system) + texts = {"index.html": page, "404.html": missing, "llms.txt": llms_txt(site)} + if site["name"] == "machine-made": + texts["mark.svg"] = card.mark_svg() for folder, url in site.get("redirects", {}).items(): texts[f"{folder}/index.html"] = redirect_html(folder, url) - data = {"img/banner.jpg": read_bytes(IMAGES / "org" / f"{site['name']}.jpg", f"img/org/{site['name']}.jpg")} - for group in site["groups"]: - for p in group["projects"]: - data[f"img/{p['repo']}.jpg"] = read_bytes(IMAGES / "repo" / f"{p['repo']}.jpg", f"img/repo/{p['repo']}.jpg") - for font in font_files_of(site): - data[f"fonts/{font}"] = read_bytes(FONTS / font, f"fonts/{font}") - for rel, text in texts.items(): - write(DOCS / rel, text) - for rel, blob in data.items(): - (DOCS / rel).parent.mkdir(parents=True, exist_ok=True) - (DOCS / rel).write_bytes(blob) - built = set(texts) | set(data) + blobs = {rel: text.encode("utf-8") for rel, text in texts.items()} + blobs |= subset_fonts(site, [page, missing]) + for f in uses(site): + licence = FONTS / f"{FONT_FILES[f].replace('-regular', '')}-OFL.txt" + if not licence.is_file(): + fail(f"fonts/{licence.name} is missing", "Restore the licence of the font.") + blobs[f"fonts/{licence.name}"] = licence.read_bytes() + blobs |= images(site, others) + for rel, blob in blobs.items(): + write(DOCS / rel, blob) for stale in sorted(DOCS.rglob("*"), reverse=True): - if stale.is_file() and stale.relative_to(DOCS).as_posix() not in built: + if stale.is_file() and stale.relative_to(DOCS).as_posix() not in blobs: stale.unlink() elif stale.is_dir() and not any(stale.iterdir()): stale.rmdir() - print(json.dumps({"built": len(built)})) + print(json.dumps({"built": len(blobs)})) if __name__ == "__main__": diff --git a/check_site.py b/check_site.py index c323a1d..2b165f6 100644 --- a/check_site.py +++ b/check_site.py @@ -1,24 +1,28 @@ #!/usr/bin/env python3 -"""Check the built site in docs/. Standard library only. +"""Check the built site in docs/. + + uv run --with fonttools==4.68.0 --with brotli==1.2.1 --with pillow==13.0.0 python3 check_site.py --data FILE [--site DIR] [--deny FILE] Prints OK and exits 0 when every rule holds. Otherwise prints one line per failure and exits 1. -`python3 check_site.py --self-test` breaks a copy of docs/ in many ways and checks that each -break is caught. - -The checks read the public list of the house from allow.json (next to site.json): the owner, the -line, the paragraph on the name, the colours and the font, the three sites, the projects in their -groups, the project sites and the redirects. The page passes only when site.json and allow.json -agree. - -Private repository names are not kept in this repository. Rules that need them read a list -from a file outside the repository: `python3 check_site.py --deny FILE` or MM_DENY_FILE=FILE. -FILE has one name per line. Without it, the allowlist rules still reject every link and every -repository-shaped name that is not public. +`--self-test` breaks a copy of docs/ in many ways and checks that each break is caught. + +The checks read the public list of the house from allow.json (next to site.json): the owner, the line, the +colours and the face, the four sites, the projects in their groups, the project sites and the redirects. The page +passes only when site.json and allow.json agree. --data is the GitHub facts file that fetch.py wrote and build.py +read: every facts line, Latest and the houses row must match it. MM_DATA=FILE does the same. + +The font checks open the font files, so they need fontTools and brotli; everything else is the standard library. + +Private repository names are not kept in this repository. Rules that need them read a list from a file outside +the repository: `--deny FILE` or MM_DENY_FILE=FILE. FILE has one name per line. Without it, the allowlist rules +still reject every link and every repository-shaped name that is not public. """ import argparse +import datetime import hashlib import html +import io import json import os import re @@ -31,19 +35,25 @@ from collections.abc import Callable, Iterator from html.parser import HTMLParser from pathlib import Path -from typing import Literal, NoReturn +from typing import TYPE_CHECKING, Any, Literal, NoReturn from urllib.parse import unquote, urlsplit -ROOT = Path(__file__).resolve().parent +if TYPE_CHECKING: + from fontTools.ttLib import TTFont + +# The generator: src/system.css, fonts/, the allow.json of every house. ROOT is the house being checked. +GEN = Path(__file__).resolve().parent +ROOT = GEN DOCS = ROOT / "docs" +SYSTEM_SRC = GEN / "src" / "system.css" +FONT_DIR = GEN / "fonts" # The public list of the house. load_allow() fills it from allow.json. OWNER = "" LINE = "" -BLURB = "" THEME: dict[str, str] = {} SELF = "" -# The three sites as (name, url), in the order of the top bar. +# The four sites as (name, url), in the order of bar 1. SITES: tuple[tuple[str, str], ...] = () # (title, ("owner/repo", ...)) in page order. GROUPS: tuple[tuple[str, tuple[str, ...]], ...] = () @@ -53,71 +63,96 @@ SITE_LABELS: dict[str, str] = {} # Moved repositories: docs//index.html forwards the old path to the new home. REDIRECTS: dict[str, str] = {} - -WEFT, SANS, WARP = "machine-made Weft", "machine-made Sans", "machine-made Warp" -# The only fonts a page may use, all machine-made, version 0.2.0 (https://machine-made.github.io/type/). -# family -> (faces, licence file). A face is (file stem, font-weight, font-style, sha256 of the woff2 file): -# the hash is the file of the 0.2.0 release, so a file under a machine-made name that is not that font fails. -FONT_SPECS: dict[str, tuple[tuple[tuple[str, str, str, str], ...], str]] = { - WEFT: ( - (("mm-weft", "100 900", "normal", "9115be68c727ae8c707eed1097f878fd7e7bd54fa75bd70b099e94e4e5e71e85"),), - "mm-weft-OFL.txt", - ), - SANS: ( - (("mm-sans", "200 800", "normal", "8ec52cf1b8a799dcda3aab4cf967d681cbd8bffd3f4cb581ed4e5ffa72e0864e"),), - "mm-sans-OFL.txt", - ), - WARP: ( - ( - ("mm-warp-regular", "400", "normal", "035042b467e6c138666b2e6b3b3a38eeb8d6dc3602ac4354f1e335e425101481"), - ("mm-warp-italic", "400", "italic", "4eb9d3abbff429bfc6130fb82790876e8416fe65bab69f11e2d7c35d693d6d53"), - ), - "mm-warp-OFL.txt", - ), +# The other two houses: name -> (line, repositories), from their allow.json in this generator. +OTHERS: dict[str, tuple[str, tuple[str, ...]]] = {} +# The GitHub facts (fetch.py): language, latest release, releases and last commit per repository; the newest +# release of each type family; the date of the fetch. +DATA: dict[str, Any] = {} + +# The source fonts in fonts/: the release files of machine-made/type, unchanged. build.py cuts a subset of each +# for each page. The hash pins the file; fonts/SOURCES.json must say the same. +SOURCES = { + "mm-weft.woff2": ("machine-made Weft", "0.2.0", "9115be68c727ae8c707eed1097f878fd7e7bd54fa75bd70b099e94e4e5e71e85"), + "mm-sans.woff2": ("machine-made Sans", "0.2.0", "8ec52cf1b8a799dcda3aab4cf967d681cbd8bffd3f4cb581ed4e5ffa72e0864e"), + "mm-heddle.woff2": ("machine-made Heddle", "0.2.0", "3f7d0bde0d436dc800abc9b9c760938f38f19c627cc3378bb199032c3a6ec0e1"), + "mm-warp-regular.woff2": ("machine-made Warp", "0.2.0", "035042b467e6c138666b2e6b3b3a38eeb8d6dc3602ac4354f1e335e425101481"), +} +FONT_SOURCE = {"weft": "mm-weft.woff2", "sans": "mm-sans.woff2", "heddle": "mm-heddle.woff2", "warp": "mm-warp-regular.woff2"} +LICENCE = {"weft": "mm-weft-OFL.txt", "sans": "mm-sans-OFL.txt", "heddle": "mm-heddle-OFL.txt", "warp": "mm-warp-OFL.txt"} +# The CSS family of each font and its @font-face descriptors (variable weight and width ranges). +CSS_FAMILY = {"weft": "mm Weft", "sans": "mm Sans", "heddle": "mm Heddle", "warp": "mm Warp"} +DESCRIPTORS = { + "weft": "font-weight:100 900", "sans": "font-weight:200 800", + "heddle": "font-weight:100 900;font-stretch:70% 140%", "warp": "font-weight:400", } -# The word spacing of reading text, per text font: Sans has a narrow word space. -WORD_SPACING = {WEFT: "normal", SANS: "0.05em", WARP: "normal"} -# Fallbacks in a font stack: CSS generic families only. A stack names no font that is not machine-made. +WEIGHTS = {"weft": (100, 900), "sans": (200, 800), "heddle": (100, 900), "warp": (400, 400)} +FACES = ("weft", "heddle", "warp") +# The OpenType features the style asks for, and kerning: a subset must keep each one its source has. +USED_FEATURES = {"ss01", "tnum", "onum", "pnum", "smcp", "c2sc", "kern"} +# Fallbacks in a font stack: machine-made families and CSS generic families only. No system font by name. GENERIC_FAMILIES = {"system-ui", "ui-monospace", "monospace", "serif", "sans-serif"} -# One type scale for the three houses: base size and house-line size in px, and the line height of the body. -SIZE, LINE_SIZE, LEADING = 16, 24, "1.55" +# The type scale: ratio 1.25 on 16 px. Step n is 1.25**n rem. +STEPS = range(-1, 6) +LEADING = "1.5" +# The spacing scale. Margins, paddings, gaps and insets use these tokens only. +SPACING = (4, 8, 12, 16, 24, 32, 48, 64, 96) +# Contrast floors: text and muted on the ground and on the surface; the accent marks only. +PAIRS = (("text", "ground", 7.0), ("muted", "ground", 4.5), ("text", "surface", 7.0), ("muted", "surface", 4.5), ("accent", "ground", 3.0)) +THEME_KEYS = ("ground", "surface", "line", "text", "muted", "accent") # Public sites that a licence text names. Only the licences may name them. LICENCE_URLS = { "fonts/mm-weft-OFL.txt": ("github.com/machine-made/type",), "fonts/mm-sans-OFL.txt": ("github.com/machine-made/type", "github.com/tokotype/PlusJakartaSans"), + "fonts/mm-heddle-OFL.txt": ("github.com/machine-made/type",), "fonts/mm-warp-OFL.txt": ("github.com/machine-made/type",), } -# The top bar and the footer: the three sites, then the type site. +# Bar 1 and the footer: the three sites, then the type site. BAR_NAMES = ("machine-made", "openfluids", "BoringQuantSystems", "type") TYPE_URL = "https://machine-made.github.io/type/" -# The tags that set bold or italic by themselves. The page uses none: it has no bold and no italic face in use. +TYPE_LINE = "Four typefaces, made by code." +# The tags that set bold or italic by themselves. The page uses none. FAUX_TAGS = ("b", "strong", "i", "em", "cite", "dfn") BANNER_SIZE = (1408, 469) PLATE_SIZE = (704, 235) +BANNER_WIDTHS = (704, 1408) +PLATE_WIDTHS = (352, 704) +OG_SIZE = (1200, 630) +PNG_SIZES = {"img/icon.png": 64, "img/touch.png": 180, "img/avatar.png": 56} MAX_IMAGE_BYTES = 400_000 -BASE_FILES = {"index.html", "style.css", "mark.svg", "llms.txt", "img/banner.jpg"} -# The one gradient the page uses: it fades the top and bottom edges of the banner into the ground. -MASK = "mask-image: linear-gradient(transparent, #000 10%, #000 90%, transparent);" -GRID = "repeat(auto-fill, minmax(min(100%, 240px), 1fr))" +PLATE_SIZES = "(min-width: 1264px) 282px, (min-width: 1000px) 22vw, (min-width: 520px) 46vw, calc(100vw - 32px)" +BANNER_SIZES = "(min-width: 1264px) 1200px, calc(100vw - 32px)" +VIEWPORT = '' +# The gradients the style may use, each a mask, each written exactly so: the banner fades at its top and bottom +# edge, and bar-2 sections fade at the right edge on a phone. Each appears with and without the -webkit- prefix. +MASKS = ( + "mask-image: linear-gradient(transparent, #000 10%, #000 90%, transparent);", + "mask-image: linear-gradient(90deg, #000 calc(100% - var(--sp-6)), transparent);", +) +# The one CSS escape the style may hold: the middle dot drawn between facts and between footer names. +DOT = 'content: "\\00b7";' FILE_NAME = re.compile(r"[a-z0-9][a-z0-9._-]*") FORBIDDEN = re.compile( r"[$โ‚ฌยฃ]\s?[0-9]|\b(?:usd|chf|eur)\s?[0-9]|[0-9]\s?(?:usd|chf|eur)\b" r"|tokens|punchcard|night-shift|nexus", re.I, ) +# Words that never appear in public text. The one exception is the line of pi-rethread. +BANNED = re.compile(r"\b(founder|brief|jac|card|session|codex)\b", re.I) +BANNED_OK = ("hand work to a fresh Pi session",) +NEVER = ("homebrew-tap",) VOID = {"meta", "link", "img", "br", "hr", "input", "source", "track", "area", "base", "col", "embed", "wbr"} GITHUB_URL = r"https://github\.com" GITHUB = re.compile(r"github\.com/[\w.-]+(?:/[\w.-]+)*", re.I) RS_NAME = re.compile(r"(? is allowed only inside . FORBIDDEN_TAGS = ( - "script", "iframe", "object", "embed", "form", "input", "button", "audio", "video", "source", "track", - "base", + "script", "iframe", "object", "embed", "form", "input", "button", "audio", "video", "track", "base", ) ALLOWED_ATTRS = { "lang", "charset", "name", "content", "rel", "href", "type", "crossorigin", "as", "class", "id", - "src", "width", "height", "alt", "loading", "aria-labelledby", "property", + "src", "width", "height", "alt", "loading", "aria-labelledby", "property", "srcset", "sizes", "decoding", + "fetchpriority", "imagesizes", "imagesrcset", "datetime", "viewbox", "focusable", "x", "y", } PAINT_PROPS = ("fill", "stroke", "stop-color", "flood-color", "lighting-color", "color") PAINT_DECL = re.compile(r"(? None: failures.append(line) +def site_json() -> dict[str, Any]: + try: + data = json.loads((ROOT / "site.json").read_text(encoding="utf-8")) + except (OSError, ValueError): + return {} + return data if isinstance(data, dict) else {} + + def site_title(name: str | None) -> str | None: """The name as people read it: site.json title (the name with capitals) when set, else the name.""" if not name: return None - try: - title = json.loads((ROOT / "site.json").read_text(encoding="utf-8")).get("title", name) - except (OSError, ValueError, AttributeError): - return name + title = site_json().get("title", name) if not isinstance(title, str) or title.lower() != name: fail("site", "site.json title must be the name with capitals only") return name @@ -187,13 +228,9 @@ def site_title(name: str | None) -> str | None: def site_name() -> str | None: """The site name from site.json, under the same file-name rule as build.py. None if unusable.""" - try: - name = json.loads((ROOT / "site.json").read_text(encoding="utf-8"))["name"] - except (OSError, ValueError, KeyError, TypeError): - fail("site", "site.json has no readable name") - return None + name = site_json().get("name") if not isinstance(name, str) or not FILE_NAME.fullmatch(name) or ".." in name: - fail("site", "site.json name is not a safe file name") + fail("site", "site.json has no readable name, or it is not a safe file name") return None return name @@ -203,21 +240,14 @@ def repos_of(groups: tuple[tuple[str, tuple[str, ...]], ...] | None = None) -> l return [full for _, fulls in (GROUPS if groups is None else groups) for full in fulls] -def families() -> list[str]: - """The font families the house loads: Weft, then its own text face when that is not Weft.""" - return [WEFT] + ([THEME["font"]] if THEME.get("font") not in (None, WEFT) else []) +def uses() -> list[str]: + """The fonts the house loads: Weft and Sans, and its face when that is not Weft.""" + face = THEME.get("face", "weft") + return ["weft", "sans"] + ([face] if face != "weft" else []) -def font_files() -> set[str]: - return { - f"fonts/{name}" for fam in families() if fam in FONT_SPECS - for name in (*(f"{stem}.woff2" for stem, _, _, _ in FONT_SPECS[fam][0]), FONT_SPECS[fam][1]) - } - - -def text_stem() -> str: - """The file stem of the regular face of the house's text font: the main text font, which the page preloads.""" - return FONT_SPECS[THEME["font"]][0][0][0] +def house_key(name: str) -> str: + return name.lower() Attrs = dict[str, str | None] @@ -230,6 +260,7 @@ def __init__(self) -> None: self.ids: list[str] = [] self.links: list[Attrs] = [] self.imgs: list[Attrs] = [] + self.sources: list[tuple[Attrs, str]] = [] self.metas: list[Attrs] = [] self.tags: list[str] = [] self.text: list[str] = [] @@ -273,10 +304,12 @@ def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None if tag == "meta": self.metas.append(a) if tag == "img": - self.imgs.append(a) + self.imgs.append({**a, "in_h1": "1" if "h1" in self.stack else None}) if self.heading is not None: self.heading[1] += a.get("alt") or "" - if tag in ("h1", "h2", "h3"): + if tag == "source": + self.sources.append((a, self.stack[-1] if self.stack else "")) + if tag in ("h1", "h2", "h3", "h4", "h5", "h6"): self.heading = [tag, ""] if tag == "p": self.paragraph = "" @@ -295,7 +328,7 @@ def handle_endtag(self, tag: str) -> None: self.problems.append(f" does not match the open <{self.stack[-1] if self.stack else 'nothing'}>") else: self.stack.pop() - if tag in ("h1", "h2", "h3") and self.heading: + if tag in ("h1", "h2", "h3", "h4", "h5", "h6") and self.heading: self.headings.append((self.heading[0], self.heading[1].strip())) self.heading = None if tag == "p" and self.paragraph is not None: @@ -321,6 +354,13 @@ def error(self, message: str) -> None: self.problems.append(message) +def parse(text: str) -> Page: + page = Page() + page.feed(text) + page.close() + return page + + def luminance(hexcolour: str) -> float: h = hexcolour.lstrip("#") if len(h) == 3: @@ -328,7 +368,7 @@ def luminance(hexcolour: str) -> float: channels = [] for i in (0, 2, 4): c = int(h[i : i + 2], 16) / 255 - channels.append(c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4) + channels.append(c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4) return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2] @@ -380,9 +420,142 @@ def slug(title: str) -> str: return re.sub(r"[^a-z0-9]+", "-", title.lower()).strip("-") -def section_titles() -> list[str]: - """The h2 headings in page order: the groups.""" - return [title for title, _ in GROUPS] +def esc(text: str) -> str: + return html.escape(text, quote=True) + + +# ------------------------------------------------------------------ the expected markup, from allow.json and the facts +def date_text(iso: str) -> str: + d = datetime.date.fromisoformat(iso[:10]) + year = datetime.date.fromisoformat(DATA["fetched"]).year + return f"{d.day} {MONTHS[d.month - 1]}" + ("" if d.year == year else f" {d.year}") + + +def time_html(iso: str) -> str: + return f'' + + +def facts_html(parts: list[str]) -> str: + return '

    ' + "".join(f"{p}" for p in parts) + "

    " + + +def repo_facts(full: str) -> str: + r = DATA["repos"][full] + parts = [esc(r["lang"])] if r["lang"] else [] + parts.append(esc(r["release"]["tagName"]) if r["release"] else "unreleased") + parts.append(time_html(r["commit"])) + return facts_html(parts) + + +def newest(fulls: list[str]) -> list[tuple[str, str, dict[str, str]]]: + """The newest release of each repository, newest first: (date, repository, release).""" + found = [] + for full in fulls: + releases = DATA["repos"][full]["releases"] + if releases: + r = max(releases, key=lambda x: x["publishedAt"]) + found.append((r["publishedAt"], full.split("/")[1], r)) + return sorted(found, key=lambda x: (x[0], x[1]), reverse=True) + + +def picture(prefix: str, stem: str, widths: tuple[int, int], size: tuple[int, int], alt: str, sizes: str, lazy: bool = True) -> str: + load = 'loading="lazy" decoding="async"' if lazy else 'decoding="async" fetchpriority="high"' + avif = ", ".join(f"{prefix}img/{stem}-{w}.avif {w}w" for w in widths) + jpeg = ", ".join(f"{prefix}img/{stem}-{w}.jpg {w}w" for w in widths) + return ( + f'' + f'{esc(alt)}' + ) + + +MK = ( + '" +) + + +def label_html(text: str, ident: str) -> str: + return f'

    {MK}{esc(text)}

    ' + + +def bar1_html() -> str: + lis = "".join( + f'
  • {esc(n)}
  • ' if n == SELF else f'
  • {esc(n)}
  • ' + for n, u in SITES + ) + return f'' + + +def footer_html() -> str: + return '
      ' + "".join(f'
    • {esc(n)}
    • ' for n, u in SITES) + "
    " + + +def latest_html() -> str: + items = newest(repos_of())[:3] + if not items: + return "" + lis = "".join(f'
  • {esc(repo)}{facts_html([esc(r["tagName"]), time_html(r["publishedAt"])])}
  • ' for _, repo, r in items) + return f'
    {label_html("Latest", "g-latest")}
      {lis}
    ' + + +def houses_html() -> str: + lis = [] + for n, u in SITES: + if n == SELF: + continue + if n == "type": + img = picture("", "type", PLATE_WIDTHS, PLATE_SIZE, "", PLATE_SIZES) + r = max(DATA["families"].items(), key=lambda kv: (kv[1]["publishedAt"], kv[0].capitalize())) + fx = facts_html([f'{r[0].capitalize()} {esc(r[1]["tagName"].split("-")[-1])}', time_html(r[1]["publishedAt"])]) + caption = TYPE_LINE + else: + line, fulls = OTHERS[n] + img = picture("", f"banner-{house_key(n)}", BANNER_WIDTHS, BANNER_SIZE, "", PLATE_SIZES) + rel = newest(list(fulls)) + fx = facts_html([f"{esc(rel[0][1])} {esc(rel[0][2]['tagName'])}", time_html(rel[0][2]["publishedAt"])]) if rel else facts_html(["unreleased"]) + caption = line + lis.append(f'
  • {img}

    {esc(caption)}

    {fx}
  • ') + return f'
    {label_html("The houses", "g-houses")}
      {"".join(lis)}
    ' + + +def plate_html(full: str, line: str | None = None) -> re.Pattern[str]: + """The markup of one plate: the repository banner as a link to the repository, named by aria-label, with an + empty alt text; one line under it, with the site or docs link of a project that has one; the live facts.""" + repo = full.split("/")[1] + url = re.escape(f"https://github.com/{full}") + text = r"(?P\S(?:[^<]*\S)?)" if line is None else re.escape(line) + more = "" + if full in SITE_LINKS: + word = SITE_LABELS.get(full, "site") + more = rf' {word}' + return re.compile( + rf'
  • ' + + re.escape(picture("", repo, PLATE_WIDTHS, PLATE_SIZE, "", PLATE_SIZES)) + + rf'

    {text}{more}

    {re.escape(repo_facts(full))}
  • ' + ) + + +# ------------------------------------------------------------------ files, links, head +def wanted_files() -> set[str]: + files = {"index.html", "404.html", "llms.txt", "og.jpg", "img/touch.png"} + files |= {"mark.svg"} if SELF == "machine-made" else {"img/icon.png", "img/avatar.png"} + for f in uses(): + files |= {f"fonts/{f}.woff2", f"fonts/{LICENCE[f]}"} + stems = [(full.split("/")[1], PLATE_WIDTHS) for full in repos_of()] + [("type", PLATE_WIDTHS)] + stems += [(f"banner-{house_key(n)}", BANNER_WIDTHS) for n, _ in SITES if n != "type"] + files |= {f"img/{stem}-{w}.{ext}" for stem, widths in stems for w in widths for ext in ("avif", "jpg")} + files |= {f"{folder}/index.html" for folder in REDIRECTS} + return files + + +def check_files() -> None: + wanted = wanted_files() + present = {p.relative_to(DOCS).as_posix() for p in DOCS.rglob("*") if p.is_file()} + for extra in sorted(present - wanted): + fail("files", f"docs/{extra} is not part of the site") + for missing in sorted(wanted - present): + fail("files", f"docs/{missing} is missing; run python3 build.py") def redirect_page(name: str, url: str) -> str: @@ -403,111 +576,131 @@ def check_redirects() -> None: fail("redirects", f"docs/{name}/index.html must be the plain redirect page to {url}") -def check_files() -> None: - wanted = BASE_FILES | font_files() | {f"img/{full.split('/')[1]}.jpg" for full in repos_of()} - wanted |= {f"{folder}/index.html" for folder in REDIRECTS} - present = {p.relative_to(DOCS).as_posix() for p in DOCS.rglob("*") if p.is_file()} - for extra in sorted(present - wanted): - fail("files", f"docs/{extra} is not part of the one-page site") - for missing in sorted(wanted - present): - fail("files", f"docs/{missing} is missing; run python3 build.py") - - -def local_target(href: str) -> Path | None: - """The file a local link names, or None when it names nothing or leaves docs/.""" +def local_target(href: str, rooted: bool) -> Path | None: + """The file a local link names, or None when it names nothing or leaves docs/. A rooted page (404.html) names + every file from the site root (/img/x.jpg); the home page names it relative to itself (img/x.jpg). A folder + means its index.html.""" path = unquote(href.split("#", 1)[0].split("?", 1)[0]) if not path: return None + if path.startswith("/") != rooted: + return None + if rooted: + path = path[1:] or "./" + if path.endswith("/"): + path += "index.html" root = DOCS.resolve() target = (DOCS / path).resolve() return target if root in target.parents else None +def release_urls() -> set[str]: + return {r["url"] for full in repos_of() for r in DATA["repos"][full]["releases"]} + + def allowed_https() -> set[str]: - """Every https address that the page may link: the three sites, the project sites, the repositories.""" - return {u for _, u in SITES} | set(SITE_LINKS.values()) | {f"https://github.com/{full}" for full in repos_of()} + """Every https address that the page may link: the four sites, the project sites, the repositories, their + releases and the organisation on GitHub.""" + return ( + {u for _, u in SITES} | set(SITE_LINKS.values()) | {f"https://github.com/{full}" for full in repos_of()} + | release_urls() | {f"https://github.com/{OWNER}"} + ) + + +def srcset_urls(value: str) -> list[str]: + return [part.strip().split()[0] for part in value.split(",") if part.strip()] -def check_html(page: Page, html_text: str, name: str | None) -> None: +def check_html(page: Page, html_text: str, where: str, rooted: bool) -> None: + """The rules both pages share: parse, head basics, no script, semantics, images and links.""" for problem in page.problems: - fail("parse", problem) + fail("parse", f"{where}: {problem}") if page.stack: - fail("parse", f"unclosed tags: {', '.join(page.stack)}") + fail("parse", f"{where}: unclosed tags: {', '.join(page.stack)}") if not html_text.lstrip().lower().startswith(""): - fail("parse", "no doctype") + fail("parse", f"{where}: no doctype") if len(page.ids) != len(set(page.ids)): - fail("parse", "an id is used twice") + fail("parse", f"{where}: an id is used twice") if not re.search(r'', html_text): - fail("responsive", "no viewport meta") + fail("a11y", f"{where}: the html element has no lang") + if VIEWPORT not in html_text: + fail("responsive", f"{where}: no viewport meta") if '' not in html_text: - fail("dark", "the page is dark only: the color-scheme meta must be dark") + fail("dark", f"{where}: the page is dark only: the color-scheme meta must be dark") if f'' not in html_text: - fail("dark", "the theme-color meta must be the ground colour of the house") + fail("dark", f"{where}: the theme-color meta must be the ground colour of the house") if re.search(r"[^<]+", html_text) is None: - fail("a11y", "no title") + fail("a11y", f"{where}: no title") for problem in page.unknown_attrs: - fail("attrs", f"{problem}; the page uses no other attributes") - for css in page.styles: - check_refs(css, "index.html", "css") - check_colour_names(css, "index.html") - if colours_of(css, "index.html"): - fail("accent", "index.html has a style block with a colour of its own; colours belong in style.css") + fail("attrs", f"{where}: {problem}; the page uses no other attributes") for forbidden in FORBIDDEN_TAGS: if forbidden in page.tags: - fail("no-js", f"<{forbidden}> is not allowed on a page that needs no script") - for tag in ("header", "nav", "main", "footer", "h1", "h2", "ul"): + fail("no-js", f"{where}: <{forbidden}> is not allowed on a page that needs no script") + for attrs, parent in page.sources: + if parent != "picture" or attrs.get("type") != "image/avif" or "src" in attrs: + fail("no-js", f"{where}: is allowed only inside , as type image/avif with a srcset") + for tag in ("header", "nav", "main", "footer", "h1"): if tag not in page.tags: - fail("semantic", f"no <{tag}>") + fail("semantic", f"{where}: no <{tag}>") if page.tags.count("h1") != 1: - fail("semantic", "the page needs exactly one h1") + fail("semantic", f"{where}: the page needs exactly one h1") if page.tags.count("main") != 1: - fail("semantic", "the page needs exactly one main") - shown = site_title(name) - if shown and ("h1", shown) not in page.headings: - fail("content", f"the h1 must be the site name, {shown}") - check_head(page, html_text, shown) + fail("semantic", f"{where}: the page needs exactly one main") + levels = [int(kind[1]) for kind, _ in page.headings] + if levels and (levels[0] != 1 or any(b - a > 1 for a, b in zip(levels, levels[1:], strict=False))): + fail("semantic", f"{where}: the headings skip a level: {levels}") for faux in FAUX_TAGS: if faux in page.tags: - fail("fonts", f"<{faux}> sets bold or italic by itself; the page uses no bold and no italic") + fail("fonts", f"{where}: <{faux}> sets bold or italic by itself; the page uses no bold and no italic") if html_text.count("aria-current=") != 1: - fail("a11y", "exactly one entry of the top bar must carry aria-current") + fail("a11y", f"{where}: exactly one entry of bar 1 must carry aria-current") first: Attrs = page.first_link or {} if first.get("href") != "#main" or "main" not in page.ids: - fail("a11y", "the first link must be a skip link to #main") + fail("a11y", f"{where}: the first link must be a skip link to #main") for img in page.imgs: - # The banner carries the org name. A plate image is decorative (alt=""): its link names it. - banner = img.get("class") == "banner" - if "alt" not in img or (banner and not (img.get("alt") or "").strip()): - fail("a11y", f"image {img.get('src')} has no alt attribute, or the banner has empty alt text") - if not banner and img.get("alt") != "": - fail("a11y", f"image {img.get('src')} is a plate image: its alt text is empty and its link carries the name") + # The banner in the h1 carries the house name. Every other image is decorative (alt=""): its link names it. + if "alt" not in img or (img.get("in_h1") and not (img.get("alt") or "").strip()): + fail("a11y", f"{where}: image {img.get('src')} has no alt attribute, or the banner has empty alt text") + if not img.get("in_h1") and img.get("alt") != "": + fail("a11y", f"{where}: image {img.get('src')} is decorative: its alt text is empty and its link carries the name") if not (img.get("width") and img.get("height")): - fail("responsive", f"image {img.get('src')} has no width and height") - target = local_target(img.get("src") or "") - if target is None or not target.is_file(): - fail("links", f"image {img.get('src')} does not resolve inside docs/") + fail("responsive", f"{where}: image {img.get('src')} has no width and height") + for src in [img.get("src") or "", *srcset_urls(img.get("srcset") or "")]: + target = local_target(src, rooted) + if target is None or not target.is_file(): + fail("links", f"{where}: image {src} does not resolve inside docs/") + for attrs, _ in page.sources: + for src in srcset_urls(attrs.get("srcset") or ""): + target = local_target(src, rooted) + if target is None or not target.is_file(): + fail("links", f"{where}: image {src} does not resolve inside docs/") allowed = allowed_https() + names = {u: n for n, u in SITES} for link in page.links: href = link.get("href") or "" parts = urlsplit(href) - if link.get("class") == "pic" and (link.get("aria-label") or "").strip() != href.rstrip("/").rsplit("/", 1)[-1]: - fail("a11y", f"the image link to {href} needs aria-label with the repository name") + if link.get("class") == "pic": + want = names.get(href) or href.rstrip("/").rsplit("/", 1)[-1] + if (link.get("aria-label") or "").strip() != want: + fail("a11y", f"{where}: the image link to {href} needs aria-label with the repository or site name") if href.startswith("#"): if href[1:] not in page.ids: - fail("links", f"{href} points to no id") + fail("links", f"{where}: {href} points to no id") elif parts.scheme or parts.netloc: if parts.scheme.lower() != "https": - fail("links", f"{href} is not an https link") + fail("links", f"{where}: {href} is not an https link") elif link.get("tag") == "link": - fail("links", f"{href} is an external resource; the page loads only files in docs/") + fail("links", f"{where}: {href} is an external resource; the page loads only files in docs/") elif href not in allowed: - fail("links", f"{href} is not in the public list") + fail("links", f"{where}: {href} is not in the public list") else: - target = local_target(href) + target = local_target(href, rooted) if target is None or not target.is_file(): - fail("links", f"{href} does not resolve inside docs/") + fail("links", f"{where}: {href} does not resolve inside docs/") + elif rooted and parts.fragment and target.name == "index.html": + ids = parse(target.read_text(encoding="utf-8", errors="replace")).ids + if parts.fragment not in ids: + fail("links", f"{where}: {href} points to no id on the home page") def meta_values(page: Page, attr: str, key: str) -> list[str]: @@ -515,33 +708,37 @@ def meta_values(page: Page, attr: str, key: str) -> list[str]: return [a.get("content") or "" for a in page.metas if a.get(attr) == key] -def check_head(page: Page, html_text: str, shown: str | None) -> None: - """The head: title, description, favicon, and the social preview that uses the org banner.""" - title = re.search(r"([^<]+)", html_text) - if shown and (not title or html.unescape(title.group(1)) != shown): - fail("head", f"the title must be the site name, {shown}") +def check_head(page: Page, html_text: str, shown: str | None, where: str, prefix: str) -> None: + """The head: description, favicon, touch icon, and the social preview at 1200 by 630.""" if meta_values(page, "name", "description") != [LINE]: - fail("head", "the description meta must be the org line, word for word") - if '' not in html_text: - fail("head", "the page needs its favicon: ") - home = next((u for n, u in SITES if n == SELF), "") + fail("head", f"{where}: the description meta must be the house line, word for word") + icon = ( + f'' if SELF == "machine-made" + else f'' + ) + if html_text.count('rel="icon"') != 1 or icon not in html_text: + fail("head", f"{where}: the page needs its favicon, {icon}") + if f'' not in html_text: + fail("head", f"{where}: the page needs its touch icon, {prefix}img/touch.png") + home = dict(SITES).get(SELF, "") expected = { "og:type": "website", "og:title": shown or "", "og:description": LINE, "og:url": home, - "og:image": f"{home.rstrip('/')}/img/banner.jpg", "og:image:width": str(BANNER_SIZE[0]), - "og:image:height": str(BANNER_SIZE[1]), "og:image:alt": shown or "", + "og:image": f"{home}og.jpg", "og:image:width": str(OG_SIZE[0]), "og:image:height": str(OG_SIZE[1]), + "og:image:alt": shown or "", } for key, value in expected.items(): if meta_values(page, "property", key) != [value]: - fail("head", f"the social preview meta {key} must be {value!r}; og:image is the org banner") + fail("head", f"{where}: the social preview meta {key} must be {value!r}; og:image is og.jpg at 1200 by 630") if meta_values(page, "name", "twitter:card") != ["summary_large_image"]: - fail("head", "the twitter:card meta must be summary_large_image") + fail("head", f"{where}: the twitter:card meta must be summary_large_image") -def check_refs(text: str, where: str, kind: CssKind) -> None: +def check_refs(text: str, where: str, kind: CssKind, rooted: bool = False) -> None: """url() and @import targets: css may load only local files; svg only #fragments. - Every other CSS image function is refused, and so is a backslash, which can spell any name.""" - if "\\" in text: + Every other CSS image function is refused, and so is a backslash, which can spell any name. The one escape + allowed is the middle dot in a content string.""" + if "\\" in text.replace(DOT, "").replace(DOT.replace(": ", ":"), ""): fail("css", f"{where} has a backslash escape, which can hide a function or a colour name") for func in IMAGE_FUNC.finditer(text): fail("links", f"{where} uses {func.group(1).lower()}(); only url() may load an image") @@ -556,331 +753,92 @@ def check_refs(text: str, where: str, kind: CssKind) -> None: elif parts.scheme or parts.netloc: fail("links", f"{where} loads {target[:50]!r}; only local files are allowed") else: - local = local_target(target) + local = local_target(target, rooted) if local is None or not local.is_file(): fail("links", f"{where} refers to {target[:50]!r}, which is not a file inside docs/") -LOCAL_WOFF2 = re.compile(r"\s*url\(\s*(['\"]?)fonts/([a-z0-9-]+)\.woff2\1\s*\)\s*format\(\s*(['\"])woff2\3\s*\)\s*") - - -def check_fonts(html_text: str) -> None: - """The fonts are files in docs/fonts/, all machine-made: one @font-face per face of each family of the - house, each with a local woff2, font-display: swap, the right weight range and style; each file is the - woff2 of the 0.2.0 release; the page preloads the main text font and no other file.""" - check_font_faces() - check_font_files(html_text) +# ------------------------------------------------------------------ the style +def system_css() -> str: + """src/system.css as the page carries it: without comments and blank lines.""" + try: + text = SYSTEM_SRC.read_text(encoding="utf-8") + except OSError: + fail("css", "src/system.css is missing") + return "" + text = re.sub(r"/\*.*?\*/", "", text, flags=re.S) + return "\n".join(line.rstrip() for line in text.splitlines() if line.strip()) + "\n" -def check_font_faces() -> None: - """The @font-face rules of style.css: only machine-made families, each face once, with its own file.""" - css = re.sub(r"/\*.*?\*/", " ", read("style.css"), flags=re.S) +def faces_css(prefix: str) -> str: + faces = "".join( + f'@font-face{{font-family:"{CSS_FAMILY[f]}";src:url({prefix}fonts/{f}.woff2) format("woff2");{DESCRIPTORS[f]};font-style:normal;font-display:swap}}' + for f in uses() + ) + tokens = ":root{" + ";".join(f"--{k}:{THEME.get(k, '')}" for k in THEME_KEYS) + "}" + return f"{faces}\n{tokens}" + + +def check_styles(page: Page, where: str, prefix: str) -> str: + """Two style blocks: the font faces and the house colours, then the one system stylesheet, src/system.css. + Returns the system block, which check_css reads.""" + if len(page.styles) != 2: + fail("css", f"{where}: the page needs exactly two style blocks, the faces and colours, then src/system.css") + return page.styles[-1] if page.styles else "" + first, system = page.styles + if first != faces_css(prefix): + fail("fonts", f"{where}: the first style block must be the @font-face rules of {', '.join(CSS_FAMILY[f] for f in uses())} and the colours of allow.json") + if system != system_css(): + fail("css", f"{where}: the second style block must be src/system.css without its comments") + check_refs(first, where, "css", rooted=prefix == "/") + check_colour_names(first, where) + colours_of(first, where) + return system + + +def check_font_faces(css: str, where: str, prefix: str) -> None: + """Every @font-face: a machine-made family of the house, its own subset file, swap, its weight range.""" faces = re.findall(r"@font-face\s*\{([^}]*)\}", css, re.I) - wanted = families() - seen: set[tuple[str, str]] = set() + seen: set[str] = set() + by_family = {CSS_FAMILY[f]: f for f in uses()} for face in faces: family = re.search(r"font-family\s*:\s*(['\"])(.*?)\1", face) - src = re.search(r"(? None: - """The font files in docs/fonts/ are the 0.2.0 release files; the page preloads the main text font only.""" - wanted = families() - pinned = {f"fonts/{stem}.woff2": digest for name in wanted for stem, _, _, digest in FONT_SPECS[name][0]} - for rel in sorted(pinned): - path = DOCS / rel - if not path.is_file(): - continue - data = path.read_bytes() - if data[:4] != b"wOF2": - fail("fonts", f"docs/{rel} is not a woff2 font") - elif hashlib.sha256(data).hexdigest() != pinned[rel]: - fail("fonts", f"docs/{rel} is not the machine-made font file of version 0.2.0") - preloads = re.findall(r"]*\brel=\"preload\"[^>]*>", html_text) - if not preloads: - fail("fonts", "the page preloads no font; preload the main text font") - hrefs = [] - for tag in preloads: - href = re.search(r'\bhref="([^"]*)"', tag) - target = href.group(1) if href else "" - hrefs.append(target) - if target not in {f"fonts/{FONT_SPECS[name][0][0][0]}.woff2" for name in wanted}: - fail("fonts", f"the page preloads {target[:50]!r}, which is not the regular face of a font of the house") - if 'as="font"' not in tag or 'type="font/woff2"' not in tag or not re.search(r"\bcrossorigin\b", tag): - fail("fonts", f"the preload of {target[:50]!r} needs as=\"font\", type=\"font/woff2\" and crossorigin") - if f"fonts/{text_stem()}.woff2" not in hrefs: - fail("fonts", f"the page must preload the main text font, fonts/{text_stem()}.woff2") - - -def family_names(stack: str) -> list[str]: - return [part.strip().strip("'\"") for part in stack.split(",") if part.strip()] - - -def check_font_use(css: str, found: dict[str, str]) -> None: - """Every font family a rule names is machine-made or generic; no rule sets bold or italic that the page - does not load as a real face.""" - for key in ("font", "mono"): - for fam in family_names(found.get(key, "")): - if fam not in FONT_SPECS and fam not in GENERIC_FAMILIES: - fail("fonts", f"--{key} names the font family {fam!r}; only machine-made fonts and generic families are allowed") - for _, selector, decls in css_rules(css): - if selector.startswith("@font-face") or ":root" in selector: - continue - # The family a rule selects: Weft through var(--mono), else the text font of the house. A rule that - # sets italic needs an italic face in that family. - family = WEFT if re.search(r"var\(\s*--mono\s*\)", decls.get("font-family", "") + decls.get("font", "")) else THEME["font"] - italic_ok = any(face[2] == "italic" for face in FONT_SPECS[family][0]) - for prop in ("font-family", "font"): - if prop in decls and not re.search(r"var\(\s*--(?:font|mono)\s*\)", decls[prop]): - fail("fonts", f"{selector[:40]} sets {prop}: {decls[prop][:30]!r}; use var(--font) or var(--mono)") - tokens = decls.get("font", "").split() - weight = decls.get("font-weight") or next((t for t in tokens if re.fullmatch(r"\d{3}|bold|bolder|lighter", t)), "400") - if weight not in ("400", "normal", "inherit"): - fail("fonts", f"{selector[:40]} sets font-weight {weight}; the page loads no bold face, so it sets none") - style = decls.get("font-style") or next((t for t in tokens if t in ("italic", "oblique")), "normal") - if style not in ("normal", "inherit") and not (italic_ok and style == "italic"): - fail("fonts", f"{selector[:40]} sets font-style {style}; {family} loads no italic face") - labels = [d for _, s, d in css_rules(css) if ".lbl" in s.split(",")[0] and "font" in d] - if not labels or not re.search(r"(? None: - """One type scale on the three houses, and the small links that a touch screen needs.""" - for key, px in (("fs", SIZE), ("ls", LINE_SIZE)): - if found.get(key, "").lower() != f"{px / 16:g}rem": - fail("scale", f"--{key} is {found.get(key) or 'missing'}; the three houses share {px / 16:g}rem ({px} px)") - if found.get("ws") != WORD_SPACING[THEME["font"]] or re.sub(r"\s+", " ", css).count("word-spacing: var(--ws)") != 3: - fail("scale", f"--ws must be {WORD_SPACING[THEME['font']]} for {THEME['font']}, and reading text must use word-spacing: var(--ws)") - body = [d for c, s, d in css_rules(css) if s == "body" and not c] - if not body or f"/ {LEADING} " not in body[0].get("font", ""): - fail("scale", f"body must set the line height {LEADING}, the same on the three houses") - rules = list(css_rules(css)) - link = [d for c, s, d in rules if s == ".ds a" and not c] - if not link or "underline" not in link[0].get("text-decoration", ""): - fail("touch", "the link after a description must be underlined always, not only on hover") - for selector in (".ds a", ".bar a, .bar span, footer a"): - narrow = [d for c, s, d in rules if s == selector and any("(max-width:720px)" in cond for cond in c)] - if not narrow or narrow[0].get("min-height") != "44px": - fail("touch", f"{selector} must be at least 44px high below 720px") - dots = [d for c, s, d in rules if s == "footer a:not(:last-child)::after" and not c] - if not dots or dots[0].get("content") != '""' or "var(--muted)" not in dots[0].get("background", ""): - fail("touch", "the footer draws the dot after each link but the last in the style, so a dot never wraps alone") - hover = [d for c, s, d in rules if s == ".pic:hover img" and any("(hover:hover)" in cond for cond in c)] - if not any("outline-color" in d for d in hover): - fail("hover", "a plate image must show its hover state without motion: .pic:hover img sets outline-color") - - -def sentences_of(paragraph: str) -> list[str]: - return re.split(r"(?<=[.!?])\s+", paragraph.strip()) - - -def check_prose(paragraphs: list[str], where: str) -> None: - for paragraph in paragraphs: - for sentence in sentences_of(paragraph): - if len(sentence.split()) > MAX_WORDS: - fail("voice", f"{where}: a sentence has more than {MAX_WORDS} words: {sentence[:40]}") - - -def plate_html(full: str, line: str | None = None) -> re.Pattern[str]: - """The markup of one plate: the repository banner as a link to the repository, named by aria-label, with an - empty alt text, and one line under it. A project with a site or documentation has a small link after the line.""" - repo = full.split("/")[1] - url = re.escape(f"https://github.com/{full}") - img = ( - rf'' - ) - text = r"(?P\S(?:[^<]*\S)?)" if line is None else re.escape(line) - more = "" - if full in SITE_LINKS: - label = SITE_LABELS.get(full, "site") - more = rf' {label}' - return re.compile( - rf'
  • {img}' - rf'{text}{more}
  • ' + fail("fonts", f"{where}: the @font-face of {name} needs font-display: swap") + if DESCRIPTORS[f] not in face: + fail("fonts", f"{where}: the @font-face of {name} must have {DESCRIPTORS[f]}") + if not re.search(r"font-style\s*:\s*normal\s*(;|$)", face): + fail("fonts", f"{where}: the @font-face of {name} must have font-style normal") + for f in uses(): + if f not in seen: + fail("fonts", f"{where} has no @font-face for {CSS_FAMILY[f]}") + + +def check_preloads(html_text: str, where: str, prefix: str, banner: bool) -> None: + """One font preload, the house face (the house line is the largest text above the fold); on the home page one + image preload too, the banner, fetched first.""" + face = THEME.get("face", "weft") + fonts = re.findall(r']*\bas="font"[^>]*>', html_text) + if fonts != [f'']: + fail("fonts", f"{where} must preload exactly the house face, {prefix}fonts/{face}.woff2, as a font with crossorigin") + images = re.findall(r']*\bas="image"[^>]*>', html_text) + name = house_key(SELF) + want = ( + [f''] if banner else [] ) - - -def check_content(page: Page, html_text: str) -> str: - text = " ".join(" ".join(page.text).split()) - visible = " ".join([text, *page.values, *page.hidden, *page.tags]) - expected_bar = "\n".join( - f'{html.escape(n)}' if n == SELF else f'{html.escape(n)}' - for n, u in SITES - ) - if f'' not in html_text: - fail("content", f"the top bar must read {' ยท '.join(n for n, _ in SITES)}: {SELF} marked with aria-current and not linked, type last") - if not re.search(r'

    ', html_text): - fail("content", "the h1 must hold the banner, img/banner.jpg at 1408 by 469, with the name as alt text") - expected_duo = ( - f'
    \n

    {html.escape(LINE)}

    \n

    {html.escape(BLURB)}

    \n
    ' - ) - if expected_duo not in html_text: - fail("content", "the org line and the paragraph on the name must sit side by side, word for word as allow.json has them") - expected_footer = " ".join(f'{html.escape(n)}' for n, u in SITES) - if f'
    \n

    {expected_footer}

    \n
    ' not in html_text: - fail("content", f"the footer must link {' ยท '.join(n for n, _ in SITES)}, in that order, and nothing else") - order = [html_text.find(m) for m in ('class="bar"', 'class="banner"', 'class="duo"', 'class="grid"', "\n

    ([^<]*)

    \n
      \n(.*?)\n
    \n', - html_text, - re.S, - ) - if len(sections) != len(GROUPS) or html_text.count(" Iterator[tuple[str, str]]: - """Every emitted text file as (name, text). The page counts as what a reader or a crawler gets.""" - yield "index.html", visible - for path in sorted(DOCS.rglob("*")): - name = path.relative_to(DOCS).as_posix() - if path.is_file() and name != "index.html" and path.suffix not in (".woff2", ".jpg"): - yield name, path.read_text(encoding="utf-8", errors="replace") - - -def decoded(source: str) -> str: - """source with every character reference decoded, however deeply it is nested.""" - while (plain := html.unescape(source)) != source: - source = plain - return source - - -def check_leaks(visible: str, deny: list[str]) -> None: - forwards = {f"{folder}/index.html": url.split("//", 1)[1] for folder, url in REDIRECTS.items()} - for name, raw in emitted(visible): - # Files are plain ASCII. - if not raw.isascii(): - fail("voice", f"docs/{name} has characters that are not plain ASCII") - if name != "index.html" and not raw.isascii(): - continue - source = raw + "\n" + decoded(raw) - for match in GITHUB.findall(source): - ok = match == forwards.get(name) or match in LICENCE_URLS.get(name, ()) or any( - match == f"github.com/{full}" for full in repos_of() - ) - if not ok: - fail("private", f"{match} is not in the public list ({name})") - for repo in RS_NAME.findall(source): - if repo.lower() not in {full.split("/")[1].lower() for full in repos_of()}: - fail("private", f"{repo} looks like a repository that is not in the public list ({name})") - for word in deny: - if re.search(rf"(? None: - for path in sorted(DOCS.rglob("*")): - if path.is_file() and path.suffix not in (".woff2", ".jpg"): - hit = FORBIDDEN.search(path.read_text(encoding="utf-8", errors="replace")) - if hit: - fail("forbidden", f"docs/{path.relative_to(DOCS).as_posix()} contains {hit.group(0)!r}") - - -def jpeg_size(data: bytes) -> tuple[int, int] | None: - """(width, height) of a JPEG, read from its first start-of-frame marker. None when it is not a JPEG.""" - if data[:3] != b"\xff\xd8\xff": - return None - i = 2 - while i + 9 < len(data): - if data[i] != 0xFF: - i += 1 - continue - marker = data[i + 1] - if marker in (0xD8, 0x01) or 0xD0 <= marker <= 0xD7 or marker == 0xFF: - i += 1 if marker == 0xFF else 2 - continue - length = int.from_bytes(data[i + 2 : i + 4], "big") - if marker in (0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF): - return int.from_bytes(data[i + 7 : i + 9], "big"), int.from_bytes(data[i + 5 : i + 7], "big") - i += 2 + length - return None - - -def check_images() -> None: - """Each image is a real JPEG of the size that the page declares, and no larger than a plate needs.""" - for path in sorted((DOCS / "img").glob("*")) if (DOCS / "img").is_dir() else []: - data = path.read_bytes() - size = jpeg_size(data) - want = BANNER_SIZE if path.name == "banner.jpg" else PLATE_SIZE - if size is None: - fail("images", f"docs/img/{path.name} is not a JPEG") - elif not data.endswith(b"\xff\xd9"): - fail("images", f"docs/img/{path.name} is cut short: it has no end-of-image marker") - elif size != want: - fail("images", f"docs/img/{path.name} is {size[0]} x {size[1]}; it must be {want[0]} x {want[1]}") - if len(data) > MAX_IMAGE_BYTES: - fail("images", f"docs/img/{path.name} is {len(data)} bytes; the limit is {MAX_IMAGE_BYTES}") + if images != want: + fail("fonts" if not banner else "images", f"{where} must preload {'the banner and no other image' if banner else 'no image'}") + if html_text.count('rel="preload"') != len(fonts) + len(images): + fail("fonts", f"{where} has a preload that is not the house face or the banner") def declarations(body: str) -> dict[str, str]: @@ -913,7 +871,7 @@ def css_rules(css: str, conditions: tuple[str, ...] = ()) -> Iterator[Rule]: body = css[start + 1 : k - 1] if prelude.lower().startswith(("@media", "@supports")): yield from css_rules(body, (*conditions, re.sub(r"\s+", "", prelude.lower()))) - else: + elif not prelude.lower().startswith("@keyframes"): yield conditions, re.sub(r"\s+", " ", prelude), declarations(body) i = k @@ -940,9 +898,9 @@ def check_behaviour(css: str) -> None: wrapper = part.strip().split(":hover")[0] if wrapper not in clipped: fail("hover", f"{wrapper} scales an image on hover but is not clipped (overflow: hidden)") - focus = [d for _, s, d in css_rules(css) if s == "a:focus-visible"] + focus = [d for c, s, d in css_rules(css) if s == ":focus-visible" and not c] if not focus or "var(--accent)" not in focus[0].get("outline", ""): - fail("focus", "a:focus-visible must draw an outline in the accent colour") + fail("focus", ":focus-visible must draw an outline in the accent colour on every element") def text_colour(value: str, prop: str, tokens: dict[str, str]) -> str | None: @@ -956,18 +914,18 @@ def text_colour(value: str, prop: str, tokens: dict[str, str]) -> str | None: if v in GREY_NAMES: return GREY_NAMES[v] if v == "transparent": - return tokens["bg"] + return tokens["ground"] if v in ("inherit", "currentcolor"): return None - fail("contrast", f"style.css sets {prop}: {value[:30]!r}; use a palette token (var(--name)), black, white or transparent") + fail("contrast", f"the style sets {prop}: {value[:30]!r}; use a palette token (var(--name)), black, white or transparent") return None def check_text_colours(css: str, tokens: dict[str, str]) -> None: - """Measure the colours that text uses: each color and background in style.css, against its partner. + """Measure the colours that text uses: each color and background in the style, against its partner. - A rule with only color is measured on --bg. A rule with only a background is measured with --fg. - A rule that draws an empty box (content: "") sets no text and is not measured.""" + A rule with only color is measured on the ground. A rule with only a background is measured with the text + colour. A rule that draws an empty box (content: "") sets no text and is not measured.""" for _, _, decls in css_rules(css): if decls.get("content") in ('""', "''"): continue @@ -978,60 +936,174 @@ def check_text_colours(css: str, tokens: dict[str, str]) -> None: fg_hex = text_colour(fg, "color", tokens) if fg is not None else None for bg in bgs or [None]: bg_hex = text_colour(bg, "background", tokens) if bg is not None else None - top, ground = fg_hex or tokens["fg"], bg_hex or tokens["bg"] + top, ground = fg_hex or tokens["text"], bg_hex or tokens["ground"] need = 3.0 if top == tokens["accent"] else 4.5 ratio = contrast(top, ground) if ratio < need: - fail("contrast", f"style.css has text {top} on {ground} at {ratio:.2f}, below {need}") + fail("contrast", f"the style has text {top} on {ground} at {ratio:.2f}, below {need}") -def check_css() -> None: - css = read("style.css") - if not css: - return - root = re.search(r":root\{([^}]*)\}", css) - if not root: - fail("dark", "style.css needs the :root block of the house colours, fonts and sizes") +def family_of(value: str) -> str | None: + """The machine-made font a font or font-family value selects through var(--f-x), or None.""" + hit = re.search(r"var\(\s*--f-(weft|sans|heddle|warp)\s*\)", value) + return hit.group(1) if hit else None + + +def family_names(stack: str) -> list[str]: + return [part.strip().strip("'\"") for part in stack.split(",") if part.strip()] + + +def check_font_use(css: str, root: dict[str, str]) -> None: + """Every font stack starts with its machine-made family and falls back only to machine-made or generic + families. Every rule selects its font through a stack token. No rule sets a weight outside the range of the font + it uses, so no weight is faked, and no rule sets italic: no italic face is loaded.""" + mm = set(CSS_FAMILY.values()) + for f, fam in CSS_FAMILY.items(): + names = family_names(root.get(f"f-{f}", "")) + if not names or names[0] != fam: + fail("fonts", f"--f-{f} must start with {fam!r}") + for name in names[1:]: + if name not in mm and name not in GENERIC_FAMILIES: + fail("fonts", f"--f-{f} names the font family {name!r}; only machine-made fonts and generic families are allowed") + for _, selector, decls in css_rules(css): + if selector.startswith("@font-face") or ":root" in selector: + continue + for prop in ("font-family", "font"): + if prop in decls and not family_of(decls[prop]) and not re.search(r'"mm (Weft|Sans|Heddle|Warp) Full"', decls[prop]): + fail("fonts", f"{selector[:40]} sets {prop}: {decls[prop][:30]!r}; use var(--f-weft), var(--f-sans), var(--f-heddle) or var(--f-warp)") + fam = family_of(decls.get("font", "") + decls.get("font-family", "")) or "sans" + tokens = decls.get("font", "").split() + weight = decls.get("font-weight") or next((t for t in tokens if re.fullmatch(r"\d{3}|bold|bolder|lighter", t)), "400") + if weight == "normal": + weight = "400" + if not weight.isdigit() or not WEIGHTS[fam][0] <= int(weight) <= WEIGHTS[fam][1]: + fail("fonts", f"{selector[:40]} sets font-weight {weight}, outside the {CSS_FAMILY[fam]} range: the browser would fake it") + style = decls.get("font-style") or next((t for t in tokens if t in ("italic", "oblique")), "normal") + if style not in ("normal", "inherit"): + fail("fonts", f"{selector[:40]} sets font-style {style}; no italic face is loaded") + labels = [d for c, s, d in css_rules(css) if s == ".lbl" and not c] + if not labels or not re.search(r"(? None: + """One type scale (ratio 1.25 on 16 px) and one spacing scale on the four sites.""" + for n in STEPS: + want = 1.25**n + got = root.get(f"step-{n}", "") + value = re.fullmatch(r"([\d.]+)rem", got) + if not value or abs(float(value.group(1)) - want) > 0.001: + fail("scale", f"--step-{n} is {got or 'missing'}; the scale is 1.25 ** {n} = {want:.4f}rem") + for _, selector, decls in css_rules(css): + if ":root" in selector or selector.startswith("@font-face"): + continue + sizes = [decls["font-size"]] if "font-size" in decls else [] + if "font" in decls: + sizes += re.findall(r"(\S+)\s*/", decls["font"]) or [decls["font"].split()[1] if len(decls["font"].split()) > 1 else ""] + for size in sizes: + if not re.fullmatch(r"var\(--(step-?-?\d|t-line|t-display)\)", size): + fail("scale", f"{selector[:40]} sets the size {size!r}; use a step of the type scale") + body = [d for c, s, d in css_rules(css) if s == "body" and not c] + if not body or f"/{LEADING} " not in body[0].get("font", ""): + fail("scale", f"body must set the line height {LEADING}, the same on the four sites") + for n, px in enumerate(SPACING, start=1): + if root.get(f"sp-{n}") != f"{px}px": + fail("spacing", f"--sp-{n} must be {px}px: the spacing scale is {', '.join(map(str, SPACING))} px") + if re.search(r"--sp-(?:[1-9]\d|0)\b", css): + fail("spacing", "the spacing scale has a token outside --sp-1 to --sp-9") + for _, selector, decls in css_rules(css): + for prop, value in decls.items(): + if re.fullmatch(r"(margin|padding|gap|row-gap|column-gap|inset|top|bottom|left|right)(-[a-z-]+)?", prop): + raw = re.findall(r"(? dict[str, str]: + """The declarations of the first rule with exactly this selector, under media conditions that contain condition + (no condition: a rule outside any media query).""" + for c, s, d in css_rules(css): + if s == selector and ((condition and any(condition in x for x in c)) or (not condition and not c)): + return d + return {} + + +def check_touch(css: str) -> None: + """The links a finger needs: 44 px high where they are small on a phone, the description links underlined.""" + if "underline" not in rule(css, "a.u, .ds a").get("text-decoration", ""): + fail("touch", "the link after a description must be underlined always, not only on hover") + if rule(css, ".ds a").get("padding-block") != "var(--sp-3)" or rule(css, ".ds a").get("margin-block") != "calc(-1 * var(--sp-3))": + fail("touch", ".ds a must add 12 px above and below its text without moving the line: 44 px to tap") + if rule(css, ".secs a").get("height") != "44px": + fail("touch", "a bar-2 section link must be 44 px high") + if rule(css, "footer a").get("min-height") != "44px": + fail("touch", "a footer link must be at least 44 px high") + for c, s, d in css_rules(css): + if s in ("footer a", ".b1 li", ".b1 a, .b1 span", ".logo", ".latest a") and any("max-width" in x for x in c): + for prop in ("height", "min-height"): + if prop in d and d[prop] not in ("44px", "100%"): + fail("touch", f"{s} is {d[prop]} high on a narrow screen; a tap needs 44 px") + dots = rule(css, "footer li::before") + if dots.get("content") != '"\\00b7"': + fail("touch", "the footer draws the dot before each name in the style, so a dot never wraps alone") + hover = rule(css, ".plate:hover .pic img, .plate:hover .tile", "(hover:hover)") + if "filter" not in hover: + fail("hover", "a plate image must show its hover state without motion: .plate:hover .pic img sets a filter") + + +def check_responsive(css: str, flat: str) -> None: + if ".row { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr));" not in flat: + fail("responsive", "the page grid is 12 columns: .row sets grid-template-columns: repeat(12, minmax(0, 1fr))") + if rule(css, ".grid").get("grid-template-columns") != "repeat(3, minmax(0, 1fr))": + fail("responsive", "the plate grid is 3 columns on a wide screen") + if rule(css, ".grid, .grid.g2", "(max-width:519px)").get("grid-template-columns") != "minmax(0, 1fr)": + fail("responsive", "the plate grid is one column below 520 px") + if not re.search(r"--max:\s*1200px", css): + fail("responsive", "the content width must be --max: 1200px") + if re.search(r"(? None: + """The style of the page: the house colours and the system stylesheet.""" + css = system + root = {k[2:]: v for k, v in rule(css, ":root").items() if k.startswith("--")} + found = re.search(r":root\{([^}]*)\}", first) + if not found: + fail("palette", "the page needs the :root block of the house colours") return - found = dict(re.findall(r"--([a-z-]+):\s*([^;]*);", root.group(1))) - tokens = {k: found.get(k, "").lower() for k in ("bg", "fg", "muted", "accent", "edge")} - for key, theme_key in (("bg", "ground"), ("fg", "text"), ("muted", "muted"), ("accent", "accent")): - if tokens[key] != THEME.get(theme_key): - fail("palette", f"--{key} is {tokens[key] or 'missing'}; allow.json gives {THEME.get(theme_key)}") - if not re.fullmatch(r"#[0-9a-f]{6}", tokens["edge"]): - fail("palette", "--edge must be #rrggbb") + tokens = {k: v.lower() for k, v in re.findall(r"--([a-z]+):(#[0-9a-fA-F]{6})", found.group(1))} + for key in THEME_KEYS: + if tokens.get(key) != THEME.get(key): + fail("palette", f"--{key} is {tokens.get(key) or 'missing'}; allow.json gives {THEME.get(key)}") + if set(tokens) != set(THEME_KEYS): return - family = THEME.get("font", "") - if not found.get("font", "").startswith(f'"{family}"') or not found.get("mono", "").startswith(f'"{WEFT}"'): - fail("fonts", f"--font must start with {family!r} and --mono with {WEFT!r}") - check_font_use(css, found) - check_scale_and_touch(css, found) - for key, need in (("fg", 4.5), ("muted", 4.5), ("accent", 3.0)): - ratio = contrast(tokens[key], tokens["bg"]) - if ratio < need: - fail("contrast", f"--{key} on --bg is {ratio:.2f}, below {need}") - check_refs(css, "style.css", "css") - check_colour_names(css, "style.css") + for fg, bg, floor in PAIRS: + ratio = contrast(tokens[fg], tokens[bg]) + if ratio < floor: + fail("contrast", f"--{fg} on --{bg} is {ratio:.2f}, below {floor}") + check_font_use(css, root) + check_scale(css, root) + check_touch(css) + check_refs(css, "the style", "css") + check_colour_names(css, "the style") if "prefers-color-scheme" in css or not re.search(r"color-scheme:\s*dark\b", css): - fail("dark", "the page is dark only: style.css sets color-scheme: dark and has no light scheme") - # The one gradient is the mask of the banner. It is cut out before the colour check, which refuses any other. + fail("dark", "the page is dark only: the style sets color-scheme: dark and has no light scheme") + # The masks are the only gradients. They are cut out before the colour check, which refuses any other. flat = re.sub(r"\s+", " ", css) - masks = flat.count(MASK) - if masks != 1: - fail("colour", f"style.css must hold the banner mask exactly once: {MASK}") - colours = colours_of(flat.replace(MASK, ""), "style.css") + rest = flat + for mask in MASKS: + if flat.count(f"-webkit-{mask}") != 1 or flat.count(mask) != 2: + fail("colour", f"the style must hold this mask once, with and without -webkit-: {mask}") + rest = rest.replace(mask, "") + colours = colours_of(rest, "the style") if colours - set(tokens.values()) - {"#000000"}: - fail("accent", f"style.css has colours outside the palette: {sorted(colours - set(tokens.values()) - {'#000000'})}") + fail("accent", f"the style has colours outside the palette: {sorted(colours - set(tokens.values()) - {'#000000'})}") if "var(--accent)" not in css: - fail("accent", "style.css never uses the accent colour") + fail("accent", "the style never uses the accent colour") check_text_colours(css, tokens) check_behaviour(css) - if f"grid-template-columns: {GRID}" not in flat: - fail("responsive", f"the plate grid must be grid-template-columns: {GRID}") - if not re.search(r"--max:\s*1200px", css): - fail("responsive", "the content width must be --max: 1200px") - if re.search(r"\bnowrap\b|(? None: @@ -1112,8 +1184,8 @@ def check_svg_safety(tree: ET.Element, where: str) -> None: for el in tree.iter(): local = el.tag.rsplit("}", 1)[-1] if local in SVG_FORBIDDEN: - rule = "colour" if local in ("linearGradient", "radialGradient", "stop") else "no-js" - fail(rule, f"{where} has <{local}>, which this site does not use") + rule_name = "colour" if local in ("linearGradient", "radialGradient", "stop") else "no-js" + fail(rule_name, f"{where} has <{local}>, which this site does not use") for key, value in el.attrib.items(): name = key.rsplit("}", 1)[-1] if re.fullmatch(r"on[a-z]+", name.lower()): @@ -1124,7 +1196,9 @@ def check_svg_safety(tree: ET.Element, where: str) -> None: def check_mark() -> None: - """The favicon, mark.svg: a valid, script-free svg whose only accent is the red of the mark.""" + """The favicon of machine-made, mark.svg: a valid, script-free svg whose only accent is the red of the mark.""" + if SELF != "machine-made": + return text = read("mark.svg") if not text: return @@ -1138,6 +1212,427 @@ def check_mark() -> None: fail("accent", "mark.svg needs exactly one accent colour, the red of the mark") +# ------------------------------------------------------------------ content +def sentences_of(paragraph: str) -> list[str]: + return re.split(r"(?<=[.!?])\s+", paragraph.strip()) + + +def check_prose(paragraphs: list[str], where: str) -> None: + for paragraph in paragraphs: + for sentence in sentences_of(paragraph): + if len(sentence.split()) > MAX_WORDS: + fail("voice", f"{where}: a sentence has more than {MAX_WORDS} words: {sentence[:40]}") + + +def line_html(face: str) -> str: + """The house line: a hyphenated word never breaks; in Warp, a word in capitals is set in small capitals.""" + t = re.sub(r"\b\w+(?:-\w+)+\b", lambda w: '' + w.group(0) + "", esc(LINE)) + if face == "warp": + t = re.sub(r"\b[A-Z]{2,}\b", lambda w: '' + w.group(0) + "", t) + return f'

    {t}

    ' + + +def bar2_html(root: str) -> str: + """The house logo, linked home, then one link per group and GitHub. The labels come from site.json, the targets + from allow.json.""" + labels = [g.get("nav", "") for g in site_json().get("groups", []) if isinstance(g, dict)] + if len(labels) != len(GROUPS): + return "" + secs = "".join(f'{esc(str(n))}' for (t, _), n in zip(GROUPS, labels, strict=True)) + secs += f'GitHub' + shown = site_title(site_name()) or SELF + if SELF == "machine-made": + logo = ( + '" + ) + else: + logo = f'' + return ( + f'
    ' + f'
    ' + ) + + +RED_CELL = ' class="r"' + + +def check_content(page: Page, html_text: str, shown: str | None) -> str: + """The home page, part by part, in order: bar 1, bar 2, the banner, the house line, Latest, the groups of + plates, the houses row, the footer.""" + text = " ".join(" ".join(page.text).split()) + visible = " ".join([text, *page.values, *page.hidden, *page.tags]) + face = THEME.get("face", "weft") + if shown and ("h1", shown) not in page.headings: + fail("content", f"the h1 must be the banner with the site name, {shown}, as its alt text") + title = re.search(r"([^<]+)", html_text) + if shown and (not title or html.unescape(title.group(1)) != shown): + fail("head", f"the title must be the site name, {shown}") + if bar1_html() not in html_text: + fail("content", f"bar 1 must read {' ยท '.join(n for n, _ in SITES)}: {SELF} marked with aria-current and not linked, type last") + if footer_html() not in html_text: + fail("content", f"the footer must link {' ยท '.join(n for n, _ in SITES)}, in that order, and nothing else") + if bar2_html("") not in html_text: + fail("content", "bar 2 must hold the logo (the mark, or the avatar at 28 px), linked home and named ' home', then one link per group in order and GitHub last") + banner = f'

    {picture("", "banner-" + house_key(SELF), BANNER_WIDTHS, BANNER_SIZE, shown or "", BANNER_SIZES, lazy=False)}

    ' + if banner not in html_text: + fail("content", "the h1 must hold the house banner, AVIF and JPEG at 704 and 1408 px, loaded first, with the name as alt text") + if line_html(face) not in html_text: + fail("content", f"the house line must follow the banner, in the house face ({face}), word for word as allow.json has it, each hyphenated word kept on one line") + if latest_html() not in html_text: + fail("latest", "Latest must list the newest release of each repository, distinct repositories, newest first, at most three, as the facts give them") + names = re.findall(r'
      (.*?)
    ', html_text) + shown_repos = re.findall(r'
  • ([^<]*)', names[0]) if names else [] + if len(set(shown_repos)) != len(shown_repos) or len(shown_repos) > 3: + fail("latest", "Latest repeats a repository or has more than three entries") + if houses_html() not in html_text: + fail("houses", "the houses row must show the other two houses and the type site: banner, line and newest release") + marks = ['class="b1"', 'class="b2"', 'class="banner"', f'class="line {face}"', 'aria-labelledby="g-latest"', + *(f'aria-labelledby="g-{slug(t)}"' for t, _ in GROUPS), 'aria-labelledby="g-houses"', "

    ' + re.escape(MK) + r'([^<]*)

      (.*?)
    ', + html_text, + ) + if len(sections) != len(GROUPS) or html_text.count(".*?
  • ', body) + if len(plates) != len(fulls) or "".join(plates) != body: + fail("projects", f"the group {want_title} must hold exactly its projects, in order") + continue + for full, plate in zip(fulls, plates, strict=True): + hit = plate_html(full).fullmatch(plate) + if not hit: + fail("projects", f"the plate of {full} is not the banner link (named by aria-label, empty alt text), one line, and its facts") + else: + lines.append(html.unescape(hit.group("line"))) + if re.match(rf"{re.escape(full.split('/')[1])}(?![\w-])", lines[-1], re.I): + fail("projects", f"the line of {full} starts with the repository name, which the banner already shows") + site_links = len(re.findall(r'

    [^<]* None: + """The 404 page: the same bars and footer, one line and a way home. GitHub Pages serves it at any depth, so + every local address starts at the site root.""" + face = THEME.get("face", "weft") + if f"Not found – {shown}" not in html_text: + fail("404", f"the title of the 404 page must be 'Not found โ€“ {shown}'") + if ("h1", "Not found") not in page.headings: + fail("404", "the h1 of the 404 page must read Not found") + if bar1_html() not in html_text or footer_html() not in html_text: + fail("404", "the 404 page has the same bar 1 and footer as the home page") + body = ( + f'

    Not found

    This page does not exist.

    ' + f'

    Back to {esc(shown or "")}

    ' + ) + if body not in html_text: + fail("404", "the 404 page says Not found in the house face, one line, and links back to the home page") + if bar2_html("/") not in html_text: + fail("404", "bar 2 of the 404 page links home and to each group from the site root") + for href in re.findall(r'(?:href|src)="([^"#][^"]*)"', html_text): + if "://" not in href and not href.startswith("/"): + fail("404", f"the 404 page names {href} relative to itself; it is served at any depth, so start at the root") + for target in (t.strip("\"' ") for style in page.styles for t in re.findall(r"url\(([^)]*)\)", style)): + if not target.startswith(("/", "#")): + fail("404", f"the 404 page loads {target} relative to itself; start at the root") + + +def emitted(visible: str) -> Iterator[tuple[str, str]]: + """Every emitted text file as (name, text). The home page counts as what a reader or a crawler gets.""" + yield "index.html", visible + for path in sorted(DOCS.rglob("*")): + name = path.relative_to(DOCS).as_posix() + if path.is_file() and name != "index.html" and path.suffix in (".html", ".txt", ".svg"): + yield name, path.read_text(encoding="utf-8", errors="replace") + + +def decoded(source: str) -> str: + """source with every character reference decoded, however deeply it is nested.""" + while (plain := html.unescape(source)) != source: + source = plain + return source + + +def check_leaks(visible: str, deny: list[str]) -> None: + forwards = {f"{folder}/index.html": url.split("//", 1)[1] for folder, url in REDIRECTS.items()} + public = {f"github.com/{full}" for full in repos_of()} | {f"github.com/{OWNER}"} + public |= {u.split("//", 1)[1] for u in release_urls()} + # The houses row names the newest release of the other houses, so their repositories are known names too. + known = {full.split("/")[1].lower() for full in [*repos_of(), *(f for _, fulls in OTHERS.values() for f in fulls)]} + for name, raw in emitted(visible): + # Files are plain ASCII. + if not raw.isascii(): + fail("voice", f"docs/{name} has characters that are not plain ASCII") + continue + source = raw + "\n" + decoded(raw) + for match in GITHUB.findall(source): + ok = match == forwards.get(name) or match in LICENCE_URLS.get(name, ()) or match in public + if not ok: + fail("private", f"{match} is not in the public list ({name})") + for repo in RS_NAME.findall(source): + if repo.lower() not in known: + fail("private", f"{repo} looks like a repository that is not in the public list ({name})") + for word in deny: + if re.search(rf"(? None: + """Money, internal words, and the words that never reach public text, in every text file.""" + for path in sorted(DOCS.rglob("*")): + if path.is_file() and path.suffix in (".html", ".txt", ".svg"): + text = path.read_text(encoding="utf-8", errors="replace") + rel = path.relative_to(DOCS).as_posix() + hit = FORBIDDEN.search(text) + if hit: + fail("forbidden", f"docs/{rel} contains {hit.group(0)!r}") + # Public words: the text a reader sees and the attribute values a reader or a crawler gets. + plain = decoded(visible_text(text) if path.suffix == ".html" else text) + for ok in BANNED_OK: + plain = plain.replace(ok, "") + hit = BANNED.search(plain) + if hit and not rel.startswith("fonts/"): + fail("forbidden", f"docs/{rel} contains the word {hit.group(0)!r}") + for never in NEVER: + if never in decoded(text): + fail("forbidden", f"docs/{rel} names {never}, which is never listed") + + +# ------------------------------------------------------------------ images and fonts +def scaled(size: tuple[int, int], width: int) -> tuple[int, int]: + return width, round(size[1] * width / size[0]) + + +def jpeg_size(data: bytes) -> tuple[int, int] | None: + """(width, height) of a JPEG, read from its first start-of-frame marker. None when it is not a JPEG.""" + if data[:3] != b"\xff\xd8\xff": + return None + i = 2 + while i + 9 < len(data): + if data[i] != 0xFF: + i += 1 + continue + marker = data[i + 1] + if marker in (0xD8, 0x01) or 0xD0 <= marker <= 0xD7 or marker == 0xFF: + i += 1 if marker == 0xFF else 2 + continue + length = int.from_bytes(data[i + 2 : i + 4], "big") + if marker in (0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF): + return int.from_bytes(data[i + 7 : i + 9], "big"), int.from_bytes(data[i + 5 : i + 7], "big") + i += 2 + length + return None + + +def avif_size(data: bytes) -> tuple[int, int] | None: + """(width, height) of an AVIF, from its ftyp brand and its ispe box. None when it is not an AVIF.""" + if data[4:12] != b"ftypavif": + return None + at = data.find(b"ispe") + if at < 0: + return None + return int.from_bytes(data[at + 8 : at + 12], "big"), int.from_bytes(data[at + 12 : at + 16], "big") + + +def decode_problem(data: bytes, size: tuple[int, int]) -> str | None: + """Why the image does not decode to the size its header declares, or None. A header can survive the loss of + the image data, so the pixels are decoded.""" + try: + from PIL import Image + except ImportError: + return "cannot be decoded here: run check_site.py under uv run --with pillow" + try: + with Image.open(io.BytesIO(data)) as im: + im.load() + if im.size != size: + return f"decodes to {im.size[0]} x {im.size[1]}, not the {size[0]} x {size[1]} it declares" + except (OSError, ValueError, SyntaxError) as exc: + return f"does not decode ({exc.__class__.__name__})" + return None + + +def png_size(data: bytes) -> tuple[int, int] | None: + if data[:8] != b"\x89PNG\r\n\x1a\n" or data[12:16] != b"IHDR": + return None + return int.from_bytes(data[16:20], "big"), int.from_bytes(data[20:24], "big") + + +def expected_size(rel: str) -> tuple[int, int] | None: + if rel == "og.jpg": + return OG_SIZE + if rel in PNG_SIZES: + return PNG_SIZES[rel], PNG_SIZES[rel] + hit = re.fullmatch(r"img/(.+)-(\d+)\.(?:avif|jpg)", rel) + if not hit: + return None + full = BANNER_SIZE if hit.group(1).startswith("banner-") else PLATE_SIZE + return scaled(full, int(hit.group(2))) + + +def check_images() -> None: + """Each image is a real JPEG, AVIF or PNG of the size the page declares, complete, and no larger than it needs.""" + paths = [DOCS / "og.jpg", *sorted((DOCS / "img").glob("*"))] if (DOCS / "img").is_dir() else [DOCS / "og.jpg"] + for path in paths: + if not path.is_file(): + continue + rel = path.relative_to(DOCS).as_posix() + data = path.read_bytes() + reader = {".jpg": jpeg_size, ".avif": avif_size, ".png": png_size}.get(path.suffix) + size = reader(data) if reader else None + want = expected_size(rel) + if size is None: + fail("images", f"docs/{rel} is not a {path.suffix[1:].upper()} image") + elif path.suffix == ".jpg" and not data.endswith(b"\xff\xd9"): + fail("images", f"docs/{rel} is cut short: it has no end-of-image marker") + elif path.suffix == ".png" and not data.endswith(b"IEND\xaeB`\x82"): + fail("images", f"docs/{rel} is cut short: it has no IEND chunk") + elif size != want: + fail("images", f"docs/{rel} is {size[0]} x {size[1]}; it must be {want[0] if want else '?'} x {want[1] if want else '?'}") + elif path.suffix in (".avif", ".jpg") and (problem := decode_problem(data, size)): + fail("images", f"docs/{rel} {problem}") + if len(data) > MAX_IMAGE_BYTES: + fail("images", f"docs/{rel} is {len(data)} bytes; the limit is {MAX_IMAGE_BYTES}") + + +def check_font_sources() -> None: + """The source fonts in fonts/ are the release files that SOURCES pins, and fonts/SOURCES.json says the same.""" + try: + listed = json.loads((FONT_DIR / "SOURCES.json").read_text(encoding="utf-8"))["fonts"] + except (OSError, ValueError, KeyError) as exc: + fail("fonts", f"fonts/SOURCES.json is missing or unreadable ({exc.__class__.__name__})") + return + if set(listed) != set(SOURCES): + fail("fonts", f"fonts/SOURCES.json lists {sorted(listed)}; the checks pin {sorted(SOURCES)}") + for name, (family, version, digest) in SOURCES.items(): + entry = listed.get(name, {}) + if (entry.get("family"), entry.get("version"), entry.get("sha256")) != (family, version, digest): + fail("fonts", f"fonts/SOURCES.json disagrees with the pinned {name}: {family} {version}") + path = FONT_DIR / name + if not path.is_file() or hashlib.sha256(path.read_bytes()).hexdigest() != digest: + fail("fonts", f"fonts/{name} is not the {family} {version} release file") + + +def check_subsets(pages: list[str]) -> None: + """Each font in docs/fonts/ is a subset of its pinned source: a woff2 of the same family, every variation axis + and every feature the style uses kept, every glyph it holds from the source, and every character the page sets + in it present.""" + try: + from fontTools.ttLib import TTFont + except ImportError: + fail("fonts", "the font checks need fontTools and brotli: run check_site.py under uv run --with fonttools --with brotli") + return + from io import BytesIO + + def meta(font: "TTFont") -> tuple[list[tuple[str, float, float]], set[str], str, set[int]]: + axes = [(a.axisTag, a.minValue, a.maxValue) for a in font["fvar"].axes] if "fvar" in font else [] + feats = {r.FeatureTag for t in ("GSUB", "GPOS") if t in font for r in font[t].table.FeatureList.FeatureRecord} + name = font["name"].getDebugName(16) or font["name"].getDebugName(1) or "" + return axes, feats, name, set(font.getBestCmap()) + + text = "".join(visible_text(p) for p in pages) + chars = {ord(c) for c in text + text.upper() if not c.isspace()} + for f in uses(): + path = DOCS / "fonts" / f"{f}.woff2" + if not path.is_file(): + continue + data = path.read_bytes() + if data[:4] != b"wOF2": + fail("fonts", f"docs/fonts/{f}.woff2 is not a woff2 font") + continue + try: + sub = meta(TTFont(BytesIO(data))) + src = meta(TTFont(FONT_DIR / FONT_SOURCE[f])) + except Exception as exc: # noqa: BLE001 -- any parse error of the shipped file is a failure to report + fail("fonts", f"docs/fonts/{f}.woff2 cannot be read as a font ({exc.__class__.__name__})") + continue + if sub[2] != src[2]: + fail("fonts", f"docs/fonts/{f}.woff2 is {sub[2]!r}, not a subset of {src[2]!r}") + if sub[0] != src[0]: + fail("fonts", f"docs/fonts/{f}.woff2 lost a variation axis: {src[0]} became {sub[0]}") + lost = (src[1] & USED_FEATURES) - sub[1] + if lost: + fail("fonts", f"docs/fonts/{f}.woff2 lost the features {sorted(lost)}") + if sub[3] - src[3]: + fail("fonts", f"docs/fonts/{f}.woff2 holds characters its source does not have") + need = chars if f in ("weft", "sans") else {ord(c) for p in pages for c in face_text(p, f) if not c.isspace()} + missing = sorted(chr(c) for c in need & src[3] - sub[3]) + if missing: + fail("fonts", f"docs/fonts/{f}.woff2 lacks characters the page sets in it: {''.join(missing)[:20]!r}") + + +class FaceText(HTMLParser): + """The text inside any element whose class names the face.""" + + def __init__(self, face: str) -> None: + super().__init__(convert_charrefs=True) + self.face, self.stack, self.out = face, [], set() + + def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None: + if tag not in VOID and tag != "rect": + self.stack.append(self.face in (dict(attrs).get("class") or "").split()) + + def handle_endtag(self, tag: str) -> None: + if tag not in VOID and tag != "rect" and self.stack: + self.stack.pop() + + def handle_data(self, data: str) -> None: + if any(self.stack): + self.out |= set(data) + + +def strip_code(page: str) -> str: + return re.sub(r"<(script|style)[^>]*>.*?", " ", page, flags=re.S) + + +def visible_text(page: str) -> str: + page = strip_code(page) + page = re.sub(r'(?:aria-label|alt|title|content)="([^"]*)"', lambda m: " " + m.group(1) + " ", page) + return html.unescape(re.sub(r"<[^>]+>", " ", page)) + + +def face_text(page: str, face: str) -> set[str]: + parser = FaceText(face) + parser.feed(strip_code(page)) + return parser.out + + def check_llms(name: str | None) -> None: text = read("llms.txt") if not text: @@ -1145,13 +1640,13 @@ def check_llms(name: str | None) -> None: links = re.findall(r"\]\((https://[^)]+)\)", text) expected = [f"https://github.com/{full}" for full in repos_of()] + [u for _, u in SITES] + list(SITE_LINKS.values()) if sorted(links) != sorted(expected): - fail("llms", "llms.txt must list exactly the public repositories, the project sites and the three sites") + fail("llms", "llms.txt must list exactly the public repositories, the project sites and the four sites") shown = site_title(name) - if shown and not text.startswith(f"# {shown}\n\n> {LINE}\n\n{BLURB}\n\n## "): - fail("llms", "llms.txt must start with the name, the line and the paragraph on the name") + if shown and not text.startswith(f"# {shown}\n\n> {LINE}\n\n## "): + fail("llms", "llms.txt must start with the name and the line") sites = "".join(f"- [{n}]({u})\n" for n, u in SITES) if not text.endswith(f"## Sites\n\n{sites}"): - fail("llms", "llms.txt must end with the Sites section: the three sites") + fail("llms", "llms.txt must end with the Sites section: the four sites") found = [ (title, re.findall(rf"{GITHUB_URL}/([\w.-]+/[\w.-]+)", body)) for title, body in re.findall(r"## ([^\n]+)\n\n((?:- [^\n]*\n?)+)", text, re.S) @@ -1173,6 +1668,7 @@ def parse_args(argv: list[str]) -> argparse.Namespace: parser.add_argument("--deny", metavar="FILE", help="names that must not appear in the output") parser.add_argument("--self-test", action="store_true", help="break a copy of docs/ and check the breaks are caught") parser.add_argument("--site", metavar="DIR", help="check another house: DIR holds site.json, allow.json and docs/") + parser.add_argument("--data", metavar="FILE", help="the GitHub facts file that fetch.py wrote and build.py read") return parser.parse_args(argv) @@ -1190,30 +1686,86 @@ def load_deny(path: str | None) -> list[str]: return [name for name in names if name and not name.startswith("#")] +def release_record_ok(record: object) -> bool: + return isinstance(record, dict) and all(isinstance(record.get(k), str) for k in ("tagName", "publishedAt", "url")) + + +def repo_record_ok(record: object) -> bool: + """A repository record as fetch.py writes it: language, latest release, last commit, recent releases.""" + if not isinstance(record, dict) or not isinstance(record.get("commit"), str): + return False + if not (record.get("lang") is None or isinstance(record.get("lang"), str)): + return False + if not (record.get("release") is None or release_record_ok(record.get("release"))): + return False + releases = record.get("releases") + return isinstance(releases, list) and all(release_record_ok(r) for r in releases) + + +def load_data(path: str | None) -> None: + """The GitHub facts: every repository of the three houses and the type families.""" + global DATA # noqa: PLW0603 + path = path or os.environ.get("MM_DATA") + if not path: + print("FAIL args: name the GitHub facts file with --data FILE (python3 fetch.py FILE writes it)") + sys.exit(2) + try: + DATA = json.loads(Path(path).read_text(encoding="utf-8")) + datetime.date.fromisoformat(DATA["fetched"]) + fulls = [*repos_of(), *(f for _, fulls in OTHERS.values() for f in fulls)] + missing = [f for f in fulls if f not in DATA["repos"]] + if missing or set(DATA["families"]) != {"weft", "sans", "heddle", "warp"}: + raise KeyError(missing[0] if missing else "families") + for full in fulls: + if not repo_record_ok(DATA["repos"][full]): + raise KeyError(f"{full} record") + for family, record in DATA["families"].items(): + if not release_record_ok(record): + raise KeyError(f"{family} record") + except (OSError, ValueError, KeyError, TypeError) as exc: + print(f"FAIL args: the GitHub facts file {path} is missing or incomplete ({exc.__class__.__name__}: {exc})") + sys.exit(2) + + def run_checks(deny: list[str]) -> list[str]: del failures[:] name = site_name() + shown = site_title(name) check_files() check_redirects() - html_text = read("index.html") - if html_text: - page = Page() - page.feed(html_text) - page.close() - check_html(page, html_text, name) - visible = check_content(page, html_text) - check_leaks(visible, deny) - check_fonts(html_text) + check_font_sources() + pages = [] + visible = "" + for rel, rooted in (("index.html", False), ("404.html", True)): + html_text = read(rel) + if not html_text: + if (DOCS / rel).is_file(): + fail("files", f"docs/{rel} is empty; run python3 build.py") + continue + pages.append(html_text) + page = parse(html_text) + prefix = "/" if rooted else "" + check_html(page, html_text, rel, rooted) + check_head(page, html_text, shown, rel, prefix) + system = check_styles(page, rel, prefix) + check_font_faces(page.styles[0] if page.styles else "", rel, prefix) + check_preloads(html_text, rel, prefix, banner=not rooted) + if rooted: + check_not_found(page, html_text, shown) + else: + visible = check_content(page, html_text, shown) + check_css(system, page.styles[0] if page.styles else "") + check_subsets(pages) + check_leaks(visible, deny) check_forbidden() check_images() - check_css() check_mark() check_llms(name) return list(failures) +# ------------------------------------------------------------------ self-test LONG = " ".join(["word"] * 30) + "." -STYLE_LINK = '' def edit(docs: Path, name: str, old: str, new: str) -> None: @@ -1230,99 +1782,112 @@ def edit_all(docs: Path, name: str, *pairs: tuple[str, str]) -> None: edit(docs, name, old, new) -def site_copy(root: Path, changes: dict[str, object]) -> subprocess.CompletedProcess[bytes]: +def edit_css(docs: Path, old: str, new: str) -> None: + """Change the system style the way a changed src/system.css would: in the source copy and in both pages, so that + only the rule under test can catch it.""" + global SYSTEM_SRC # noqa: PLW0603 + copy = docs.parent / "system.css" + if not copy.is_file(): + shutil.copy(SYSTEM_SRC, copy) + SYSTEM_SRC = copy + text = copy.read_text(encoding="utf-8") + flat_old = old + if flat_old not in text: + raise AssertionError(f"self-test is stale: {old!r} is not in src/system.css") # noqa: TRY003 + copy.write_text(text.replace(old, new, 1), encoding="utf-8") + for page in ("index.html", "404.html"): + edit(docs, page, old, new) + + +def site_copy(root: Path, changes: dict[str, object], data: Path) -> subprocess.CompletedProcess[bytes]: """Build a copy of the generator in root, with these keys of site.json changed.""" (root / "src").mkdir(parents=True) - for rel in ("build.py", "card.py", "src/style.css"): - shutil.copy(ROOT / rel, root / rel) - shutil.copytree(ROOT / "fonts", root / "fonts") - shutil.copytree(ROOT / "img", root / "img") - data = json.loads((ROOT / "site.json").read_text(encoding="utf-8")) - old = data["name"] - data.update(changes) + for rel in ("build.py", "card.py", "fetch.py", "src/system.css", "allow.json"): + shutil.copy(GEN / rel, root / rel) + for folder in ("fonts", "img", "houses"): + shutil.copytree(GEN / folder, root / folder, ignore=shutil.ignore_patterns("docs")) + site = json.loads((GEN / "site.json").read_text(encoding="utf-8")) + old = site["name"] + site.update(changes) new = changes.get("name") if isinstance(new, str) and FILE_NAME.fullmatch(new) and ".." not in new: # A renamed site keeps the banner of the site it was copied from, under the new name. - shutil.copy(ROOT / "img" / "org" / f"{old}.jpg", root / "img" / "org" / f"{new}.jpg") - if "title" not in changes: - data.pop("title", None) - (root / "site.json").write_text(json.dumps(data), encoding="utf-8") + shutil.copy(GEN / "img" / "org" / f"{old}.jpg", root / "img" / "org" / f"{new}.jpg") + (root / "site.json").write_text(json.dumps(site), encoding="utf-8") env = {**os.environ, "PYTHONDONTWRITEBYTECODE": "1"} - return subprocess.run([sys.executable, str(root / "build.py")], capture_output=True, env=env) + return subprocess.run([sys.executable, str(root / "build.py"), "--data", str(data)], capture_output=True, env=env, check=False) -def build_rejects(changes: dict[str, object]) -> bool: - """True when build.py exits 2 on a site.json with these changes and writes no docs/ outside the copy.""" +def build_rejects(changes: dict[str, object], data: Path) -> bool: + """True when build.py exits 2 on a site.json with these changes and writes no page.""" with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) / "site" - done = site_copy(root, changes) - outside = [p.name for p in Path(tmp).rglob("*.html") if root / "docs" not in p.parents] - return done.returncode == 2 and not outside + done = site_copy(root, changes, data) + written = [p.name for p in Path(tmp).rglob("*.html")] + return done.returncode == 2 and not written -def build_needs(rel: str) -> bool: +def build_needs(rel: str, data: Path) -> bool: """True when build.py exits 2 without this file of the generator and writes no docs/.""" with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) / "site" - site_copy(root, {}) + site_copy(root, {}, data) shutil.rmtree(root / "docs") - target = root / rel - target.unlink() + (root / rel).unlink() env = {**os.environ, "PYTHONDONTWRITEBYTECODE": "1"} - done = subprocess.run([sys.executable, str(root / "build.py")], capture_output=True, env=env) + done = subprocess.run([sys.executable, str(root / "build.py"), "--data", str(data)], capture_output=True, env=env, check=False) return done.returncode == 2 and not (root / "docs").exists() -def renamed_site_passes(new_name: str) -> bool: - """True when a site built under another name passes every check.""" - global ROOT, DOCS - real_root, real_docs = ROOT, DOCS +def build_fails_on_fetch() -> bool: + """True when build.py, left to fetch for itself with gh unreachable, exits 2 and writes no docs/.""" with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) / "site" - if site_copy(root, {"name": new_name}).returncode != 0: - return False - ROOT, DOCS = root, root / "docs" - try: - return not run_checks([]) - finally: - ROOT, DOCS = real_root, real_docs + site_copy(root, {}, Path(DATA_PATH)) + shutil.rmtree(root / "docs") + env = {**os.environ, "PYTHONDONTWRITEBYTECODE": "1", "PATH": str(Path(tmp) / "nobin"), "GH_TOKEN": "x"} + done = subprocess.run([sys.executable, str(root / "build.py")], capture_output=True, env=env, check=False) + return done.returncode == 2 and not (root / "docs").exists() def cli_fails(args: list[str], prefix: str) -> bool: """True when check_site.py exits 2 with exactly one line that starts with prefix.""" - env = {k: v for k, v in os.environ.items() if k != "MM_DENY_FILE"} + env = {k: v for k, v in os.environ.items() if k not in ("MM_DENY_FILE", "MM_DATA")} env["PYTHONDONTWRITEBYTECODE"] = "1" done = subprocess.run( - [sys.executable, str(Path(__file__).resolve()), *args], capture_output=True, text=True, env=env + [sys.executable, str(Path(__file__).resolve()), *args], capture_output=True, text=True, env=env, check=False ) lines = done.stdout.splitlines() return done.returncode == 2 and len(lines) == 1 and lines[0].startswith(prefix) and not done.stderr -def site_links_hold() -> list[str]: +DATA_PATH = "" + + +def site_links_hold(data: Path) -> list[str]: """The site-link fixture for a plain address and for one with a query string, which the page writes with &.""" return [ - *site_link_fixture("https://machine-made.github.io/zz-site/"), - *site_link_fixture("https://example.net/docs/?a=1&b=2"), + *site_link_fixture("https://machine-made.github.io/zz-site/", data), + *site_link_fixture("https://example.net/docs/?a=1&b=2", data), ] -def site_link_fixture(url: str) -> list[str]: - """Build a site with one more project site link and run the checks on it: it passes, and each way - of breaking the link fails. The checks read the link from the public list, so the list changes too.""" - global DOCS, SITE_LINKS +def site_link_fixture(url: str, data: Path) -> list[str]: + """Build a site with one more project site link and run the checks on it: it passes, and each way of breaking the + link fails. The checks read the link from the public list, so the list changes too.""" + global DOCS, SITE_LINKS # noqa: PLW0603 real_docs, real_links = DOCS, SITE_LINKS full = next(f for f in repos_of() if f not in real_links) repo, eurl = full.split("/")[1], html.escape(url) problems: list[str] = [] - data = json.loads((ROOT / "site.json").read_text(encoding="utf-8")) - next(p for g in data["groups"] for p in g["projects"] if p["repo"] == repo)["site"] = url - link = f' site' + site = json.loads((GEN / "site.json").read_text(encoding="utf-8")) + next(p for g in site["groups"] for p in g["projects"] if p["repo"] == repo)["site"] = url + link = f' site' breaks: list[tuple[str, Callable[[Path], object]]] = [ ("site link missing", lambda d: edit(d, "index.html", link, "")), ("site link on another host", lambda d: edit(d, "index.html", eurl, "https://example.net/zz-site/")), ("site link to another path", lambda d: edit(d, "index.html", eurl, "https://machine-made.github.io/other/")), - ("second site link", lambda d: edit(d, "index.html", "", f'
  • x
  • ')), + ("second site link", lambda d: edit(d, "index.html", "", f'

    x x

    ')), ("site link says docs but the list says site", lambda d: edit(d, "index.html", f'aria-label="{repo} site">site', f'aria-label="{repo} docs">docs')), ("site link without its accessible name", lambda d: edit(d, "index.html", f' aria-label="{repo} site"', "")), ("site link on the banner", lambda d: edit(d, "index.html", f'' def plate_edit(repo: str, change: Callable[[str], str]) -> Callable[[Path], object]: """Change the markup of one plate: change() takes the
  • of the repository and returns the new one.""" @@ -1379,80 +1946,88 @@ def run(d: Path) -> None: return run cases: list[Case] = [ - ("private name in style.css", "private", ["zzprivate"], lambda d: edit(d, "style.css", "box-sizing", "/* zzprivate */ box-sizing")), - ("private name in the mark svg", "private", ["zzprivate"], lambda d: edit(d, "mark.svg", "", "<title>zzprivate ")), + ("private name in the style", "private", ["zzprivate"], lambda d: edit(d, "index.html", "<style>", "<style>/* zzprivate */")), + ("private name in the mark svg", "private", ["zzprivate"], lambda d: edit(d, "mark.svg", "<title>", "<title>zzprivate ") if SELF == "machine-made" else edit(d, "404.html", "<body>", "<body><!-- zzprivate -->")), ("private name in an html comment", "private", ["zzprivate"], lambda d: edit(d, "index.html", "<body>", "<body><!-- zzprivate -->")), ("private link", "links", [], lambda d: edit(d, "index.html", f"/{first}\"", "/zzprivate\"")), ("private rs name in llms.txt", "private", [], lambda d: edit(d, "llms.txt", "## Sites", "zz-rs\n\n## Sites")), - ("long project line", "voice", [], lambda d: edit(d, "index.html", '<span class="ds">', f'<span class="ds">{LONG} ')), - ("long org line", "voice", [], lambda d: edit(d, "llms.txt", f"> {LINE}", f"> {LONG} {LINE}")), + ("empty 404 page", "files", [], lambda d: (d / "404.html").write_text("", encoding="utf-8")), + ("AVIF cut in half", "images", [], lambda d: (p := d / "img" / f"{first}-704.avif").write_bytes(p.read_bytes()[: p.stat().st_size // 2])), + ("relative url in the 404 system style", "404", [], lambda d: edit(d, "404.html", "box-sizing: border-box;", "box-sizing: border-box; cursor: url(img/touch.png), auto;")), + ("long project line", "voice", [], lambda d: edit(d, "index.html", '<p class="ds">', f'<p class="ds">{LONG} ')), + ("long house line", "voice", [], lambda d: edit(d, "llms.txt", f"> {LINE}", f"> {LONG} {LINE}")), ("long line in llms.txt", "voice", [], lambda d: edit(d, "llms.txt", "## Sites", f"{LONG}\n\n## Sites")), - ("alpha hex in a variable", "colour", [], lambda d: edit(d, "style.css", f"--muted:{THEME['muted']}", f"--muted:{THEME['muted']}80")), - ("short alpha hex in a rule", "colour", [], lambda d: edit(d, "style.css", "box-sizing", "color:#fff8;box-sizing")), - ("second accent", "accent", [], lambda d: edit(d, "style.css", "box-sizing", "color:#0000ff;box-sizing")), - ("a hex grey outside the palette", "accent", [], lambda d: edit(d, "style.css", "box-sizing", "color:#777777;box-sizing")), - ("accent changed in style.css", "palette", [], lambda d: edit(d, "style.css", f"--accent:{THEME['accent']}", "--accent:#123456")), - ("ground changed in style.css", "palette", [], lambda d: edit(d, "style.css", css_first, ":root{--bg:#222222;")), - ("light scheme comes back", "dark", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}@media (prefers-color-scheme: light){a{margin:0")), + ("alpha hex in a variable", "colour", [], lambda d: edit_all(d, "index.html", (f"--muted:{THEME['muted']}", f"--muted:{THEME['muted']}80"))), + ("short alpha hex in a rule", "colour", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:#fff8;box-sizing: border-box;")), + ("second accent", "accent", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:#0000ff;box-sizing: border-box;")), + ("a hex grey outside the palette", "accent", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:#777777;box-sizing: border-box;")), + ("accent changed in the page", "palette", [], lambda d: edit(d, "index.html", f"--accent:{THEME['accent']}", "--accent:#123456")), + ("ground changed in the page", "palette", [], lambda d: edit(d, "index.html", tokens_first, ":root{--ground:#222222;")), + ("surface changed in the page", "palette", [], lambda d: edit(d, "index.html", f"--surface:{THEME['surface']}", "--surface:#333333")), + ("light scheme comes back", "dark", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }@media (prefers-color-scheme: light){a{margin:0}}")), ("color-scheme meta is light dark", "dark", [], lambda d: edit(d, "index.html", 'content="dark"', 'content="light dark"')), ("theme-color differs from the ground", "dark", [], lambda d: edit(d, "index.html", f'name="theme-color" content="{THEME["ground"]}"', 'name="theme-color" content="#ffffff"')), - ("link leaves docs/", "links", [], lambda d: edit(d, "index.html", 'href="style.css"', 'href="../README.md"')), - ("image leaves docs/", "links", [], lambda d: edit(d, "index.html", 'src="img/banner.jpg"', 'src="../README.md"')), - ("icon leaves docs/", "links", [], lambda d: edit(d, "index.html", 'href="mark.svg"', 'href="../README.md"')), - ("absolute local link", "links", [], lambda d: edit(d, "index.html", 'href="style.css"', 'href="/etc/hostname"')), - ("protocol-relative link", "links", [], lambda d: edit(d, "index.html", 'href="style.css"', 'href="//example.com/x.css"')), - ("Google Fonts stylesheet", "links", [], lambda d: edit(d, "index.html", STYLE_LINK, '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Other">' + STYLE_LINK)), - ("font preconnect", "links", [], lambda d: edit(d, "index.html", STYLE_LINK, '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>' + STYLE_LINK)), - ("remote stylesheet", "links", [], lambda d: edit(d, "index.html", 'href="style.css"', 'href="https://example.net/style.css"')), - ("preload of a remote font", "links", [], lambda d: edit(d, "index.html", 'href="fonts/mm-weft.woff2"', 'href="https://fonts.gstatic.com/x.woff2"')), - ("preload of a file that is not a font", "fonts", [], lambda d: edit(d, "index.html", 'href="fonts/mm-weft.woff2"', 'href="mark.svg"')), + ("link leaves docs/", "links", [], lambda d: edit(d, "index.html", 'href="./"', 'href="../README.md"')), + ("image leaves docs/", "links", [], lambda d: edit(d, "index.html", f'src="img/{first}-704.jpg"', 'src="../README.md"')), + ("srcset leaves docs/", "links", [], lambda d: edit(d, "index.html", f'srcset="img/{first}-352.avif', 'srcset="../README.md')), + ("icon leaves docs/", "links", [], lambda d: edit(d, "index.html", 'href="img/touch.png"', 'href="../README.md"')), + ("absolute local link", "links", [], lambda d: edit(d, "index.html", 'href="./"', 'href="/etc/hostname"')), + ("root link on the home page", "links", [], lambda d: edit(d, "index.html", 'href="./"', 'href="/"')), + ("protocol-relative link", "links", [], lambda d: edit(d, "index.html", 'href="./"', 'href="//example.com/x.css"')), + ("Google Fonts stylesheet", "links", [], lambda d: edit(d, "index.html", "<style>", '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Other"><style>')), + ("font preconnect", "links", [], lambda d: edit(d, "index.html", "<style>", '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><style>')), + ("remote stylesheet", "links", [], lambda d: edit(d, "index.html", "<style>", '<link rel="stylesheet" href="https://example.net/style.css"><style>')), + ("preload of a remote font", "links", [], lambda d: edit(d, "index.html", f'href="fonts/{face}.woff2"', 'href="https://fonts.gstatic.com/x.woff2"')), + ("preload of a file that is not the house face", "fonts", [], lambda d: edit(d, "index.html", f'<link rel="preload" href="fonts/{face}.woff2"', '<link rel="preload" href="fonts/sans.woff2"')), ("preload without crossorigin", "fonts", [], lambda d: edit(d, "index.html", 'type="font/woff2" crossorigin>', 'type="font/woff2">')), - ("no preload", "fonts", [], lambda d: edit_all(d, "index.html", *[(f'<link rel="preload" href="fonts/{f}.woff2" as="font" type="font/woff2" crossorigin>\n', "") for f in {"mm-weft", font_stem}])), - ("css font face from a font host", "links", [], lambda d: edit(d, "style.css", "url(fonts/mm-weft.woff2)", "url(https://fonts.gstatic.com/s/other/v1/x.woff2)")), - ("css imports Google Fonts", "links", [], lambda d: edit(d, "style.css", ":root{", '@import url("https://fonts.googleapis.com/css2?family=Other");:root{')), - ("css font face from a local file that is not the font", "fonts", [], lambda d: edit(d, "style.css", "url(fonts/mm-weft.woff2)", "url(fonts/mark.woff2)")), - ("css font face for another family", "fonts", [], lambda d: edit(d, "style.css", '@font-face{font-family:"machine-made Weft"', '@font-face{font-family:"Other"')), - ("css font face for Lato", "fonts", [], lambda d: edit(d, "style.css", '@font-face{font-family:"machine-made Weft"', '@font-face{font-family:"Lato"')), - ("css font face for EB Garamond", "fonts", [], lambda d: edit(d, "style.css", '@font-face{font-family:"machine-made Weft"', '@font-face{font-family:"EB Garamond"')), - ("css font face without swap", "fonts", [], lambda d: edit(d, "style.css", "font-display:swap", "font-display:block")), - ("css font face with another weight", "fonts", [], lambda d: edit(d, "style.css", "font-weight:100 900", "font-weight:400")), - ("css font face with another style", "fonts", [], lambda d: edit(d, "style.css", "font-weight:100 900;font-style:normal", "font-weight:100 900;font-style:italic")), - ("css font face drops a face", "fonts", [], lambda d: (d / "style.css").write_text("\n".join(line for line in read_css(d).splitlines() if font_stem not in line) + "\n") if font_stem != "mm-weft" else edit(d, "style.css", "url(fonts/mm-weft.woff2)", "url(fonts/mm-sans.woff2)")), - ("a stack names a system font", "fonts", [], lambda d: edit(d, "style.css", "ui-monospace, monospace", "ui-monospace, Georgia, monospace")), - ("a rule sets a font family of its own", "fonts", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{font-family:Lato;margin")), - ("a rule sets a named family in the font shorthand", "fonts", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{font:400 1rem Lato;margin")), - ("a rule sets bold", "fonts", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{font-weight:700;margin")), - ("a rule sets bold in the font shorthand", "fonts", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{font:700 1rem var(--font);margin")), - *([("a rule sets italic", "fonts", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{font-style:italic;margin"))] if not italic_ok else []), - ("the group label loses its weight", "fonts", [], lambda d: edit(d, "style.css", "font: 400 0.71875rem / 1 var(--mono);\n letter-spacing: 0.08em;", "font: 0.71875rem / 1 var(--mono);\n letter-spacing: 0.08em;")), + ("no font preload", "fonts", [], lambda d: edit(d, "index.html", f'<link rel="preload" href="fonts/{face}.woff2" as="font" type="font/woff2" crossorigin>', "")), + ("a second font preload", "fonts", [], lambda d: edit(d, "index.html", "<style>", '<link rel="preload" href="fonts/weft.woff2" as="font" type="font/woff2" crossorigin><style>')), + ("no banner preload", "images", [], lambda d: edit(d, "index.html", '<link rel="preload" as="image"', '<link rel="prefetch" as="image"')), + ("the banner preload without high priority", "images", [], lambda d: edit(d, "index.html", 'type="image/avif" fetchpriority="high" imagesizes', 'type="image/avif" imagesizes')), + ("css font face from a font host", "links", [], lambda d: edit(d, "index.html", "url(fonts/weft.woff2)", "url(https://fonts.gstatic.com/s/other/v1/x.woff2)")), + ("css imports Google Fonts", "links", [], lambda d: edit_css(d, ":root {", '@import url("https://fonts.googleapis.com/css2?family=Other");:root {')), + ("css font face from a local file that is not the font", "fonts", [], lambda d: edit(d, "index.html", "url(fonts/weft.woff2)", "url(fonts/mark.woff2)")), + ("css font face for another family", "fonts", [], lambda d: edit(d, "index.html", '@font-face{font-family:"mm Weft"', '@font-face{font-family:"Other"')), + ("css font face for Lato", "fonts", [], lambda d: edit(d, "index.html", '@font-face{font-family:"mm Weft"', '@font-face{font-family:"Lato"')), + ("css font face for EB Garamond", "fonts", [], lambda d: edit(d, "index.html", '@font-face{font-family:"mm Weft"', '@font-face{font-family:"EB Garamond"')), + ("css font face without swap", "fonts", [], lambda d: edit(d, "index.html", "font-display:swap", "font-display:block")), + ("css font face with another weight", "fonts", [], lambda d: edit(d, "index.html", "font-weight:100 900", "font-weight:400")), + ("css font face with another style", "fonts", [], lambda d: edit(d, "index.html", "font-weight:100 900;font-style:normal", "font-weight:100 900;font-style:italic")), + ("css font face drops a face", "fonts", [], lambda d: edit(d, "index.html", re.search(r'@font-face\{font-family:"mm Sans".*?\}', read_index(d)).group(0), "")), # type: ignore[union-attr] + ("a stack names a system font", "fonts", [], lambda d: edit_css(d, '--f-warp: "mm Warp", serif;', '--f-warp: "mm Warp", Georgia, serif;')), + ("a stack starts with another font", "fonts", [], lambda d: edit_css(d, '--f-sans: "mm Sans", system-ui', '--f-sans: Arial, "mm Sans", system-ui')), + ("a rule sets a font family of its own", "fonts", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{font-family:Lato}")), + ("a rule sets a named family in the font shorthand", "fonts", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{font:400 var(--step-0) Lato}")), + ("a rule sets a weight Warp does not have", "fonts", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{font:700 var(--step-0)/1 var(--f-warp)}")), + ("a rule sets bold beyond Sans", "fonts", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{font-weight:900}")), + ("a rule sets italic", "fonts", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{font-style:italic}")), + ("a weight inside the variable range is allowed", None, [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{font:600 var(--step-0)/1 var(--f-weft)}")), + ("the group label loses its weight", "fonts", [], lambda d: edit_css(d, "font: 400 var(--step--1)/1.4 var(--f-weft); letter-spacing: 0.05em;", "font: var(--step--1)/1.4 var(--f-weft); letter-spacing: 0.05em;")), ("a bold tag", "fonts", [], lambda d: edit(d, "index.html", "<body>", "<body><b>x</b>")), ("an italic tag", "fonts", [], lambda d: edit(d, "index.html", "<body>", "<body><em>x</em>")), - *( - [ - ("the italic face is preloaded", "fonts", [], lambda d: edit(d, "index.html", STYLE_LINK, '<link rel="preload" href="fonts/mm-warp-italic.woff2" as="font" type="font/woff2" crossorigin>\n' + STYLE_LINK)), - ("italic through the Weft variable", "fonts", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{font:400 1rem var(--mono);font-style:italic;margin")), - ("italic of the house font is allowed", None, [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{font-style:italic;margin")), - ] - if italic_ok - else [] - ), - ("a second og:image with content first", "head", [], lambda d: edit(d, "index.html", "</head>", '<meta content="https://example.net/x.jpg" property="og:image">\n</head>')), - ("a second description", "head", [], lambda d: edit(d, "index.html", "</head>", '<meta content="Other." name="description">\n</head>')), - ("the main text font is not preloaded", "fonts", [], lambda d: edit(d, "index.html", f'<link rel="preload" href="fonts/{font_stem}.woff2" as="font" type="font/woff2" crossorigin>\n', "")), - ("the font file is not the 0.2.0 file", "fonts", [], lambda d: (d / "fonts" / f"{font_stem}.woff2").write_bytes(b"wOF2" + (d / "fonts" / f"{font_stem}.woff2").read_bytes()[4:] + b"\x00")), - ("the type scale changed", "scale", [], lambda d: edit(d, "style.css", f"--fs:{SIZE / 16:g}rem", "--fs:1.125rem")), - ("the house line size changed", "scale", [], lambda d: edit(d, "style.css", f"--ls:{LINE_SIZE / 16:g}rem", "--ls:1.6875rem")), - ("the word spacing is dropped", "scale", [], lambda d: (d / "style.css").write_text(read_css(d).replace("word-spacing: var(--ws);", ""))), - ("the word spacing of the house changed", "scale", [], lambda d: edit(d, "style.css", "--ws:" + ("0.05em" if THEME["font"] == SANS else "normal"), "--ws:0.3em")), - ("the body line height changed", "scale", [], lambda d: edit(d, "style.css", f"/ {LEADING} ", "/ 1.4 ")), - ("the description link is underlined on hover only", "touch", [], lambda d: edit(d, "style.css", "text-decoration: underline 1px var(--accent);\n text-underline-offset: 0.2em;\n}\n\n@media (max-width", "text-decoration: none;\n text-underline-offset: 0.2em;\n}\n\n@media (max-width")), - ("the description link is short on a narrow screen", "touch", [], lambda d: edit(d, "style.css", "width: fit-content;\n min-height: 44px;", "width: fit-content;\n min-height: 20px;")), - ("a top bar link is short on a narrow screen", "touch", [], lambda d: edit(d, "style.css", ".bar a,\n .bar span,\n footer a {\n min-height: 44px;", ".bar a,\n .bar span,\n footer a {\n min-height: 20px;")), - ("a plate image has no hover state without motion", "hover", [], lambda d: edit(d, "style.css", "outline-color: var(--accent);", "margin: 0;")), - ("font file is not a woff2", "fonts", [], lambda d: (d / "fonts" / "mm-weft.woff2").write_bytes(b"<svg/>")), - ("font file missing", "files", [], lambda d: (d / "fonts" / "mm-weft.woff2").unlink()), + ("a second og:image with content first", "head", [], lambda d: edit(d, "index.html", "<style>", '<meta content="https://example.net/x.jpg" property="og:image"><style>')), + ("a second description", "head", [], lambda d: edit(d, "index.html", "<style>", '<meta content="Other." name="description"><style>')), + ("the font subset is not a woff2", "fonts", [], lambda d: (d / "fonts" / f"{face}.woff2").write_bytes(b"<svg/>")), + ("the font subset is another font", "fonts", [], lambda d: (d / "fonts" / "weft.woff2").write_bytes((d / "fonts" / "sans.woff2").read_bytes())), + ("the font subset is cut too far", "fonts", [], lambda d: (d / "fonts" / "sans.woff2").write_bytes(cut_font(d / "fonts" / "sans.woff2", "ab"))), + ("the source font is not the release file", "fonts", [], break_source), + ("a step of the type scale changed", "scale", [], lambda d: edit_css(d, "--step-0: 1rem;", "--step-0: 1.0625rem;")), + ("a size off the scale", "scale", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{font-size:17px}")), + ("the body line height changed", "scale", [], lambda d: edit_css(d, "var(--step-0)/1.5 var(--f-sans)", "var(--step-0)/1.4 var(--f-sans)")), + ("a spacing token off the scale", "spacing", [], lambda d: edit_css(d, "--sp-3: 12px;", "--sp-3: 10px;")), + ("a raw margin", "spacing", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{margin-top:10px}")), + ("a raw gap in rem", "spacing", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{gap:1rem}")), + ("the description link is underlined on hover only", "touch", [], lambda d: edit_css(d, "a.u, .ds a { color: var(--text); text-decoration: underline 1px var(--accent);", "a.u, .ds a { color: var(--text); text-decoration: none;")), + ("the description link is short", "touch", [], lambda d: edit_css(d, ".ds a { display: inline-block; padding-block: var(--sp-3);", ".ds a { display: inline-block; padding-block: var(--sp-1);")), + ("a section link is short", "touch", [], lambda d: edit_css(d, "height: 44px; position: relative;", "height: 32px; position: relative;")), + ("a bar-1 link is short on a phone", "touch", [], lambda d: edit_css(d, ".b1 li { height: 44px; }", ".b1 li { height: var(--sp-6); }")), + ("a footer link is short on a phone", "touch", [], lambda d: edit_css(d, "@media (max-width: 719px) { .banner img", "@media (max-width: 719px) { footer a { min-height: var(--sp-6); } }\n@media (max-width: 719px) { .banner img")), + ("the footer dot is dropped from the style", "touch", [], lambda d: edit_css(d, 'footer li::before { content: "\\00b7";', 'footer li::after { content: "\\00b7";')), + ("a plate image has no hover state", "hover", [], lambda d: edit_css(d, ".plate:hover .pic img, .plate:hover .tile { filter: brightness(1.02); }", ".plate:hover .pic img, .plate:hover .tile { outline-color: var(--line); }")), + ("font file missing", "files", [], lambda d: (d / "fonts" / "weft.woff2").unlink()), ("font licence missing", "files", [], lambda d: (d / "fonts" / "mm-weft-OFL.txt").unlink()), ("extra font file", "files", [], lambda d: (d / "fonts" / "other.woff2").write_bytes(b"wOF2")), + ("the full font comes back", "files", [], lambda d: (d / "fonts" / "mm-weft.woff2").write_bytes((GEN / "fonts" / "mm-weft.woff2").read_bytes())), ("Lato comes back", "files", [], lambda d: (d / "fonts" / "lato-400.woff2").write_bytes(b"wOF2")), ("EB Garamond comes back", "files", [], lambda d: (d / "fonts" / "eb-garamond-OFL.txt").write_text("OFL")), ("private repo in a font licence", "private", [], lambda d: edit(d, "fonts/mm-weft-OFL.txt", "SIL OPEN FONT", "github.com/machine-made/zzprivate SIL OPEN FONT")), @@ -1460,163 +2035,186 @@ def run(d: Path) -> None: ("money amount in a font licence", "forbidden", [], lambda d: edit(d, "fonts/mm-weft-OFL.txt", "SIL OPEN FONT", "$5 SIL OPEN FONT")), *[ (f"{tag} tag", "no-js", [], lambda d, tag=tag: edit(d, "index.html", "<body>", f'<body><{tag} src="https://example.net/x"></{tag}>')) - for tag in ("audio", "video", "source", "track", "iframe", "object", "embed") + for tag in ("audio", "video", "iframe", "object", "embed") ], + ("source outside a picture", "no-js", [], lambda d: edit(d, "index.html", "<body>", '<body><source type="image/avif" srcset="og.jpg">')), + ("source of another type", "no-js", [], lambda d: edit(d, "index.html", '<source type="image/avif"', '<source type="video/mp4"')), + ("track tag", "no-js", [], lambda d: edit(d, "index.html", "<body>", '<body><track src="https://example.net/x">')), ("script tag", "no-js", [], lambda d: edit(d, "index.html", "</body>", "<script>1</script></body>")), - ("banner without alt", "a11y", [], lambda d: edit(d, "index.html", 'height="469" alt="', 'height="469" alt=" " data-x="')), - ("plate image without alt attribute", "a11y", [], lambda d: edit(d, "index.html", f'<img src="img/{first}.jpg" width="704" height="235" loading="lazy" alt="">', f'<img src="img/{first}.jpg" width="704" height="235" loading="lazy">')), + ("script tag on the 404 page", "no-js", [], lambda d: edit(d, "404.html", "</body>", "<script>1</script></body>")), + ("banner without alt", "a11y", [], lambda d: edit(d, "index.html", f'height="469" alt="{site_title(name)}"', 'height="469" alt=" "')), + ("plate image without alt attribute", "a11y", [], lambda d: edit(d, "index.html", first_img, first_img.replace(' alt=""', ""))), ("plate link without an accessible name", "a11y", [], plate_edit(first, lambda li: li.replace(f' aria-label="{first}"', "", 1))), ("plate link named by something else", "a11y", [], plate_edit(first, lambda li: li.replace(f'aria-label="{first}"', 'aria-label="zz"', 1))), - ("the repository name comes back under the plate", "projects", [], plate_edit(first, lambda li: li.replace('<span class="ds">', f'<span class="nm">{first}</span><span class="ds">', 1))), - ("the repository name comes back inside the plate line", "projects", [], plate_edit(first, lambda li: li.replace('<span class="ds">', f'<span class="ds">{first} ', 1))), - ("the plate has no image link", "projects", [], plate_edit(first, lambda li: re.sub(r'<a class="pic"[^>]*>(<img[^>]*>)</a>', r"\1", li, count=1))), - ("plate image has alt text that repeats the name", "projects", [], lambda d: edit(d, "index.html", f'<img src="img/{first}.jpg" width="704" height="235" loading="lazy" alt="">', f'<img src="img/{first}.jpg" width="704" height="235" loading="lazy" alt="{first}">')), - ("plate image without lazy loading", "projects", [], lambda d: edit(d, "index.html", f'<img src="img/{first}.jpg" width="704" height="235" loading="lazy" alt="">', f'<img src="img/{first}.jpg" width="704" height="235" alt="">')), - ("plate image without size", "responsive", [], lambda d: edit(d, "index.html", f'<img src="img/{first}.jpg" width="704" height="235"', f'<img src="img/{first}.jpg"')), - ("plate image missing", "files", [], lambda d: (d / "img" / f"{first}.jpg").unlink()), + ("house link named by something else", "a11y", [], lambda d: edit(d, "index.html", f'class="pic" href="{TYPE_URL}" aria-label="type"', f'class="pic" href="{TYPE_URL}" aria-label="fonts"')), + ("the repository name comes back under the plate", "projects", [], plate_edit(first, lambda li: li.replace('<p class="ds">', f'<span class="nm">{first}</span><p class="ds">', 1))), + ("the repository name comes back inside the plate line", "projects", [], plate_edit(first, lambda li: li.replace('<p class="ds">', f'<p class="ds">{first} ', 1))), + ("the plate has no image link", "projects", [], plate_edit(first, lambda li: re.sub(r'<a class="pic"[^>]*>(<picture>.*?</picture>)</a>', r"\1", li, count=1))), + ("plate image has alt text that repeats the name", "a11y", [], lambda d: edit(d, "index.html", first_img, first_img.replace('alt=""', f'alt="{first}"'))), + ("plate image without lazy loading", "projects", [], lambda d: edit(d, "index.html", first_img, first_img.replace(' loading="lazy"', ""))), + ("plate image without size", "responsive", [], lambda d: edit(d, "index.html", first_img, first_img.replace(' width="704" height="235"', ""))), + ("plate without AVIF", "projects", [], plate_edit(first, lambda li: re.sub(r"<source[^>]*>", "", li, count=1))), + ("the plate facts are not the live facts", "projects", [], plate_edit(first, lambda li: re.sub(r'<time datetime="[^"]*">', '<time datetime="2001-01-01">', li, count=1))), + ("the plate facts lose the language", "projects", [], plate_edit(first, lambda li: li.replace('<p class="facts"><span><span>', '<p class="facts"><span><span hidden>', 1))), + ("plate image missing", "files", [], lambda d: (d / "img" / f"{first}-704.avif").unlink()), ("extra image", "files", [], lambda d: (d / "img" / "extra.jpg").write_bytes(b"\xff\xd8\xff")), - ("banner is not a JPEG", "images", [], lambda d: (d / "img" / "banner.jpg").write_bytes(b"<svg/>")), - ("plate has the wrong size", "images", [], lambda d: (d / "img" / f"{first}.jpg").write_bytes((d / "img" / "banner.jpg").read_bytes())), - ("banner is cut short", "images", [], lambda d: (d / "img" / "banner.jpg").write_bytes((d / "img" / "banner.jpg").read_bytes()[:-2])), - ("banner has the wrong size", "images", [], lambda d: (d / "img" / "banner.jpg").write_bytes((d / "img" / f"{first}.jpg").read_bytes())), - ("image is too large", "images", [], lambda d: (d / "img" / f"{first}.jpg").write_bytes((d / "img" / f"{first}.jpg").read_bytes() + b"\x00" * 400_000)), + ("og image missing", "files", [], lambda d: (d / "og.jpg").unlink()), + ("banner is not a JPEG", "images", [], lambda d: (d / "img" / f"banner-{house_key(SELF)}-1408.jpg").write_bytes(b"<svg/>")), + ("banner AVIF is not an AVIF", "images", [], lambda d: (d / "img" / f"banner-{house_key(SELF)}-1408.avif").write_bytes((d / "og.jpg").read_bytes())), + ("plate has the wrong size", "images", [], lambda d: (d / "img" / f"{first}-704.jpg").write_bytes((d / "img" / f"{first}-352.jpg").read_bytes())), + ("plate AVIF has the wrong size", "images", [], lambda d: (d / "img" / f"{first}-704.avif").write_bytes((d / "img" / f"{first}-352.avif").read_bytes())), + ("banner is cut short", "images", [], lambda d: (d / "img" / f"banner-{house_key(SELF)}-1408.jpg").write_bytes((d / "img" / f"banner-{house_key(SELF)}-1408.jpg").read_bytes()[:-2])), + ("og image has the wrong size", "images", [], lambda d: (d / "og.jpg").write_bytes((d / "img" / f"banner-{house_key(SELF)}-1408.jpg").read_bytes())), + ("touch icon has the wrong size", "images", [], lambda d: (d / "img" / "touch.png").write_bytes(tiny_png())), + ("image is too large", "images", [], lambda d: (d / "img" / f"{first}-704.jpg").write_bytes((d / "img" / f"{first}-704.jpg").read_bytes() + b"\x00" * 400_000)), ("money amount", "forbidden", [], lambda d: edit(d, "llms.txt", "## Sites", "$5\n\n## Sites")), + ("a banned word", "forbidden", [], lambda d: edit(d, "llms.txt", "## Sites", "the brief\n\n## Sites")), + ("a banned word in a character reference", "forbidden", [], lambda d: edit(d, "index.html", "<body>", "<body>card")), + ("homebrew-tap is listed", "forbidden", [], lambda d: edit(d, "llms.txt", "## Sites", "homebrew-tap\n\n## Sites")), ("second page", "files", [], lambda d: (d / "second.html").write_text("<!doctype html>")), - ("mark file missing", "files", [], lambda d: (d / "mark.svg").unlink()), + ("mark file missing", "files" if SELF == "machine-made" else None, [], lambda d: (d / "mark.svg").unlink() if SELF == "machine-made" else None), + ("old style file comes back", "files", [], lambda d: (d / "style.css").write_text("a{}")), ("old hero comes back", "files", [], lambda d: (d / "heroes").mkdir() or (d / "heroes" / "x.svg").write_text("<svg/>")), ("non-ASCII in llms.txt", "voice", [], lambda d: edit(d, "llms.txt", "## Sites", "cafรฉ\n\n## Sites")), ("non-ASCII in the page", "voice", [], lambda d: edit(d, "index.html", "<body>", "<body>cafรฉ")), - ("a dot written in the footer", "voice", [], lambda d: edit(d, "index.html", "</p>\n</footer>", "ยท</p>\n</footer>")), - ("a dot written in the footer as text", "content", [], lambda d: edit(d, "index.html", "</a> <a", "</a> · <a")), - ("the top bar loses a site", "content", [], lambda d: edit(d, "index.html", f'<a href="{nav_other}">{other_name}</a>\n', "")), - ("the top bar marks another site", "content", [], lambda d: edit_all(d, "index.html", (f'<span aria-current="page">{SELF}</span>', f'<a href="{self_url}">{SELF}</a>'), (f'<a href="{nav_other}">{other_name}</a>', f'<span aria-current="page">{other_name}</span>'))), + ("non-ASCII in the 404 page", "voice", [], lambda d: edit(d, "404.html", "–", "โ€“")), + ("a dot written in the footer", "content", [], lambda d: edit(d, "index.html", "</ul></div></footer>", "<li>·</li></ul></div></footer>")), + ("bar 1 loses a site", "content", [], lambda d: edit(d, "index.html", f'<li><a href="{nav_other}">{other_name}</a></li>', "")), + ("bar 1 marks another site", "content", [], lambda d: edit_all(d, "index.html", (f'<span aria-current="page">{SELF}</span>', f'<a href="{self_url}">{SELF}</a>'), (f'<li><a href="{nav_other}">{other_name}</a>', f'<li><span aria-current="page">{other_name}</span>'))), ("the current site links to itself", "content", [], lambda d: edit(d, "index.html", f'<span aria-current="page">{SELF}</span>', f'<a href="{self_url}" aria-current="page">{SELF}</a>')), ("the current site is not marked", "content", [], lambda d: edit(d, "index.html", f'<span aria-current="page">{SELF}</span>', f"<span>{SELF}</span>")), - ("two entries are marked", "a11y", [], lambda d: edit(d, "index.html", f'<a href="{nav_other}">{other_name}</a>', f'<a href="{nav_other}" aria-current="page">{other_name}</a>')), - ("a site linked twice", "links", [], lambda d: edit(d, "index.html", "</footer>", f'<a href="{nav_other}">x</a></footer>')), - ("the footer loses the type link", "content", [], lambda d: edit(d, "index.html", f' <a href="{TYPE_URL}">type</a></p>', "</p>")), - ("the footer is plain text again", "content", [], lambda d: edit(d, "index.html", footer_html(d), '<footer class="wrap">\n<p>' + " ".join(n for n, _ in SITES) + "</p>\n</footer>")), - ("the footer lists type first", "content", [], lambda d: edit_all(d, "index.html", (f' <a href="{TYPE_URL}">type</a></p>', "</p>"), ("<footer class=\"wrap\">\n<p>", f'<footer class="wrap">\n<p><a href="{TYPE_URL}">type</a> '))), - ("the footer type link goes elsewhere", "content", [], lambda d: edit(d, "index.html", f' <a href="{TYPE_URL}">type</a></p>', ' <a href="https://machine-made.github.io/fonts/">type</a></p>')), - ("a footer link without its site", "links", [], lambda d: edit(d, "index.html", "</footer>", f'<a href="{self_url}">x</a></footer>')), - ("the type link is missing", "content", [], lambda d: edit(d, "index.html", f'<a href="{TYPE_URL}">type</a>\n', "")), - ("the type link goes elsewhere", "content", [], lambda d: edit(d, "index.html", f'<a href="{TYPE_URL}">type</a>', '<a href="https://machine-made.github.io/fonts/">type</a>')), - ("the type link moves first", "content", [], lambda d: edit_all(d, "index.html", (f'<a href="{TYPE_URL}">type</a>\n', ""), ('<nav class="bar" aria-label="Sites">\n', f'<nav class="bar" aria-label="Sites">\n<a href="{TYPE_URL}">type</a>\n'))), - ("the type link reads fonts", "content", [], lambda d: edit(d, "index.html", f'<a href="{TYPE_URL}">type</a>', f'<a href="{TYPE_URL}">fonts</a>')), + ("two entries are marked", "a11y", [], lambda d: edit(d, "index.html", f'<li><a href="{nav_other}">{other_name}</a>', f'<li><a href="{nav_other}" aria-current="page">{other_name}</a>')), + ("a site linked twice", "links", [], lambda d: edit(d, "index.html", "</ul></div></footer>", f'<li><a href="{nav_other}">x</a></li></ul></div></footer>')), + ("the footer loses the type link", "content", [], lambda d: edit(d, "index.html", f'<li><a href="{TYPE_URL}">type</a></li></ul></div></footer>', "</ul></div></footer>")), + ("the footer is plain text again", "content", [], lambda d: edit(d, "index.html", footer_of(d), '<footer class="wrap"><p>' + " ".join(n for n, _ in SITES) + "</p></footer>")), + ("the footer type link goes elsewhere", "content", [], lambda d: edit(d, "index.html", f'<li><a href="{TYPE_URL}">type</a></li></ul></div></footer>', '<li><a href="https://machine-made.github.io/fonts/">type</a></li></ul></div></footer>')), + ("a footer link without its site", "links", [], lambda d: edit(d, "index.html", "</ul></div></footer>", f'<li><a href="{self_url}">x</a></li></ul></div></footer>')), + ("the type link is missing", "content", [], lambda d: edit(d, "index.html", f'<li><a href="{TYPE_URL}">type</a></li></ul></nav>', "</ul></nav>")), + ("the type link goes elsewhere", "content", [], lambda d: edit(d, "index.html", f'<li><a href="{TYPE_URL}">type</a></li></ul></nav>', '<li><a href="https://machine-made.github.io/fonts/">type</a></li></ul></nav>')), + ("the type link moves first", "content", [], lambda d: edit_all(d, "index.html", (f'<li><a href="{TYPE_URL}">type</a></li></ul></nav>', "</ul></nav>"), ('<ul class="wrap">', f'<ul class="wrap"><li><a href="{TYPE_URL}">type</a></li>'))), + ("the type link reads fonts", "content", [], lambda d: edit(d, "index.html", f'<a href="{TYPE_URL}">type</a></li></ul></nav>', f'<a href="{TYPE_URL}">fonts</a></li></ul></nav>')), + ("bar 2 loses a section", "content", [], lambda d: edit(d, "index.html", f'<a href="#g-{slug(GROUPS[0][0])}">', '<a href="#main">')), + ("bar 2 loses GitHub", "content", [], lambda d: edit(d, "index.html", f'<a href="https://github.com/{OWNER}">GitHub</a>', "")), + ("bar 2 logo is not named", "content", [], lambda d: edit(d, "index.html", f'aria-label="{site_title(name)} home"', 'aria-label="home"')), + ("a section link points to no group", "links", [], lambda d: edit(d, "index.html", f'<a href="#g-{slug(GROUPS[0][0])}">', '<a href="#g-zz">')), + ("a heading level is skipped", "semantic", [], lambda d: edit_all(d, "index.html", ('<h2 class="lbl" id="g-houses">', '<h4 class="lbl" id="g-houses">'), ("<span>The houses</span></h2>", "<span>The houses</span></h4>"))), + ("a second h1", "semantic", [], lambda d: edit(d, "index.html", "</main>", "<h1>x</h1></main>")), # The head: title, description, favicon and the social preview. ("the title changed", "head", [], lambda d: edit(d, "index.html", "<title>", "<title>Other ")), ("the description meta changed", "head", [], lambda d: edit(d, "index.html", '<meta name="description" content="', '<meta name="description" content="Other. ')), - ("the favicon is missing", "head", [], lambda d: edit(d, "index.html", '<link rel="icon" href="mark.svg" type="image/svg+xml">\n', "")), - ("og:image is missing", "head", [], lambda d: edit(d, "index.html", f'<meta property="og:image" content="{self_url}img/banner.jpg">\n', "")), - ("og:image is not the org banner", "head", [], lambda d: edit(d, "index.html", f'content="{self_url}img/banner.jpg"', f'content="{self_url}img/{first}.jpg"')), - ("og:image is a relative path", "head", [], lambda d: edit(d, "index.html", f'content="{self_url}img/banner.jpg"', 'content="img/banner.jpg"')), + ("the favicon is missing", "head", [], lambda d: edit(d, "index.html", re.search(r'<link rel="icon"[^>]*>', read_index(d)).group(0), "")), # type: ignore[union-attr] + ("the touch icon is missing", "head", [], lambda d: edit(d, "index.html", '<link rel="apple-touch-icon" href="img/touch.png">', "")), + ("og:image is missing", "head", [], lambda d: edit(d, "index.html", f'<meta property="og:image" content="{self_url}og.jpg">', "")), + ("og:image is the banner", "head", [], lambda d: edit(d, "index.html", f'content="{self_url}og.jpg"', f'content="{self_url}img/banner-{house_key(SELF)}-1408.jpg"')), + ("og:image is a relative path", "head", [], lambda d: edit(d, "index.html", f'content="{self_url}og.jpg"', 'content="og.jpg"')), + ("og:image has the old size", "head", [], lambda d: edit(d, "index.html", '<meta property="og:image:height" content="630">', '<meta property="og:image:height" content="469">')), ("og:title changed", "head", [], lambda d: edit(d, "index.html", '<meta property="og:title" content="', '<meta property="og:title" content="Other ')), ("og:url changed", "head", [], lambda d: edit(d, "index.html", f'<meta property="og:url" content="{self_url}"', '<meta property="og:url" content="https://example.net/"')), - ("twitter:card is missing", "head", [], lambda d: edit(d, "index.html", '<meta name="twitter:card" content="summary_large_image">\n', "")), - ("the banner is not in the h1", "content", [], lambda d: edit(d, "index.html", "<h1><img", "<h1></h1><img")), - ("banner shows another image", "content", [], lambda d: edit(d, "index.html", 'src="img/banner.jpg"', f'src="img/{first}.jpg"')), - ("org line changed", "content", [], lambda d: edit(d, "index.html", f'<p class="line">{html.escape(LINE)}', '<p class="line">Another line.')), - ("name paragraph changed", "content", [], lambda d: edit(d, "index.html", f'<p class="blurb">{html.escape(BLURB)}', '<p class="blurb">Another paragraph.')), - ("line and paragraph swap", "content", [], lambda d: edit_all(d, "index.html", ('<p class="line">', '<p class="tmp">'), ('<p class="blurb">', '<p class="line">'), ('<p class="tmp">', '<p class="blurb">'))), - ("org line missing in llms.txt", "llms", [], lambda d: edit(d, "llms.txt", f"> {LINE}", "> ")), - ("name paragraph missing in llms.txt", "llms", [], lambda d: edit(d, "llms.txt", f"{BLURB}\n\n", "")), - ("old footer text", "content", [], lambda d: edit(d, "index.html", "<footer class=\"wrap\">\n<p>", "<footer class=\"wrap\">\n<p>An open-source workshop. ")), - ("footer line changed", "content", [], lambda d: edit(d, "index.html", "</a> <a", "</a> x <a")), - ("the footer dot is dropped from the style", "touch", [], lambda d: edit(d, "style.css", "footer a:not(:last-child)::after {", "footer a:last-child::after {")), - ("page order changed", "content", [], move_footer_up), + ("twitter:card is missing", "head", [], lambda d: edit(d, "index.html", '<meta name="twitter:card" content="summary_large_image">', "")), + ("the banner is not in the h1", "content", [], lambda d: edit_all(d, "index.html", ('<h1 class="banner"><picture>', '<h1 class="banner"></h1><picture>'), ("</picture></h1>", "</picture>"))), + ("banner shows another image", "content", [], lambda d: edit(d, "index.html", f'<img src="img/banner-{house_key(SELF)}-1408.jpg"', f'<img src="img/{first}-704.jpg"')), + ("banner loads lazily", "content", [], lambda d: edit(d, "index.html", 'decoding="async" fetchpriority="high"></picture></h1>', 'loading="lazy" decoding="async"></picture></h1>')), + ("house line changed", "content", [], lambda d: edit(d, "index.html", f'<p class="line {face}">', f'<p class="line {face}">Another line. ')), + ("house line in another face", "content", [], lambda d: edit(d, "index.html", f'<p class="line {face}">', '<p class="line sans">')), + ("the name paragraph comes back", "content", [], lambda d: edit(d, "index.html", f'<p class="line {face}">', '<p class="blurb">x</p><p class="line zz">')), + ("house line missing in llms.txt", "llms", [], lambda d: edit(d, "llms.txt", f"> {LINE}", "> ")), + ("Latest is not the newest", "latest", [], lambda d: edit(d, "index.html", '<ol class="latest', '<ol class="latest"><li><a href="#main">zz</a></li></ol><ol class="zz')), + ("Latest repeats a repository", "latest", [], lambda d: edit(d, "index.html", re.search(r'(<ol class="latest n\d">)(<li>.*?</li>)', read_index(d)).group(0), re.sub(r'(<ol class="latest n\d">)(<li>.*?</li>)', r"\1\2\2", re.search(r'(<ol class="latest n\d">)(<li>.*?</li>)', read_index(d)).group(0)))), # type: ignore[union-attr] + ("Latest has an old date", "latest", [], lambda d: edit(d, "index.html", re.search(r'<ol class="latest n\d"><li>.*?<time datetime="[^"]*">', read_index(d)).group(0), re.sub(r'datetime="[^"]*"', 'datetime="2001-01-01"', re.search(r'<ol class="latest n\d"><li>.*?<time datetime="[^"]*">', read_index(d)).group(0)))), # type: ignore[union-attr] + ("the houses row loses the type site", "houses", [], lambda d: edit(d, "index.html", re.search(r'<li class="plate"><a class="pic" href="' + re.escape(TYPE_URL) + r'".*?</li>', read_index(d)).group(0), "")), # type: ignore[union-attr] + ("the houses row shows this house", "houses", [], lambda d: edit(d, "index.html", f'<li class="plate"><a class="pic" href="{nav_other}"', f'<li class="plate"><a class="pic" href="{self_url}"')), + ("the houses row has a stale release", "houses", [], lambda d: edit(d, "index.html", re.search(r'aria-labelledby="g-houses".*?<time datetime="[^"]*">', read_index(d)).group(0), re.sub(r'datetime="[^"]*">$', 'datetime="2001-01-01">', re.search(r'aria-labelledby="g-houses".*?<time datetime="[^"]*">', read_index(d)).group(0)))), # type: ignore[union-attr] ("sites missing in llms.txt", "llms", [], lambda d: edit(d, "llms.txt", "## Sites", "## Elsewhere")), - ("a group heading is renamed", "projects", [], lambda d: edit(d, "index.html", f">{GROUPS[0][0]}</h2>", ">Tools</h2>")), - ("a group has no label class", "projects", [], lambda d: edit(d, "index.html", '<h2 class="lbl"', "<h2")), - ("a project is dropped", "projects", [], lambda d: edit(d, "index.html", next(m for m in re.findall(r'<li class="plate">.*?</li>\n', read_index(d), re.S) if f"/{first}" in m), "")), + ("page order changed", "content", [], move_footer_up), + ("a group heading is renamed", "projects", [], lambda d: edit(d, "index.html", f"<span>{GROUPS[0][0]}</span></h2>", "<span>Tools</span></h2>")), + ("a group has no label class", "projects", [], lambda d: edit(d, "index.html", f'<h2 class="lbl" id="g-{slug(GROUPS[0][0])}"', f'<h2 id="g-{slug(GROUPS[0][0])}"')), + ("a project is dropped", "projects", [], plate_edit(first, lambda li: "")), *( [("two projects swap places", "projects", [], lambda d: edit_all(d, "index.html", (f"/{first}\"", "/zz-swap\""), (f"/{second}\"", f"/{first}\""), ("/zz-swap\"", f"/{second}\"")))] if second != first else [] ), - ("a project is added", "projects", [], lambda d: edit(d, "index.html", "</ul>", f'<li class="plate"><a class="pic" href="https://github.com/{OWNER}/{first}" aria-label="{first}">x</a></li></ul>')), + ("a project is added", "projects", [], lambda d: edit(d, "index.html", '</ul></section><section class="row" aria-labelledby="g-houses">', f'<li class="plate"><a class="pic" href="https://github.com/{OWNER}/{first}" aria-label="{first}">x</a></li></ul></section><section class="row" aria-labelledby="g-houses">')), ("a group heading is renamed in llms.txt", "llms", [], lambda d: edit(d, "llms.txt", f"## {GROUPS[0][0]}", "## Tools")), - ("unexpected site link", "links", [], plate_edit(second, lambda li: li.replace("</span></li>", ' <a class="nm" href="https://machine-made.github.io/zz/">site</a></span></li>'))), - ("unexpected site link on another host", "projects", [], plate_edit(second, lambda li: li.replace("</span></li>", ' <a class="nm" href="https://example.net/">site</a></span></li>'))), - ("plate name is a heading", "projects", [], plate_edit(second, lambda li: li.replace("</span></li>", f'</span><h3 class="nm">{second}</h3></li>'))), - ("moved repository listed again", "projects", [], lambda d: edit(d, "index.html", "</ul>", f'<li><a href="https://github.com/{OWNER}/chaos-atlas">chaos-atlas</a><p>x</p></li></ul>')), - ("accent in a style attribute", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path style="fill:#00f" class="k"')), - ("accent in stop-color", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path stop-color="#00ff00" class="k"')), - ("named colour in a stroke", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path stroke="red" class="k"')), - ("named colour in an svg rule", "accent", [], lambda d: edit(d, "mark.svg", ".k{fill:", ".k{stroke:red;fill:")), - ("gradient in the mark", "colour", [], lambda d: edit(d, "mark.svg", "<rect", '<defs><linearGradient id="z"/></defs><rect')), - ("private name in a class value", "private", ["zzprivate"], lambda d: edit(d, "index.html", '<main id="main"', '<main id="main" class="zzprivate"')), + ("unexpected site link", "links", [], plate_edit(second, lambda li: li.replace("</p><p class=\"facts\">", ' <a href="https://machine-made.github.io/zz/">site</a></p><p class="facts">', 1))), + ("unexpected site link on another host", "links", [], plate_edit(second, lambda li: li.replace("</p><p class=\"facts\">", ' <a href="https://example.net/">site</a></p><p class="facts">', 1))), + ("plate name is a heading", "projects", [], plate_edit(second, lambda li: li.replace("</li>", f'<h3 class="nm">{second}</h3></li>'))), + ("moved repository listed again", "projects", [], lambda d: edit(d, "index.html", "</ol>", f'</ol><a href="https://github.com/{OWNER}/chaos-atlas">chaos-atlas</a>')), + ("private name in a class value", "private", ["zzprivate"], lambda d: edit(d, "index.html", '<main id="main" class="wrap', '<main id="main" class="zzprivate wrap')), ("private name in an id value", "private", ["zzprivate"], lambda d: edit(d, "index.html", 'id="main"', 'id="zzprivate"')), ("unknown attribute", "attrs", [], lambda d: edit(d, "index.html", '<main id="main"', '<main data-x="1" id="main"')), - ("css imports a remote file", "links", [], lambda d: edit(d, "style.css", ":root{", '@import url("https://example.net/x.css");:root{')), - ("css string import", "links", [], lambda d: edit(d, "style.css", ":root{", '@import "https://example.net/x.css";:root{')), - ("css url on a look-alike font host", "links", [], lambda d: edit(d, "style.css", ":root{", "a{background:url(https://fonts.gstatic.com.example.net/f.woff2)}:root{")), - ("css url leaves docs/", "links", [], lambda d: edit(d, "style.css", ":root{", "a{background:url(../README.md)}:root{")), - ("css data url", "links", [], lambda d: edit(d, "style.css", ":root{", "a{background:url(data:image/png;base64,AAAA)}:root{")), - ("script in the mark svg", "no-js", [], lambda d: edit(d, "mark.svg", "<title>", "<script>1</script><title>")), - ("event handler in the mark svg", "no-js", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path onclick="x()" class="k"')), - ("external href in the mark svg", "links", [], lambda d: edit(d, "mark.svg", "<rect", '<use href="https://example.net/x.svg#a"/><rect')), - ("remote url in an svg rule", "links", [], lambda d: edit(d, "mark.svg", "<style>", "<style>.z{fill:url(https://example.net/x.svg#a)}")), - ("css image-set", "links", [], lambda d: edit(d, "style.css", ":root{", 'a{background:image-set("mark.svg" 1x)}:root{')), - ("css image()", "links", [], lambda d: edit(d, "style.css", ":root{", 'a{background:image("mark.svg")}:root{')), - ("css prefixed cross-fade", "links", [], lambda d: edit(d, "style.css", ":root{", "a{background:-webkit-cross-fade(url(mark.svg),url(mark.svg),50%)}:root{")), - ("css escaped function name", "css", [], lambda d: edit(d, "style.css", ":root{", "a{background:\\69mage-set(mark.svg 1x)}:root{")), - ("named colour in style.css", "accent", [], lambda d: edit(d, "style.css", "box-sizing", "color:red;box-sizing")), - ("upper-case named colour", "accent", [], lambda d: edit(d, "style.css", "box-sizing", "color:BLUE;box-sizing")), - ("named colour in a border", "accent", [], lambda d: edit(d, "style.css", "box-sizing", "border:1px solid tomato;box-sizing")), - ("named colour in a var fallback", "accent", [], lambda d: edit(d, "style.css", "box-sizing", "color:var(--fg,navy);box-sizing")), - ("system colour", "accent", [], lambda d: edit(d, "style.css", "box-sizing", "color:LinkText;box-sizing")), - ("escaped colour name", "css", [], lambda d: edit(d, "style.css", "box-sizing", "color:\\72 ed;box-sizing")), - ("colour mix function", "colour", [], lambda d: edit(d, "style.css", "box-sizing", "color:color-mix(in srgb,#fff,#000);box-sizing")), - ("black, white and transparent are allowed", None, [], lambda d: edit(d, "style.css", "box-sizing", "color:black;background:WHITE;border-color:transparent;outline-color:currentColor;box-sizing")), - ("a class with a colour name is not a colour", None, [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.red{margin:0}a:not(.tan){margin:0}.zz{margin:0")), - ("named colour in a page style block", "accent", [], lambda d: edit(d, "index.html", "<body>", "<body><style>a{color:red}</style>")), - ("hex accent in a page style block", "accent", [], lambda d: edit(d, "index.html", "<body>", "<body><style>a{color:#00f}</style>")), - ("accent as the fallback of a fragment paint", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) #0000ff" class="k"')), - ("named fallback of a fragment paint", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) red" class="k"')), - ("function fallback of a fragment paint", "colour", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) rgb(0,0,255)" class="k"')), - ("keyword fallback of a fragment paint", None, [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) currentColor" class="k"')), - ("text colour from a low-contrast grey", "contrast", [], lambda d: edit(d, "style.css", "box-sizing", f"color:{THEME['ground'].replace('0', '1', 1)};box-sizing")), - ("text colour from the edge token", "contrast", [], lambda d: edit(d, "style.css", "box-sizing", "color:var(--edge);box-sizing")), - ("text on a low-contrast background token", "contrast", [], lambda d: edit(d, "style.css", "box-sizing", "color:var(--fg);background:var(--muted);box-sizing")), - ("background shorthand with more than a token", "contrast", [], lambda d: edit(d, "style.css", "box-sizing", "background:var(--bg) url(mark.svg);box-sizing")), - ("text colour from an unknown token", "contrast", [], lambda d: edit(d, "style.css", "box-sizing", "color:var(--nope);box-sizing")), - ("a pair of palette tokens is allowed", None, [], lambda d: edit(d, "style.css", "box-sizing", "color:var(--muted);background:var(--bg) !important;box-sizing")), - ("upper-case colour function", "colour", [], lambda d: edit(d, "style.css", "box-sizing", "color:RGB(0,0,255);box-sizing")), - ("upper-case gradient", "colour", [], lambda d: edit(d, "style.css", "box-sizing", "background:LINEAR-GRADIENT(red,blue);box-sizing")), - ("a second gradient", "colour", [], lambda d: edit(d, "style.css", "box-sizing", "background:linear-gradient(#000,#000);box-sizing")), - ("the banner mask changed", "colour", [], lambda d: edit(d, "style.css", "#000 10%", "#000 20%")), - ("the banner mask missing", "colour", [], lambda d: edit(d, "style.css", MASK, "")), + ("css imports a remote file", "links", [], lambda d: edit_css(d, ":root {", '@import url("https://example.net/x.css");:root {')), + ("css string import", "links", [], lambda d: edit_css(d, ":root {", '@import "https://example.net/x.css";:root {')), + ("css url on a look-alike font host", "links", [], lambda d: edit_css(d, ":root {", "a{background:url(https://fonts.gstatic.com.example.net/f.woff2)}:root {")), + ("css url leaves docs/", "links", [], lambda d: edit_css(d, ":root {", "a{background:url(../README.md)}:root {")), + ("css data url", "links", [], lambda d: edit_css(d, ":root {", "a{background:url(data:image/png;base64,AAAA)}:root {")), + ("css image-set", "links", [], lambda d: edit_css(d, ":root {", 'a{background:image-set("og.jpg" 1x)}:root {')), + ("css image()", "links", [], lambda d: edit_css(d, ":root {", 'a{background:image("og.jpg")}:root {')), + ("css prefixed cross-fade", "links", [], lambda d: edit_css(d, ":root {", "a{background:-webkit-cross-fade(url(og.jpg),url(og.jpg),50%)}:root {")), + ("css escaped function name", "css", [], lambda d: edit_css(d, ":root {", "a{background:\\69mage-set(og.jpg 1x)}:root {")), + ("a second escape in a content string", "css", [], lambda d: edit_css(d, "box-sizing: border-box; }", 'box-sizing: border-box; }.zz::before{content:"\\72 ed"}')), + ("named colour in the style", "accent", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:red;box-sizing: border-box;")), + ("upper-case named colour", "accent", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:BLUE;box-sizing: border-box;")), + ("named colour in a border", "accent", [], lambda d: edit_css(d, "box-sizing: border-box;", "border:1px solid tomato;box-sizing: border-box;")), + ("named colour in a var fallback", "accent", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:var(--text,navy);box-sizing: border-box;")), + ("system colour", "accent", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:LinkText;box-sizing: border-box;")), + ("escaped colour name", "css", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:\\72 ed;box-sizing: border-box;")), + ("colour mix function", "colour", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:color-mix(in srgb,#fff,#000);box-sizing: border-box;")), + ("black, white and transparent are allowed", None, [], lambda d: edit_css(d, "box-sizing: border-box;", "color:black;background:WHITE;border-color:transparent;outline-color:currentColor;box-sizing: border-box;")), + ("a class with a colour name is not a colour", None, [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.red{margin:0}a:not(.tan){margin:0}.zz{margin:0}")), + ("named colour in the colour block", "accent", [], lambda d: edit(d, "index.html", "<style>@font-face", "<style>a{color:red}@font-face")), + ("a third style block", "css", [], lambda d: edit(d, "index.html", "</head>", "<style>a{color:#00f}</style></head>")), + ("text colour from a low-contrast grey", "contrast", [], lambda d: edit_css(d, "box-sizing: border-box; }", f"box-sizing: border-box; }}.zz{{color:{THEME['ground'].replace('0', '1', 1)}}}")), + ("text colour from the line token", "contrast", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{color:var(--line)}")), + ("text on a low-contrast background token", "contrast", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{color:var(--text);background:var(--muted)}")), + ("background shorthand with more than a token", "contrast", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{background:var(--ground) url(og.jpg)}")), + ("text colour from an unknown token", "contrast", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{color:var(--nope)}")), + ("a pair of palette tokens is allowed", None, [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{color:var(--muted);background:var(--surface) !important}")), + ("the muted colour fails its floor", "contrast", [], lambda d: (edit(d, "index.html", f"--muted:{THEME['muted']}", "--muted:#4a4a4a"), set_theme("muted", "#4a4a4a"))), + ("upper-case colour function", "colour", [], lambda d: edit_css(d, "box-sizing: border-box;", "color:RGB(0,0,255);box-sizing: border-box;")), + ("upper-case gradient", "colour", [], lambda d: edit_css(d, "box-sizing: border-box;", "background:LINEAR-GRADIENT(red,blue);box-sizing: border-box;")), + ("a second gradient", "colour", [], lambda d: edit_css(d, "box-sizing: border-box;", "background:linear-gradient(#000,#000);box-sizing: border-box;")), + ("the banner mask changed", "colour", [], lambda d: edit_css(d, " mask-image: linear-gradient(transparent, #000 10%", " mask-image: linear-gradient(transparent, #000 20%")), + ("the banner mask missing", "colour", [], lambda d: edit_css(d, " " + MASKS[0], " ")), ("base tag", "no-js", [], lambda d: edit(d, "index.html", "<body>", '<body><base href="https://example.net/">')), - ("private name as a character reference in the mark", "private", ["zzprivate"], lambda d: edit(d, "mark.svg", "<title>", "<title>zzprivate ")), - ("private name as a nested reference in an attribute", "private", ["zzprivate"], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path id="zz&#112;rivate" class="k"')), - ("private repo as a character reference in the mark", "private", [], lambda d: edit(d, "mark.svg", "<title>", "<title>github.com/machine-made/zzprivate ")), - ("remote url in a filter attribute", "links", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path filter="url(https://example.net/x.svg#f)" class="k"')), - ("remote url in a fill attribute", "links", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(https://example.net/x.svg#f)" class="k"')), - ("local fragment in a filter attribute", None, [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path filter="url(#f)" class="k"')), + ("private name as a character reference in llms.txt", "private", ["zzprivate"], lambda d: edit(d, "404.html", "<body>", "<body>zzprivate ")), + ("private name as a nested reference in an attribute", "private", ["zzprivate"], lambda d: edit(d, "llms.txt", "## Sites", "zz&#112;rivate\n\n## Sites")), + ("private repo as a character reference", "private", [], lambda d: edit(d, "llms.txt", "## Sites", "github.com/machine-made/zzprivate\n\n## Sites")), ("USD before an amount", "forbidden", [], lambda d: edit(d, "llms.txt", "## Sites", "USD 5\n\n## Sites")), ("CHF before an amount", "forbidden", [], lambda d: edit(d, "llms.txt", "## Sites", "chf 5\n\n## Sites")), ("EUR before an amount", "forbidden", [], lambda d: edit(d, "llms.txt", "## Sites", "Eur5\n\n## Sites")), ("USD after an amount", "forbidden", [], lambda d: edit(d, "llms.txt", "## Sites", "5 USD\n\n## Sites")), ("private name as an element name", "private", ["zzprivate"], lambda d: edit(d, "index.html", "<body>", "<body><zzprivate></zzprivate>")), - # The behaviour rules of the brief: each break is one rule moved out of its media query. - ("a hover rule outside the hover query", "hover", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.plate:hover{margin:0")), - ("a scaled plate image is not clipped", "hover", [], lambda d: edit(d, "style.css", ".pic {\n display: block;\n overflow: hidden;", ".pic {\n display: block;")), - ("a hover rule in the wrong query", "hover", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}@media (min-width: 1px){.plate:hover{margin:0}}.zz{margin:0")), - ("a hover rule in the hover query is allowed", None, [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}@media (hover: hover){.zz:hover{margin:0}}.zz{margin:0")), - ("a transition outside the motion query", "motion", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{transition:color 1s")), - ("a transform outside the motion query", "motion", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.zz{transform:scale(2)")), - ("a hover transform without the motion query", "motion", [], lambda d: edit(d, "style.css", "@media (hover: hover) and (prefers-reduced-motion: no-preference)", "@media (hover: hover)")), - ("an animation in a hover query only", "motion", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}@media (hover: hover){.zz{animation:none}}.zz{margin:0")), - ("smooth scrolling outside the motion query", "motion", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}html{scroll-behavior:smooth")), - ("the focus ring is removed", "focus", [], lambda d: edit(d, "style.css", "outline: 2px solid var(--accent);", "outline: none;")), - ("the focus ring is not the accent", "focus", [], lambda d: edit(d, "style.css", "outline: 2px solid var(--accent);", "outline: 2px solid var(--fg);")), - ("an outline is removed on a link", "focus", [], lambda d: edit(d, "style.css", "box-sizing", "box-sizing:border-box}.plate a{outline:none}.zz{margin:0")), - ("the plate grid minimum changed", "responsive", [], lambda d: edit(d, "style.css", "minmax(min(100%, 240px), 1fr)", "minmax(min(100%, 150px), 1fr)")), - ("the plate grid has a fixed minimum", "responsive", [], lambda d: edit(d, "style.css", "minmax(min(100%, 240px), 1fr)", "minmax(240px, 1fr)")), - ("the content width changed", "responsive", [], lambda d: edit(d, "style.css", "--max: 1200px", "--max: 1280px")), - ("a forced width", "responsive", [], lambda d: edit(d, "style.css", "box-sizing", "width:900px;box-sizing")), - ("no-wrap text", "responsive", [], lambda d: edit(d, "style.css", "box-sizing", "white-space:nowrap;box-sizing")), - ("the accent never used", "accent", [], lambda d: (d / "style.css").write_text(re.sub(r"var\(--accent\)", "var(--fg)", (d / "style.css").read_text()))), + # The behaviour rules: each break is one rule moved out of its media query. + ("a hover rule outside the hover query", "hover", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.plate:hover{margin:0}")), + ("a colour hover outside the hover query", "hover", [], lambda d: edit_css(d, "@media (hover: hover) { .b1 a:hover { color: var(--text); } }", ".b1 a:hover { color: var(--text); }")), + ("a hover rule in the wrong query", "hover", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }@media (min-width: 1px){.plate:hover{margin:0}}")), + ("a hover rule in the hover query is allowed", None, [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }@media (hover: hover){.zz:hover{margin:0}}")), + ("a transition outside the motion query", "motion", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{transition:color 1s}")), + ("a transform outside the motion query", "motion", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.zz{transform:scale(2)}")), + ("the plate transition leaves the motion query", "motion", [], lambda d: edit_css(d, "outline-offset: -1px; }", "outline-offset: -1px; transition: filter 240ms var(--ease); }")), + ("the bar-2 line animates for every reader", "motion", [], lambda d: edit_css(d, "@media (prefers-reduced-motion: no-preference) {\n @supports", "@media (min-width: 1px) {\n @supports")), + ("an animation in a hover query only", "motion", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }@media (hover: hover){.zz{animation:none}}")), + ("smooth scrolling outside the motion query", "motion", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }html{scroll-behavior:smooth}")), + ("the focus ring is removed", "focus", [], lambda d: edit_css(d, ":focus-visible { outline: 2px solid var(--accent);", ":focus-visible { outline: none;")), + ("the focus ring is not the accent", "focus", [], lambda d: edit_css(d, ":focus-visible { outline: 2px solid var(--accent);", ":focus-visible { outline: 2px solid var(--text);")), + ("an outline is removed on a link", "focus", [], lambda d: edit_css(d, "box-sizing: border-box; }", "box-sizing: border-box; }.plate a{outline:none}")), + ("the page grid changed", "responsive", [], lambda d: edit_css(d, ".row { display: grid; grid-template-columns: repeat(12,", ".row { display: grid; grid-template-columns: repeat(10,")), + ("the plate grid is four columns", "responsive", [], lambda d: edit_css(d, ".grid { display: grid; grid-template-columns: repeat(3,", ".grid { display: grid; grid-template-columns: repeat(4,")), + ("the plate grid keeps two columns on a phone", "responsive", [], lambda d: edit_css(d, ".grid, .grid.g2 { grid-template-columns: minmax(0, 1fr);", ".grid, .grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr));")), + ("the content width changed", "responsive", [], lambda d: edit_css(d, "--max: 1200px", "--max: 1280px")), + ("a forced width", "responsive", [], lambda d: edit_css(d, "box-sizing: border-box;", "width:900px;box-sizing: border-box;")), + ("the accent never used", "accent", [], lambda d: edit_css_all(d, "var(--accent)", "var(--text)")), + ("the style is not src/system.css", "css", [], lambda d: edit(d, "index.html", "box-sizing: border-box;", "box-sizing: content-box;")), + ("the faces block differs from the house", "fonts", [], lambda d: edit(d, "index.html", "font-display:swap}", "font-display:swap} ")), + # The 404 page. + ("the 404 page links relative to itself", "404", [], lambda d: edit(d, "404.html", 'href="/img/touch.png"', 'href="img/touch.png"')), + ("the 404 page loads fonts relative to itself", "404", [], lambda d: edit(d, "404.html", "url(/fonts/weft.woff2)", "url(fonts/weft.woff2)")), + ("the 404 page loses its way home", "404", [], lambda d: edit(d, "404.html", '<a class="u" href="/">', '<a class="u" href="#main">')), + ("the 404 title changed", "404", [], lambda d: edit(d, "404.html", "<title>Not found –", "<title>Missing –")), + ("the 404 page has another bar 1", "404", [], lambda d: edit(d, "404.html", f'<span aria-current="page">{SELF}</span>', f'<a href="{self_url}" aria-current="page">{SELF}</a>')), + ("the 404 section link points to no group", "links", [], lambda d: edit(d, "404.html", f'<a href="/#g-{slug(GROUPS[0][0])}">', '<a href="/#g-zz">')), + ("the 404 page loads a missing image", "links", [], lambda d: edit(d, "404.html", 'href="/img/touch.png"', 'href="/img/zz.png"')), ] if REDIRECTS: folder = next(iter(REDIRECTS)) @@ -1628,6 +2226,27 @@ def run(d: Path) -> None: ("redirect refresh differs from canonical", "redirects", [], lambda d: edit(d, f"{folder}/index.html", f'content="0; url={target}"', 'content="0; url=https://example.net/"')), ("redirect page with a script", "redirects", [], lambda d: edit(d, f"{folder}/index.html", "</head>", "<script>1</script></head>")), ] + if SELF == "machine-made": + cases += [ + ("accent in a style attribute", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path style="fill:#00f" class="k"')), + ("accent in stop-color", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path stop-color="#00ff00" class="k"')), + ("named colour in a stroke", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path stroke="red" class="k"')), + ("named colour in an svg rule", "accent", [], lambda d: edit(d, "mark.svg", ".k{fill:", ".k{stroke:red;fill:")), + ("gradient in the mark", "colour", [], lambda d: edit(d, "mark.svg", "<rect", '<defs><linearGradient id="z"/></defs><rect')), + ("script in the mark svg", "no-js", [], lambda d: edit(d, "mark.svg", "<title>", "<script>1</script><title>")), + ("event handler in the mark svg", "no-js", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path onclick="x()" class="k"')), + ("external href in the mark svg", "links", [], lambda d: edit(d, "mark.svg", "<rect", '<use href="https://example.net/x.svg#a"/><rect')), + ("remote url in an svg rule", "links", [], lambda d: edit(d, "mark.svg", "<style>", "<style>.z{fill:url(https://example.net/x.svg#a)}")), + ("accent as the fallback of a fragment paint", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) #0000ff" class="k"')), + ("named fallback of a fragment paint", "accent", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) red" class="k"')), + ("function fallback of a fragment paint", "colour", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) rgb(0,0,255)" class="k"')), + ("keyword fallback of a fragment paint", None, [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(#a) currentColor" class="k"')), + ("private name as a character reference in the mark", "private", ["zzprivate"], lambda d: edit(d, "mark.svg", "<title>", "<title>zzprivate ")), + ("private repo as a character reference in the mark", "private", [], lambda d: edit(d, "mark.svg", "<title>", "<title>github.com/machine-made/zzprivate ")), + ("remote url in a filter attribute", "links", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path filter="url(https://example.net/x.svg#f)" class="k"')), + ("remote url in a fill attribute", "links", [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path fill="url(https://example.net/x.svg#f)" class="k"')), + ("local fragment in a filter attribute", None, [], lambda d: edit(d, "mark.svg", '<rect class="k"', '<path filter="url(#f)" class="k"')), + ] total, bad = 0, 0 def report(ok: bool, title: str) -> None: @@ -1637,71 +2256,181 @@ def report(ok: bool, title: str) -> None: bad += 1 print(f"SELF-TEST FAIL: {title}") + real_theme = dict(THEME) with tempfile.TemporaryDirectory() as tmp: - for title, rule, deny, mutate in [*cases, ("clean copy", None, [], lambda d: None)]: + for title, rule_name, deny, mutate in [*cases, ("clean copy", None, [], lambda d: None)]: root = Path(tmp) / "case" shutil.rmtree(root, ignore_errors=True) shutil.copytree(real, root / "docs") (root / "README.md").write_text("outside docs/\n") - DOCS = root / "docs" + DOCS, SYSTEM_SRC = root / "docs", real_src + THEME.clear() + THEME.update(real_theme) + FONT_DIR = GEN / "fonts" try: mutate(DOCS) found = run_checks(deny) except AssertionError as exc: - found, rule = [str(exc)], "stale" - except Exception as exc: - found, rule = [f"crash {exc!r}"], "no crash" - caught = any(line.startswith(f"FAIL {rule}:") for line in found) if rule else not found - report(caught, f"{title}: expected {rule or 'a clean pass'}, got {found[:2]}") - DOCS = real + found, rule_name = [str(exc)], "stale" + except Exception as exc: # noqa: BLE001 -- a crash is a self-test failure, reported with its case + found, rule_name = [f"crash {exc!r}"], "no crash" + caught = any(line.startswith(f"FAIL {rule_name}:") for line in found) if rule_name else not found + report(caught, f"{title}: expected {rule_name or 'a clean pass'}, got {found[:2]}") + DOCS, SYSTEM_SRC, FONT_DIR = real, real_src, GEN / "fonts" + THEME.clear() + THEME.update(real_theme) + site = json.loads((GEN / "site.json").read_text(encoding="utf-8")) for bad_name in ("../evil", "Machine", "a..b", "-x", "a/b"): - report(build_rejects({"name": bad_name}), f"build.py accepted the site name {bad_name!r}") + report(build_rejects({"name": bad_name}, data), f"build.py accepted the site name {bad_name!r}") + theme = site["theme"] + group0 = site["groups"][0] bad_sites: list[dict[str, object]] = [ {"groups": []}, {"groups": "x"}, - {"groups": [{"title": "A", "projects": []}]}, - {"groups": [{"title": "A", "projects": [{"repo": first, "line": "y"}]}, {"title": "a!", "projects": [{"repo": second, "line": "y"}]}]}, - {"groups": [{"title": "A", "projects": [{"repo": first, "line": "y"}, {"repo": first, "line": "y"}]}]}, - {"groups": [{"title": "A", "projects": [{"repo": first, "line": "y", "site": "http://x"}]}]}, - {"groups": [{"title": "A", "projects": [{"repo": "zz-no-image", "line": "y"}]}]}, - {"groups": [{"title": "A", "projects": [{"repo": first, "line": "cafรฉ"}]}]}, - {"blurb": 5}, + {"groups": [{"title": "A", "nav": "A", "projects": []}]}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": first, "line": "y"}]}, {"title": "a!", "nav": "B", "projects": [{"repo": second, "line": "y"}]}]}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": first, "line": "y"}, {"repo": first, "line": "y"}]}]}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": first, "line": "y", "site": "http://x"}]}]}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": "zz-no-image", "line": "y"}]}]}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": first, "line": "cafรฉ"}]}]}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": "homebrew-tap", "line": "y"}]}]}, + {"groups": [{"title": "A", "projects": [{"repo": first, "line": "y"}]}]}, + {"groups": [{**group0, "nav": "A label far too long"}]}, + {"blurb": "x"}, {"line": "cafรฉ"}, - {"theme": {"ground": "#000", "text": "#ffffff", "muted": "#888888", "accent": "#ff0000", "font": WEFT}}, - {"theme": {**json.loads((ROOT / "site.json").read_text(encoding="utf-8"))["theme"], "size": 20}}, - {"groups": [{"title": "A", "projects": [{"repo": first, "line": "y", "site": "https://example.net/", "site_label": "demo"}]}]}, - {"groups": [{"title": "A", "projects": [{"repo": first, "line": "y", "site_label": "docs"}]}]}, - {"theme": {**json.loads((ROOT / "site.json").read_text(encoding="utf-8"))["theme"], "font": "Comic Sans"}}, + {"theme": {**theme, "ground": "#000"}}, + {"theme": {**theme, "size": 20}}, + {"theme": {k: v for k, v in theme.items() if k != "surface"}}, + {"theme": {**theme, "muted": "#3a3a3a"}}, + {"theme": {**theme, "face": "Comic Sans"}}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": first, "line": "y", "site": "https://example.net/", "site_label": "demo"}]}]}, + {"groups": [{"title": "A", "nav": "A", "projects": [{"repo": first, "line": "y", "site_label": "docs"}]}]}, {"nav": []}, {"nav": ["machine-made"]}, - {"nav": [dict(n) for n in json.loads((ROOT / "site.json").read_text(encoding="utf-8"))["nav"][:3]]}, - {"nav": [*json.loads((ROOT / "site.json").read_text(encoding="utf-8"))["nav"][:3], {"name": "type", "url": "https://example.net/type/"}]}, - {"nav": [*json.loads((ROOT / "site.json").read_text(encoding="utf-8"))["nav"][:3], {"name": "type", "url": TYPE_URL, "self": True}]}, - {"redirects": {"style.css": "https://example.net/x"}}, + {"nav": [dict(n) for n in site["nav"][:3]]}, + {"nav": [*site["nav"][:3], {"name": "type", "url": "https://example.net/type/"}]}, + {"nav": [*site["nav"][:3], {"name": "type", "url": TYPE_URL, "self": True}]}, + {"redirects": {"404.html": "https://example.net/x"}}, {"redirects": {"llms.txt": "https://example.net/x"}}, + {"groups": [{"title": "Latest", "nav": "A", "projects": [{"repo": first, "line": "y"}]}]}, + {"groups": [{"title": "Houses", "nav": "A", "projects": [{"repo": first, "line": "y"}]}]}, ] for changes in bad_sites: - report(build_rejects(changes), f"build.py accepted {str(changes)[:60]}") - for problem in site_links_hold(): + report(build_rejects(changes, data), f"build.py accepted {str(changes)[:60]}") + for problem in site_links_hold(data): report(False, problem) - report(renamed_site_passes("loom-x"), "a site under another name does not pass the checks") - report(build_needs("fonts/mm-weft.woff2"), "build.py builds without the fonts in fonts/") - report(build_needs(f"img/org/{name}.jpg"), "build.py builds without the banner of the house") - report(build_needs(f"img/repo/{first}.jpg"), "build.py builds without the banner of a repository") + report(build_needs("fonts/mm-weft.woff2", data), "build.py builds without the fonts in fonts/") + report(build_needs("src/system.css", data), "build.py builds without src/system.css") + report(build_needs(f"img/org/{name}.jpg", data), "build.py builds without the banner of the house") + report(build_needs(f"img/repo/{first}.jpg", data), "build.py builds without the banner of a repository") + report(build_fails_on_fetch(), "build.py builds when the GitHub fetch fails") + broken = Path(tmp) / "data.json" + facts = json.loads(data.read_text(encoding="utf-8")) + del facts["repos"][first_full] + broken.write_text(json.dumps(facts), encoding="utf-8") + report(build_rejects({}, broken), "build.py builds from a facts file that lacks a repository") missing = str(Path(tmp) / "missing") denied = Path(tmp) / "deny.txt" denied.write_text("# a comment\n\nzz one\n zz two \n#zz three\n", encoding="utf-8") report(load_deny(str(denied)) == ["zz one", "zz two"], "load_deny does not keep one name per line") report(cli_fails(["--deny"], "FAIL args:"), "--deny without a file") - report(cli_fails(["--deny", missing], "FAIL deny:"), "--deny with a missing file") + report(cli_fails(["--data", DATA_PATH, "--deny", missing], "FAIL deny:"), "--deny with a missing file") report(cli_fails(["--no-such-flag"], "FAIL args:"), "an unknown flag") - report(cli_fails(["--site", missing], "FAIL args:"), "--site with no allow.json") + report(cli_fails(["--data", DATA_PATH, "--site", missing], "FAIL args:"), "--site with no allow.json") + report(cli_fails([], "FAIL args:"), "no GitHub facts file") + report(cli_fails(["--data", str(broken)], "FAIL args:"), "a facts file that lacks a repository") + hollow = Path(tmp) / "hollow.json" + facts = json.loads(data.read_text(encoding="utf-8")) + facts["repos"][first_full] = {} + hollow.write_text(json.dumps(facts), encoding="utf-8") + report(cli_fails(["--data", str(hollow)], "FAIL args:"), "a facts file with an empty repository record") + report(cli_fails(["--data", DATA_PATH, "--self-test", "--site", str(GEN)], "FAIL args:"), "--self-test with --site") + stale = Path(tmp) / "stale" + stale.mkdir() + shutil.copy(ROOT / "allow.json", stale / "allow.json") + site_json = json.loads((ROOT / "site.json").read_text(encoding="utf-8")) + site_json["theme"]["accent"] = "#123456" + (stale / "site.json").write_text(json.dumps(site_json), encoding="utf-8") + report(cli_fails(["--data", DATA_PATH, "--site", str(stale)], "FAIL args:"), "site.json theme differs from allow.json") + report(other_rs_known(), "the check refuses the -rs repository of another house") if bad: sys.exit(1) print(f"SELF-TEST OK ({total} cases)") -def footer_html(docs: Path) -> str: +def other_rs_known() -> bool: + """A -rs repository of another house (named by the houses row) passes the leak check.""" + global OTHERS # noqa: PLW0603 + real = OTHERS + name = next(iter(real)) + OTHERS = {**real, name: (real[name][0], (*real[name][1], "zz/zz-other-rs"))} + try: + del failures[:] + check_leaks("zz-other-rs", []) + return not any("zz-other-rs" in f for f in failures) + finally: + OTHERS = real + del failures[:] + + +def break_source(docs: Path) -> None: + """Point the checks at a copy of fonts/ whose Weft source has one more byte.""" + global FONT_DIR # noqa: PLW0603 + copy = docs.parent / "fonts" + shutil.copytree(GEN / "fonts", copy) + (copy / "mm-weft.woff2").write_bytes((copy / "mm-weft.woff2").read_bytes() + b"\x00") + FONT_DIR = copy + + +def set_theme(key: str, value: str) -> None: + """A case that changes the public list itself: the page and allow.json agree on a colour that fails its floor.""" + THEME[key] = value + + +def cut_font(path: Path, keep: str) -> bytes: + from io import BytesIO + + from fontTools import subset as fts + + opts = fts.Options() + opts.flavor = "woff2" + opts.layout_features = ["*"] + font = fts.load_font(str(path), opts) + sub = fts.Subsetter(opts) + sub.populate(text=keep) + sub.subset(font) + buf = BytesIO() + fts.save_font(font, buf, opts) + return buf.getvalue() + + +def tiny_png() -> bytes: + """A valid 1 x 1 PNG.""" + import struct + import zlib + + def chunk(kind: bytes, body: bytes) -> bytes: + return struct.pack(">I", len(body)) + kind + body + struct.pack(">I", zlib.crc32(kind + body)) + + return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", 1, 1, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(b"\x00\x00\x00\x00")) + chunk(b"IEND", b"") + + +def edit_css_all(docs: Path, old: str, new: str) -> None: + """Replace every occurrence in the source copy and both pages.""" + global SYSTEM_SRC # noqa: PLW0603 + copy = docs.parent / "system.css" + if not copy.is_file(): + shutil.copy(SYSTEM_SRC, copy) + SYSTEM_SRC = copy + copy.write_text(copy.read_text(encoding="utf-8").replace(old, new), encoding="utf-8") + for page in ("index.html", "404.html"): + path = docs / page + text = path.read_text(encoding="utf-8") + head, _, style = text.rpartition("<style>") + path.write_text(head + "<style>" + style.replace(old, new), encoding="utf-8") + + +def footer_of(docs: Path) -> str: """The footer element of docs/index.html as written.""" found = re.search(r"<footer.*?</footer>", read_index(docs), re.S) if found is None: @@ -1712,49 +2441,57 @@ def footer_html(docs: Path) -> str: def move_footer_up(docs: Path) -> None: """Put the footer before the main part: the page order is broken.""" text = read_index(docs) - foot = re.search(r"<footer.*?</footer>\n", text, re.S) - if foot is None: - raise AssertionError("self-test is stale: no footer in docs/index.html") # noqa: TRY003 - text = text.replace(foot.group(0), "").replace('<main id="main"', foot.group(0) + '<main id="main"', 1) + foot = footer_of(docs) + text = text.replace(foot, "").replace('<main id="main"', foot + '<main id="main"', 1) (docs / "index.html").write_text(text, encoding="utf-8") -def read_css(docs: Path) -> str: - return (docs / "style.css").read_text(encoding="utf-8") - - def read_index(docs: Path) -> str: return (docs / "index.html").read_text(encoding="utf-8") def load_allow(folder: str) -> None: - """Point the checks at a house. Its allow.json is the public list, kept apart from site.json - on purpose: the page passes only when the two agree.""" - global ROOT, DOCS, OWNER, LINE, BLURB, THEME, SELF, SITES, GROUPS, SITE_LINKS, SITE_LABELS, REDIRECTS # noqa: PLW0603 + """Point the checks at a house. Its allow.json is the public list, kept apart from site.json on purpose: the page + passes only when the two agree. The other houses come from the allow.json files of this generator.""" + global ROOT, DOCS, OWNER, LINE, THEME, SELF, SITES, GROUPS, SITE_LINKS, SITE_LABELS, REDIRECTS, OTHERS # noqa: PLW0603 root = Path(folder).resolve() try: allow = json.loads((root / "allow.json").read_text(encoding="utf-8")) - OWNER, LINE, BLURB = str(allow["owner"]), str(allow["line"]), str(allow["blurb"]) - THEME = {k: str(allow["theme"][k]) for k in ("ground", "text", "muted", "accent", "font")} + OWNER, LINE = str(allow["owner"]), str(allow["line"]) + THEME = {k: str(allow["theme"][k]) for k in (*THEME_KEYS, "face")} SITES = tuple((str(n), str(u)) for n, u in allow["sites"]) SELF = str(allow["self"]) GROUPS = tuple((str(title), tuple(str(r) for r in repos)) for title, repos in allow["groups"]) SITE_LINKS = {str(k): str(v) for k, v in allow.get("site_links", {}).items()} SITE_LABELS = {str(k): str(v) for k, v in allow.get("site_labels", {}).items()} REDIRECTS = {str(k): str(v) for k, v in allow.get("redirects", {}).items()} - site_owner = str(json.loads((root / "site.json").read_text(encoding="utf-8"))["owner"]) + site_json = json.loads((root / "site.json").read_text(encoding="utf-8")) + site_owner = str(site_json["owner"]) + site_theme = {k: str(site_json["theme"][k]) for k in (*THEME_KEYS, "face")} + others = {} + for path in [GEN / "allow.json", *sorted((GEN / "houses").glob("*/allow.json"))]: + other = json.loads(path.read_text(encoding="utf-8")) + if other["self"] != SELF: + others[str(other["self"])] = (str(other["line"]), tuple(str(r) for _, repos in other["groups"] for r in repos)) + OTHERS = others except (OSError, ValueError, KeyError, TypeError) as exc: print(f"FAIL args: {folder}/allow.json is missing or incomplete ({exc.__class__.__name__})") sys.exit(2) if site_owner != OWNER: print(f"FAIL args: {folder}/allow.json owner {OWNER!r} differs from site.json owner {site_owner!r}") sys.exit(2) - if THEME["font"] not in FONT_SPECS or SELF not in {n for n, _ in SITES}: - print(f"FAIL args: {folder}/allow.json names a font or a current site that the checks do not know") + if site_theme != THEME: + print(f"FAIL args: {folder}/site.json theme differs from allow.json; set both, then run python3 build.py") + sys.exit(2) + if THEME["face"] not in FACES or SELF not in {n for n, _ in SITES}: + print(f"FAIL args: {folder}/allow.json names a face or a current site that the checks do not know") sys.exit(2) if [n for n, _ in SITES] != list(BAR_NAMES) or dict(SITES)["type"] != TYPE_URL or SELF == "type": print(f"FAIL args: {folder}/allow.json sites must be {', '.join(BAR_NAMES)} with type at {TYPE_URL}") sys.exit(2) + if set(OTHERS) != set(BAR_NAMES[:3]) - {SELF}: + print(f"FAIL args: the generator must hold the allow.json of {', '.join(BAR_NAMES[:3])}") + sys.exit(2) if set(SITE_LABELS) - set(SITE_LINKS) or not set(SITE_LABELS.values()) <= {"docs"}: print(f"FAIL args: {folder}/allow.json site_labels may only mark a site link as docs") sys.exit(2) @@ -1762,12 +2499,20 @@ def load_allow(folder: str) -> None: def main() -> None: + global DATA_PATH # noqa: PLW0603 args = parse_args(sys.argv[1:]) - load_allow(args.site or str(ROOT)) + if args.self_test and args.site: + print("FAIL args: the self-test builds and breaks the generator's own site; run it without --site " + "(gate.sh then checks every house with --site)") + sys.exit(2) + load_allow(args.site or str(GEN)) + load_data(args.data) + DATA_PATH = str(Path(args.data or os.environ["MM_DATA"]).resolve()) + deny = load_deny(args.deny) if args.self_test: self_test() return - found = run_checks(load_deny(args.deny)) + found = run_checks(deny) if found: print("\n".join(found)) sys.exit(1) diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..086371c --- /dev/null +++ b/docs/404.html @@ -0,0 +1,191 @@ +<!doctype html> +<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><title>Not found – machine-made +

    Not found

    This page does not exist.

    Back to machine-made

    diff --git a/docs/fonts/mm-sans-OFL.txt b/docs/fonts/mm-sans-OFL.txt new file mode 100644 index 0000000..fd56bf8 --- /dev/null +++ b/docs/fonts/mm-sans-OFL.txt @@ -0,0 +1,95 @@ +Copyright 2020 The Plus Jakarta Sans Project Authors (https://github.com/tokotype/PlusJakartaSans) +Copyright 2026 The machine-made Sans Project Authors (https://github.com/machine-made/type), +with Reserved Font Name "machine-made". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/docs/fonts/mm-weft.woff2 b/docs/fonts/mm-weft.woff2 deleted file mode 100644 index b32fe74..0000000 Binary files a/docs/fonts/mm-weft.woff2 and /dev/null differ diff --git a/docs/fonts/sans.woff2 b/docs/fonts/sans.woff2 new file mode 100644 index 0000000..176b75b Binary files /dev/null and b/docs/fonts/sans.woff2 differ diff --git a/docs/fonts/weft.woff2 b/docs/fonts/weft.woff2 new file mode 100644 index 0000000..e0bf8f3 Binary files /dev/null and b/docs/fonts/weft.woff2 differ diff --git a/docs/img/alexandria-352.avif b/docs/img/alexandria-352.avif new file mode 100644 index 0000000..71d55a7 Binary files /dev/null and b/docs/img/alexandria-352.avif differ diff --git a/docs/img/alexandria-352.jpg b/docs/img/alexandria-352.jpg new file mode 100644 index 0000000..5b19fa8 Binary files /dev/null and b/docs/img/alexandria-352.jpg differ diff --git a/docs/img/alexandria-704.avif b/docs/img/alexandria-704.avif new file mode 100644 index 0000000..382d3e1 Binary files /dev/null and b/docs/img/alexandria-704.avif differ diff --git a/docs/img/alexandria-704.jpg b/docs/img/alexandria-704.jpg new file mode 100644 index 0000000..0d3152c Binary files /dev/null and b/docs/img/alexandria-704.jpg differ diff --git a/docs/img/alexandria.jpg b/docs/img/alexandria.jpg deleted file mode 100644 index 9fc89fa..0000000 Binary files a/docs/img/alexandria.jpg and /dev/null differ diff --git a/docs/img/banner-boringquantsystems-1408.avif b/docs/img/banner-boringquantsystems-1408.avif new file mode 100644 index 0000000..e05e2a9 Binary files /dev/null and b/docs/img/banner-boringquantsystems-1408.avif differ diff --git a/docs/img/banner-boringquantsystems-1408.jpg b/docs/img/banner-boringquantsystems-1408.jpg new file mode 100644 index 0000000..161e2d0 Binary files /dev/null and b/docs/img/banner-boringquantsystems-1408.jpg differ diff --git a/docs/img/banner-boringquantsystems-704.avif b/docs/img/banner-boringquantsystems-704.avif new file mode 100644 index 0000000..b8e26ed Binary files /dev/null and b/docs/img/banner-boringquantsystems-704.avif differ diff --git a/docs/img/banner-boringquantsystems-704.jpg b/docs/img/banner-boringquantsystems-704.jpg new file mode 100644 index 0000000..64ae64c Binary files /dev/null and b/docs/img/banner-boringquantsystems-704.jpg differ diff --git a/docs/img/banner-machine-made-1408.avif b/docs/img/banner-machine-made-1408.avif new file mode 100644 index 0000000..ef772dd Binary files /dev/null and b/docs/img/banner-machine-made-1408.avif differ diff --git a/docs/img/banner-machine-made-1408.jpg b/docs/img/banner-machine-made-1408.jpg new file mode 100644 index 0000000..50b8246 Binary files /dev/null and b/docs/img/banner-machine-made-1408.jpg differ diff --git a/docs/img/banner-machine-made-704.avif b/docs/img/banner-machine-made-704.avif new file mode 100644 index 0000000..f5095c7 Binary files /dev/null and b/docs/img/banner-machine-made-704.avif differ diff --git a/docs/img/banner-machine-made-704.jpg b/docs/img/banner-machine-made-704.jpg new file mode 100644 index 0000000..3e7a756 Binary files /dev/null and b/docs/img/banner-machine-made-704.jpg differ diff --git a/docs/img/banner-openfluids-1408.avif b/docs/img/banner-openfluids-1408.avif new file mode 100644 index 0000000..957af48 Binary files /dev/null and b/docs/img/banner-openfluids-1408.avif differ diff --git a/docs/img/banner-openfluids-1408.jpg b/docs/img/banner-openfluids-1408.jpg new file mode 100644 index 0000000..33997d8 Binary files /dev/null and b/docs/img/banner-openfluids-1408.jpg differ diff --git a/docs/img/banner-openfluids-704.avif b/docs/img/banner-openfluids-704.avif new file mode 100644 index 0000000..d0a28d3 Binary files /dev/null and b/docs/img/banner-openfluids-704.avif differ diff --git a/docs/img/banner-openfluids-704.jpg b/docs/img/banner-openfluids-704.jpg new file mode 100644 index 0000000..3363762 Binary files /dev/null and b/docs/img/banner-openfluids-704.jpg differ diff --git a/docs/img/banner.jpg b/docs/img/banner.jpg deleted file mode 100644 index 9208ae1..0000000 Binary files a/docs/img/banner.jpg and /dev/null differ diff --git a/docs/img/bun-do-352.avif b/docs/img/bun-do-352.avif new file mode 100644 index 0000000..0495a8f Binary files /dev/null and b/docs/img/bun-do-352.avif differ diff --git a/docs/img/bun-do-352.jpg b/docs/img/bun-do-352.jpg new file mode 100644 index 0000000..7fc7c99 Binary files /dev/null and b/docs/img/bun-do-352.jpg differ diff --git a/docs/img/bun-do-704.avif b/docs/img/bun-do-704.avif new file mode 100644 index 0000000..a1ed8b3 Binary files /dev/null and b/docs/img/bun-do-704.avif differ diff --git a/docs/img/bun-do-704.jpg b/docs/img/bun-do-704.jpg new file mode 100644 index 0000000..3903a46 Binary files /dev/null and b/docs/img/bun-do-704.jpg differ diff --git a/docs/img/bun-do.jpg b/docs/img/bun-do.jpg deleted file mode 100644 index 18341b9..0000000 Binary files a/docs/img/bun-do.jpg and /dev/null differ diff --git a/docs/img/fortran-lsp-352.avif b/docs/img/fortran-lsp-352.avif new file mode 100644 index 0000000..dc1bec7 Binary files /dev/null and b/docs/img/fortran-lsp-352.avif differ diff --git a/docs/img/fortran-lsp-352.jpg b/docs/img/fortran-lsp-352.jpg new file mode 100644 index 0000000..0f15a1b Binary files /dev/null and b/docs/img/fortran-lsp-352.jpg differ diff --git a/docs/img/fortran-lsp-704.avif b/docs/img/fortran-lsp-704.avif new file mode 100644 index 0000000..2e186e3 Binary files /dev/null and b/docs/img/fortran-lsp-704.avif differ diff --git a/docs/img/fortran-lsp-704.jpg b/docs/img/fortran-lsp-704.jpg new file mode 100644 index 0000000..af2a4ce Binary files /dev/null and b/docs/img/fortran-lsp-704.jpg differ diff --git a/docs/img/fortran-lsp.jpg b/docs/img/fortran-lsp.jpg deleted file mode 100644 index bf77f30..0000000 Binary files a/docs/img/fortran-lsp.jpg and /dev/null differ diff --git a/docs/img/liblinear-rs-352.avif b/docs/img/liblinear-rs-352.avif new file mode 100644 index 0000000..26836e3 Binary files /dev/null and b/docs/img/liblinear-rs-352.avif differ diff --git a/docs/img/liblinear-rs-352.jpg b/docs/img/liblinear-rs-352.jpg new file mode 100644 index 0000000..bd6be42 Binary files /dev/null and b/docs/img/liblinear-rs-352.jpg differ diff --git a/docs/img/liblinear-rs-704.avif b/docs/img/liblinear-rs-704.avif new file mode 100644 index 0000000..d528d15 Binary files /dev/null and b/docs/img/liblinear-rs-704.avif differ diff --git a/docs/img/liblinear-rs-704.jpg b/docs/img/liblinear-rs-704.jpg new file mode 100644 index 0000000..bba763e Binary files /dev/null and b/docs/img/liblinear-rs-704.jpg differ diff --git a/docs/img/liblinear-rs.jpg b/docs/img/liblinear-rs.jpg deleted file mode 100644 index cef252b..0000000 Binary files a/docs/img/liblinear-rs.jpg and /dev/null differ diff --git a/docs/img/libsvm-rs-352.avif b/docs/img/libsvm-rs-352.avif new file mode 100644 index 0000000..1569077 Binary files /dev/null and b/docs/img/libsvm-rs-352.avif differ diff --git a/docs/img/libsvm-rs-352.jpg b/docs/img/libsvm-rs-352.jpg new file mode 100644 index 0000000..6291411 Binary files /dev/null and b/docs/img/libsvm-rs-352.jpg differ diff --git a/docs/img/libsvm-rs-704.avif b/docs/img/libsvm-rs-704.avif new file mode 100644 index 0000000..e7c595b Binary files /dev/null and b/docs/img/libsvm-rs-704.avif differ diff --git a/docs/img/libsvm-rs-704.jpg b/docs/img/libsvm-rs-704.jpg new file mode 100644 index 0000000..e39e731 Binary files /dev/null and b/docs/img/libsvm-rs-704.jpg differ diff --git a/docs/img/libsvm-rs.jpg b/docs/img/libsvm-rs.jpg deleted file mode 100644 index c8e27b3..0000000 Binary files a/docs/img/libsvm-rs.jpg and /dev/null differ diff --git a/docs/img/minuit2-rs-352.avif b/docs/img/minuit2-rs-352.avif new file mode 100644 index 0000000..66b2f55 Binary files /dev/null and b/docs/img/minuit2-rs-352.avif differ diff --git a/docs/img/minuit2-rs-352.jpg b/docs/img/minuit2-rs-352.jpg new file mode 100644 index 0000000..0ad05cc Binary files /dev/null and b/docs/img/minuit2-rs-352.jpg differ diff --git a/docs/img/minuit2-rs-704.avif b/docs/img/minuit2-rs-704.avif new file mode 100644 index 0000000..c43a616 Binary files /dev/null and b/docs/img/minuit2-rs-704.avif differ diff --git a/docs/img/minuit2-rs-704.jpg b/docs/img/minuit2-rs-704.jpg new file mode 100644 index 0000000..fb8ee92 Binary files /dev/null and b/docs/img/minuit2-rs-704.jpg differ diff --git a/docs/img/minuit2-rs.jpg b/docs/img/minuit2-rs.jpg deleted file mode 100644 index d21d4e3..0000000 Binary files a/docs/img/minuit2-rs.jpg and /dev/null differ diff --git a/docs/img/nanochat-rs-352.avif b/docs/img/nanochat-rs-352.avif new file mode 100644 index 0000000..b3f3e9d Binary files /dev/null and b/docs/img/nanochat-rs-352.avif differ diff --git a/docs/img/nanochat-rs-352.jpg b/docs/img/nanochat-rs-352.jpg new file mode 100644 index 0000000..f2364ed Binary files /dev/null and b/docs/img/nanochat-rs-352.jpg differ diff --git a/docs/img/nanochat-rs-704.avif b/docs/img/nanochat-rs-704.avif new file mode 100644 index 0000000..875d8ef Binary files /dev/null and b/docs/img/nanochat-rs-704.avif differ diff --git a/docs/img/nanochat-rs-704.jpg b/docs/img/nanochat-rs-704.jpg new file mode 100644 index 0000000..c38d5a2 Binary files /dev/null and b/docs/img/nanochat-rs-704.jpg differ diff --git a/docs/img/nanochat-rs.jpg b/docs/img/nanochat-rs.jpg deleted file mode 100644 index 6020e08..0000000 Binary files a/docs/img/nanochat-rs.jpg and /dev/null differ diff --git a/docs/img/nebula-quanta-352.avif b/docs/img/nebula-quanta-352.avif new file mode 100644 index 0000000..1d22db6 Binary files /dev/null and b/docs/img/nebula-quanta-352.avif differ diff --git a/docs/img/nebula-quanta-352.jpg b/docs/img/nebula-quanta-352.jpg new file mode 100644 index 0000000..c114af4 Binary files /dev/null and b/docs/img/nebula-quanta-352.jpg differ diff --git a/docs/img/nebula-quanta-704.avif b/docs/img/nebula-quanta-704.avif new file mode 100644 index 0000000..981542a Binary files /dev/null and b/docs/img/nebula-quanta-704.avif differ diff --git a/docs/img/nebula-quanta-704.jpg b/docs/img/nebula-quanta-704.jpg new file mode 100644 index 0000000..28bd6fb Binary files /dev/null and b/docs/img/nebula-quanta-704.jpg differ diff --git a/docs/img/nebula-quanta.jpg b/docs/img/nebula-quanta.jpg deleted file mode 100644 index c2a2941..0000000 Binary files a/docs/img/nebula-quanta.jpg and /dev/null differ diff --git a/docs/img/pdf-next-352.avif b/docs/img/pdf-next-352.avif new file mode 100644 index 0000000..83e9b25 Binary files /dev/null and b/docs/img/pdf-next-352.avif differ diff --git a/docs/img/pdf-next-352.jpg b/docs/img/pdf-next-352.jpg new file mode 100644 index 0000000..b6ec877 Binary files /dev/null and b/docs/img/pdf-next-352.jpg differ diff --git a/docs/img/pdf-next-704.avif b/docs/img/pdf-next-704.avif new file mode 100644 index 0000000..a86f4c3 Binary files /dev/null and b/docs/img/pdf-next-704.avif differ diff --git a/docs/img/pdf-next-704.jpg b/docs/img/pdf-next-704.jpg new file mode 100644 index 0000000..2527f93 Binary files /dev/null and b/docs/img/pdf-next-704.jpg differ diff --git a/docs/img/pdf-next.jpg b/docs/img/pdf-next.jpg deleted file mode 100644 index 7157b26..0000000 Binary files a/docs/img/pdf-next.jpg and /dev/null differ diff --git a/docs/img/pi-effort-352.avif b/docs/img/pi-effort-352.avif new file mode 100644 index 0000000..e56c8f2 Binary files /dev/null and b/docs/img/pi-effort-352.avif differ diff --git a/docs/img/pi-effort-352.jpg b/docs/img/pi-effort-352.jpg new file mode 100644 index 0000000..c84ddc1 Binary files /dev/null and b/docs/img/pi-effort-352.jpg differ diff --git a/docs/img/pi-effort-704.avif b/docs/img/pi-effort-704.avif new file mode 100644 index 0000000..72864b7 Binary files /dev/null and b/docs/img/pi-effort-704.avif differ diff --git a/docs/img/pi-effort-704.jpg b/docs/img/pi-effort-704.jpg new file mode 100644 index 0000000..c21848b Binary files /dev/null and b/docs/img/pi-effort-704.jpg differ diff --git a/docs/img/pi-effort.jpg b/docs/img/pi-effort.jpg deleted file mode 100644 index 48c4828..0000000 Binary files a/docs/img/pi-effort.jpg and /dev/null differ diff --git a/docs/img/pi-rethread-352.avif b/docs/img/pi-rethread-352.avif new file mode 100644 index 0000000..66f8ddc Binary files /dev/null and b/docs/img/pi-rethread-352.avif differ diff --git a/docs/img/pi-rethread-352.jpg b/docs/img/pi-rethread-352.jpg new file mode 100644 index 0000000..c735425 Binary files /dev/null and b/docs/img/pi-rethread-352.jpg differ diff --git a/docs/img/pi-rethread-704.avif b/docs/img/pi-rethread-704.avif new file mode 100644 index 0000000..7d7e811 Binary files /dev/null and b/docs/img/pi-rethread-704.avif differ diff --git a/docs/img/pi-rethread-704.jpg b/docs/img/pi-rethread-704.jpg new file mode 100644 index 0000000..b619c88 Binary files /dev/null and b/docs/img/pi-rethread-704.jpg differ diff --git a/docs/img/pi-rethread.jpg b/docs/img/pi-rethread.jpg deleted file mode 100644 index 34232e7..0000000 Binary files a/docs/img/pi-rethread.jpg and /dev/null differ diff --git a/docs/img/tex2speech-352.avif b/docs/img/tex2speech-352.avif new file mode 100644 index 0000000..1d583dc Binary files /dev/null and b/docs/img/tex2speech-352.avif differ diff --git a/docs/img/tex2speech-352.jpg b/docs/img/tex2speech-352.jpg new file mode 100644 index 0000000..d2f51d3 Binary files /dev/null and b/docs/img/tex2speech-352.jpg differ diff --git a/docs/img/tex2speech-704.avif b/docs/img/tex2speech-704.avif new file mode 100644 index 0000000..1870b7a Binary files /dev/null and b/docs/img/tex2speech-704.avif differ diff --git a/docs/img/tex2speech-704.jpg b/docs/img/tex2speech-704.jpg new file mode 100644 index 0000000..c54fed6 Binary files /dev/null and b/docs/img/tex2speech-704.jpg differ diff --git a/docs/img/tex2speech.jpg b/docs/img/tex2speech.jpg deleted file mode 100644 index 0d8c019..0000000 Binary files a/docs/img/tex2speech.jpg and /dev/null differ diff --git a/docs/img/touch.png b/docs/img/touch.png new file mode 100644 index 0000000..22a850b Binary files /dev/null and b/docs/img/touch.png differ diff --git a/docs/img/type-352.avif b/docs/img/type-352.avif new file mode 100644 index 0000000..0a07710 Binary files /dev/null and b/docs/img/type-352.avif differ diff --git a/docs/img/type-352.jpg b/docs/img/type-352.jpg new file mode 100644 index 0000000..cb2007f Binary files /dev/null and b/docs/img/type-352.jpg differ diff --git a/docs/img/type-704.avif b/docs/img/type-704.avif new file mode 100644 index 0000000..182e800 Binary files /dev/null and b/docs/img/type-704.avif differ diff --git a/docs/img/type-704.jpg b/docs/img/type-704.jpg new file mode 100644 index 0000000..0e82f6a Binary files /dev/null and b/docs/img/type-704.jpg differ diff --git a/docs/img/type.jpg b/docs/img/type.jpg deleted file mode 100644 index 30385bd..0000000 Binary files a/docs/img/type.jpg and /dev/null differ diff --git a/docs/img/vscode-diff-next-352.avif b/docs/img/vscode-diff-next-352.avif new file mode 100644 index 0000000..368c528 Binary files /dev/null and b/docs/img/vscode-diff-next-352.avif differ diff --git a/docs/img/vscode-diff-next-352.jpg b/docs/img/vscode-diff-next-352.jpg new file mode 100644 index 0000000..2d4164e Binary files /dev/null and b/docs/img/vscode-diff-next-352.jpg differ diff --git a/docs/img/vscode-diff-next-704.avif b/docs/img/vscode-diff-next-704.avif new file mode 100644 index 0000000..4f09bfc Binary files /dev/null and b/docs/img/vscode-diff-next-704.avif differ diff --git a/docs/img/vscode-diff-next-704.jpg b/docs/img/vscode-diff-next-704.jpg new file mode 100644 index 0000000..44f7be7 Binary files /dev/null and b/docs/img/vscode-diff-next-704.jpg differ diff --git a/docs/img/vscode-diff-next.jpg b/docs/img/vscode-diff-next.jpg deleted file mode 100644 index 1612209..0000000 Binary files a/docs/img/vscode-diff-next.jpg and /dev/null differ diff --git a/docs/img/vscode-pdf-next-352.avif b/docs/img/vscode-pdf-next-352.avif new file mode 100644 index 0000000..fdaeb55 Binary files /dev/null and b/docs/img/vscode-pdf-next-352.avif differ diff --git a/docs/img/vscode-pdf-next-352.jpg b/docs/img/vscode-pdf-next-352.jpg new file mode 100644 index 0000000..54dd6ca Binary files /dev/null and b/docs/img/vscode-pdf-next-352.jpg differ diff --git a/docs/img/vscode-pdf-next-704.avif b/docs/img/vscode-pdf-next-704.avif new file mode 100644 index 0000000..b075160 Binary files /dev/null and b/docs/img/vscode-pdf-next-704.avif differ diff --git a/docs/img/vscode-pdf-next-704.jpg b/docs/img/vscode-pdf-next-704.jpg new file mode 100644 index 0000000..1728960 Binary files /dev/null and b/docs/img/vscode-pdf-next-704.jpg differ diff --git a/docs/img/vscode-pdf-next.jpg b/docs/img/vscode-pdf-next.jpg deleted file mode 100644 index d4fb123..0000000 Binary files a/docs/img/vscode-pdf-next.jpg and /dev/null differ diff --git a/docs/index.html b/docs/index.html index 9ffdef3..e23609e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,79 +1,191 @@ - - - - -machine-made - - - - - - - - - - - - - - - - - - -
    - -

    -
    -
    -
    -

    A home-built, asynchronous factory for scientific software.

    -

    In 1804 the Jacquard loom wove patterns read from punched cards. The pattern came from a person; the cloth came from the machine. The name and the mark come from those cards.

    -
    -
    -

    Type

    -
      -
    • Weft, Sans, Heddle and Warp, typefaces made by code site
    • -
    -
    -
    -

    Science and numerics

    -
      -
    • CERN ROOT Minuit2 in Rust
    • -
    • LIBSVM in Rust
    • -
    • LIBLINEAR in Rust
    • -
    • Barnes-Hut N-body simulation
    • -
    • small language models trained in Rust
    • -
    -
    -
    -

    Tools for agents

    -
      -
    • a research library agents search over MCP
    • -
    • a todo list for people and agents
    • -
    • Fortran for Claude
    • -
    • thinking effort for Pi
    • -
    • hand work to a fresh Pi session
    • -
    • LaTeX and Markdown as spoken words
    • -
    -
    -
    -

    Desktop

    -
      -
    • a PDF viewer that reloads when the file changes
    • -
    • PDF viewing in VS Code
    • -
    • branch and workspace diffs in VS Code
    • -
    -
    -
    - - - +machine-made +

    machine-made

    A home-built, asynchronous factory for scientific software.

    Latest

    1. type

      warp-v0.2.0

    2. liblinear-rs

      v0.0.1

    3. pdf-next

      v0.19.0

    Type

    • Weft, Sans, Heddle and Warp, typefaces made by code site

      Pythonwarp-v0.2.0

    Science and numerics

    • CERN ROOT Minuit2 in Rust

      Rustv0.5.5

    • LIBSVM in Rust

      Rustv0.9.2

    • LIBLINEAR in Rust

      Rustv0.0.1

    • Barnes-Hut N-body simulation

      Rustunreleased

    • small language models trained in Rust

      Rustunreleased

    Tools for agents

    • a research library agents search over MCP

      Pythonunreleased

    • a todo list for people and agents

      HTMLv1.4.0

    • Fortran for Claude

      Pythonunreleased

    • thinking effort for Pi

      TypeScriptv0.1.0

    • hand work to a fresh Pi session

      TypeScriptunreleased

    • LaTeX and Markdown as spoken words

      Rustv0.0.1

    Desktop

    • a PDF viewer that reloads when the file changes

      JavaScriptv0.19.0

    • PDF viewing in VS Code

      JavaScriptv2.6.0

    • branch and workspace diffs in VS Code

      TypeScriptv0.10.1

    The houses

    • Open tools for fluid flows: state-of-the-art methods, ultra-modern low-memory code, for humans and agents.

      dynachaos v0.4.2

    • Boring on purpose. Deterministic infrastructure for non-deterministic systems.

      nanobook v0.19.3

    • Four typefaces, made by code.

      Warp v0.2.0

    diff --git a/docs/llms.txt b/docs/llms.txt index 824ee07..c087306 100644 --- a/docs/llms.txt +++ b/docs/llms.txt @@ -2,8 +2,6 @@ > A home-built, asynchronous factory for scientific software. -In 1804 the Jacquard loom wove patterns read from punched cards. The pattern came from a person; the cloth came from the machine. The name and the mark come from those cards. - ## Type - [type](https://github.com/machine-made/type): Weft, Sans, Heddle and Warp, typefaces made by code ([site](https://machine-made.github.io/type/)) diff --git a/docs/og.jpg b/docs/og.jpg new file mode 100644 index 0000000..3bf44f0 Binary files /dev/null and b/docs/og.jpg differ diff --git a/docs/style.css b/docs/style.css deleted file mode 100644 index ff8c2c6..0000000 --- a/docs/style.css +++ /dev/null @@ -1,290 +0,0 @@ -@font-face{font-family:"machine-made Weft";src:url(fonts/mm-weft.woff2) format("woff2");font-weight:100 900;font-style:normal;font-display:swap} -:root{--bg:#0a0a0b;--fg:#ecebe6;--muted:#8b8b90;--accent:#e5251c;--edge:#222223;--font:"machine-made Weft", ui-monospace, monospace;--mono:"machine-made Weft", ui-monospace, monospace;--ws:normal;--fs:1rem;--ls:1.5rem;} -/* The colours, the fonts and the sizes of a house come first (:root). */ - -:root { - --gutter: 16px; - --max: 1200px; -} - -@media (min-width: 720px) { - :root { - --gutter: 24px; - } -} - -@media (min-width: 1100px) { - :root { - --gutter: 32px; - } -} - -*, -*::before, -*::after { - box-sizing: border-box; -} - -html { - color-scheme: dark; - -webkit-text-size-adjust: 100%; - text-size-adjust: 100%; -} - -body { - margin: 0; - min-height: 100vh; - padding-block: 14px 22px; - background: var(--bg); - color: var(--fg); - font: 400 var(--fs) / 1.55 var(--font); - -webkit-font-smoothing: antialiased; -} - -h1, -h2, -p, -ul { - margin: 0; -} - -ul { - padding: 0; - list-style: none; -} - -img { - display: block; - max-width: 100%; - height: auto; -} - -a { - color: inherit; - text-decoration: none; -} - -a:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 3px; - border-radius: 2px; -} - -.skip { - position: absolute; - top: -5rem; - left: var(--gutter); - z-index: 10; - padding: 8px 16px; - background: var(--fg); - color: var(--bg); - font-family: var(--mono); - font-size: 0.75rem; -} - -.skip:focus { - top: 8px; -} - -.wrap { - width: min(100% - 2 * var(--gutter), var(--max)); - margin-inline: auto; -} - -/* The top bar: the three sites and the type site. Weft sets it on every house. The current site is - marked and is not a link. The footer repeats the four names as links. */ -.bar { - display: flex; - flex-wrap: wrap; - gap: 0 16px; - margin-bottom: 14px; - font: 400 0.75rem / 1 var(--mono); - letter-spacing: 0.04em; -} - -.bar a, -.bar span { - display: inline-flex; - align-items: center; - padding-block: 6px; - color: var(--muted); - overflow-wrap: anywhere; -} - -.bar [aria-current="page"] { - color: var(--fg); - text-decoration: underline 2px var(--accent); - text-underline-offset: 6px; -} - -/* On a narrow screen every link is at least 44 px high. */ -@media (max-width: 720px) { - .bar a, - .bar span, - footer a { - min-height: 44px; - } -} - -/* The banner is the image of the GitHub profile. Its top and bottom edges fade into the ground. */ -.banner { - display: block; - width: 100%; - aspect-ratio: 1408 / 469; - object-fit: cover; - mask-image: linear-gradient(transparent, #000 10%, #000 90%, transparent); -} - -.duo { - display: grid; - grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); - gap: 20px; - align-items: end; - margin-top: 20px; -} - -.line { - font-size: var(--ls); - line-height: 1.3; - text-wrap: balance; - word-spacing: var(--ws); -} - -.blurb { - max-width: 52ch; - word-spacing: var(--ws); - font-size: calc(var(--fs) * 0.88); - color: var(--muted); -} - -@media (max-width: 520px) { - .duo { - grid-template-columns: 1fr; - } -} - -/* A small group label, set in Weft with a square of the accent colour. */ -.lbl { - display: flex; - align-items: center; - gap: 8px; - margin: 32px 0 10px; - font: 400 0.71875rem / 1 var(--mono); - letter-spacing: 0.08em; - text-transform: uppercase; - color: var(--muted); -} - -.lbl::before { - content: ""; - width: 6px; - height: 6px; - background: var(--accent); -} - -.grid { - display: grid; - grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); - gap: 14px 12px; -} - -.plate { - display: grid; - align-content: start; - gap: 4px; - min-width: 0; -} - -.pic { - display: block; - overflow: hidden; -} - -.plate img { - display: block; - width: 100%; - aspect-ratio: 3 / 1; - object-fit: cover; - outline: 1px solid var(--edge); - outline-offset: -1px; - border-radius: 2px; -} - -.plate .ds { - word-spacing: var(--ws); - font-size: calc(var(--fs) * 0.8); - color: var(--muted); - line-height: 1.35; - overflow-wrap: anywhere; -} - -/* The small link after a description: always underlined, so a touch screen shows it too. */ -.ds a { - color: var(--fg); - text-decoration: underline 1px var(--accent); - text-underline-offset: 0.2em; -} - -@media (max-width: 720px) { - .ds a { - display: flex; - align-items: center; - width: fit-content; - min-height: 44px; - } -} - -footer { - margin-top: 40px; - font: 400 0.71875rem / 1 var(--mono); - letter-spacing: 0.04em; - color: var(--muted); -} - -/* The footer line: the four links, set like the top bar. Each link but the last draws a dot after its name, - so a dot stays on the line of the name it follows. */ -footer p { - display: flex; - flex-wrap: wrap; - align-items: center; - gap: 0 0.5em; -} - -footer a { - display: inline-flex; - align-items: center; - gap: 0.5em; - padding-block: 6px; -} - -footer a:not(:last-child)::after { - content: ""; - width: 3px; - height: 3px; - background: var(--muted); - border-radius: 50%; -} - -/* Hover effects only for pointers that hover. Motion only when the reader has not asked for less. */ -@media (hover: hover) { - .pic:hover img { - outline-color: var(--accent); - } - - .ds a:hover { - text-decoration-thickness: 2px; - } -} - -@media (prefers-reduced-motion: no-preference) { - a, - img { - transition: color 0.2s ease, transform 0.2s ease; - } -} - -@media (hover: hover) and (prefers-reduced-motion: no-preference) { - .pic:hover img { - transform: scale(1.02); - } -} diff --git a/fetch.py b/fetch.py new file mode 100644 index 0000000..b88826c --- /dev/null +++ b/fetch.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 +"""Fetch the live GitHub facts of the three house sites into one data file. Standard library and gh only. + +Usage: python3 fetch.py OUT.json + +Reads the projects of site.json and houses/*/site.json, asks the GitHub API (GraphQL through gh: one call, +then one more per further page of type releases) for each repository's language, latest release, recent +releases and last commit on the default branch, and for the newest release of each machine-made type family. Any failed call, error or missing answer stops with +exit 1 and writes nothing, so a stale page cannot ship. build.py reads OUT.json. +""" + +import datetime +import json +import subprocess +import sys +from pathlib import Path +from typing import Any, NoReturn, TypedDict + +ROOT = Path(__file__).resolve().parent +# Never listed on any site. +NEVER = {"homebrew-tap"} +FAMILIES = ("weft", "sans", "heddle", "warp") + + +class Release(TypedDict): + tagName: str + publishedAt: str + url: str + + +class RepoFacts(TypedDict): + lang: str | None + release: Release | None + commit: str + releases: list[Release] + + +class Facts(TypedDict): + fetched: str + repos: dict[str, RepoFacts] + families: dict[str, Release] + + +def release(node: dict[str, Any]) -> Release: + """The three fields a page uses, each checked to be a string.""" + if not all(isinstance(node.get(k), str) for k in ("tagName", "publishedAt", "url")): + die(f"a release lacks its tag, date or url: {json.dumps(node)[:200]}") + return {"tagName": node["tagName"], "publishedAt": node["publishedAt"], "url": node["url"]} + + +def die(message: str) -> NoReturn: + print(json.dumps({"error": message, "fix": "Check gh auth status and the network, then run again."}), file=sys.stderr) + sys.exit(1) + + +def site_files() -> list[Path]: + return [ROOT / "site.json", *sorted((ROOT / "houses").glob("*/site.json"))] + + +def repositories() -> list[tuple[str, str]]: + """Every (owner, repo) that a house lists, in a stable order.""" + found: set[tuple[str, str]] = set() + for path in site_files(): + site = json.loads(path.read_text(encoding="utf-8")) + for group in site["groups"]: + for item in group["projects"]: + found.add((item.get("owner", site["owner"]), item["repo"])) + return sorted(found) + + +def gh_graphql(query: str) -> dict[str, Any]: + done = subprocess.run(["gh", "api", "graphql", "-f", f"query={query}"], capture_output=True, text=True, check=False) + if done.returncode != 0: + die(f"gh api graphql failed: {done.stderr.strip()[:300]}") + try: + answer = json.loads(done.stdout) + except ValueError: + die("gh api graphql did not return JSON") + if answer.get("errors"): + die("graphql errors: " + json.dumps(answer["errors"])[:300]) + return answer["data"] + + +RELEASE = "tagName publishedAt url isPrerelease isDraft" +TYPE_RELEASES = ( + 'releases(first:100{after}, orderBy:{{field:CREATED_AT, direction:DESC}})' + "{{pageInfo{{hasNextPage endCursor}} nodes{{" + RELEASE + "}}}}" +) +FIELDS = """primaryLanguage{name} + latestRelease{tagName publishedAt url} + defaultBranchRef{target{... on Commit{committedDate}}} + releases(first:10, orderBy:{field:CREATED_AT, direction:DESC}){nodes{tagName publishedAt url isPrerelease isDraft}}""" + + +def main() -> None: + if len(sys.argv) != 2: + print("usage: python3 fetch.py OUT.json", file=sys.stderr) + sys.exit(2) + out = Path(sys.argv[1]) + repos = repositories() + if any(name in NEVER for _, name in repos): + die("a house lists homebrew-tap, which is never listed") + parts = [f'r{i}: repository(owner:"{o}", name:"{n}"){{ {FIELDS} }}' for i, (o, n) in enumerate(repos)] + parts.append('typerepo: repository(owner:"machine-made", name:"type"){ ' + TYPE_RELEASES.format(after="") + " }") + data = gh_graphql("query{" + "\n".join(parts) + "}") + result: Facts = {"fetched": datetime.datetime.now(datetime.UTC).date().isoformat(), "repos": {}, "families": {}} + for i, (owner, name) in enumerate(repos): + node = data.get(f"r{i}") + if not node or not node.get("defaultBranchRef"): + die(f"no data for {owner}/{name}") + releases = [r for r in node["releases"]["nodes"] if not r["isDraft"] and not r["isPrerelease"] and r["publishedAt"]] + latest = node["latestRelease"] + # The ten newest releases may all be prereleases; the latest stable release still counts. + if latest and latest["publishedAt"] and latest["tagName"] not in {r["tagName"] for r in releases}: + releases.append(latest) + result["repos"][f"{owner}/{name}"] = { + "lang": (node["primaryLanguage"] or {}).get("name"), + "release": release(latest) if latest else None, + "commit": node["defaultBranchRef"]["target"]["committedDate"], + "releases": [release(r) for r in releases], + } + # Every page of type releases: the newest publication of each family wins, whatever the creation order. + page = (data.get("typerepo") or {}).get("releases") or {} + nodes = list(page.get("nodes", [])) + while (page.get("pageInfo") or {}).get("hasNextPage"): + after = ', after:"' + page["pageInfo"]["endCursor"] + '"' + more = gh_graphql('query{typerepo: repository(owner:"machine-made", name:"type"){ ' + TYPE_RELEASES.format(after=after) + " }}") + page = (more.get("typerepo") or {}).get("releases") or {} + nodes += page.get("nodes", []) + for r in nodes: + family = r["tagName"].split("-v")[0] + if family not in FAMILIES or r["isDraft"] or r["isPrerelease"] or not r["publishedAt"]: + continue + if family not in result["families"] or r["publishedAt"] > result["families"][family]["publishedAt"]: + result["families"][family] = release(r) + missing = [f for f in FAMILIES if f not in result["families"]] + if missing: + die(f"no release found for the type families {', '.join(missing)}") + text = json.dumps(result, indent=1, sort_keys=True) + "\n" + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(text, encoding="utf-8") + print(json.dumps({"repos": len(result["repos"]), "families": {k: v["tagName"] for k, v in sorted(result["families"].items())}})) + + +if __name__ == "__main__": + main() diff --git a/fonts/SOURCES.json b/fonts/SOURCES.json new file mode 100644 index 0000000..2e17ef3 --- /dev/null +++ b/fonts/SOURCES.json @@ -0,0 +1,9 @@ +{ + "note": "The source font files of the house sites: the release files of machine-made/type, unchanged. build.py cuts a subset of each for each page; check_site.py checks every hash here.", + "fonts": { + "mm-weft.woff2": {"family": "machine-made Weft", "version": "0.2.0", "release": "weft-v0.2.0", "asset": "MachineMadeWeft.FRAG.wght.woff2", "bytes": 77208, "sha256": "9115be68c727ae8c707eed1097f878fd7e7bd54fa75bd70b099e94e4e5e71e85", "licence": "mm-weft-OFL.txt"}, + "mm-sans.woff2": {"family": "machine-made Sans", "version": "0.2.0", "release": "sans-v0.2.0", "asset": "MachineMadeSans.wght.woff2", "bytes": 73236, "sha256": "8ec52cf1b8a799dcda3aab4cf967d681cbd8bffd3f4cb581ed4e5ffa72e0864e", "licence": "mm-sans-OFL.txt"}, + "mm-heddle.woff2": {"family": "machine-made Heddle", "version": "0.2.0", "release": "heddle-v0.2.0", "asset": "MachineMadeHeddle.wdth.wght.woff2", "bytes": 77600, "sha256": "3f7d0bde0d436dc800abc9b9c760938f38f19c627cc3378bb199032c3a6ec0e1", "licence": "mm-heddle-OFL.txt"}, + "mm-warp-regular.woff2": {"family": "machine-made Warp", "version": "0.2.0", "release": "warp-v0.2.0", "asset": "MachineMadeWarp-Regular.woff2", "bytes": 82732, "sha256": "035042b467e6c138666b2e6b3b3a38eeb8d6dc3602ac4354f1e335e425101481", "licence": "mm-warp-OFL.txt"} + } +} diff --git a/fonts/mm-heddle-OFL.txt b/fonts/mm-heddle-OFL.txt new file mode 100644 index 0000000..7511f4b --- /dev/null +++ b/fonts/mm-heddle-OFL.txt @@ -0,0 +1,94 @@ +Copyright 2026 The machine-made Heddle Project Authors (https://github.com/machine-made/type), +with Reserved Font Name "machine-made". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/fonts/mm-heddle.woff2 b/fonts/mm-heddle.woff2 new file mode 100644 index 0000000..0a0a357 Binary files /dev/null and b/fonts/mm-heddle.woff2 differ diff --git a/fonts/mm-warp-italic.woff2 b/fonts/mm-warp-italic.woff2 deleted file mode 100644 index de5ab8f..0000000 Binary files a/fonts/mm-warp-italic.woff2 and /dev/null differ diff --git a/gate.sh b/gate.sh index a51c1b2..c14b6bf 100755 --- a/gate.sh +++ b/gate.sh @@ -1,18 +1,27 @@ #!/bin/sh -# The gate: deterministic build, self-tests, site checks, forbidden words. -# Prints DETERMINISTIC, SELF-TEST OK, OK and "grep clean"; any failure exits 1. +# The gate: one GitHub fetch, then for every house a deterministic build from that fetch, the self-tests, the site +# checks, the browser checks and the forbidden words. +# Prints FETCHED, DETERMINISTIC, SELF-TEST OK, OK, HOUSES OK, SHOTS OK and "grep clean"; any failure exits 1. +# Needs gh (signed in), uv and Chrome or Chromium. MM_CHROME=PATH names the browser for shots.py when Playwright has +# none of its own; MM_AXE=FILE (axe.min.js of axe-core) also runs axe on every page and fails on a violation. +# MM_SHOTS=0 skips the browser checks and prints SHOTS SKIPPED. # MM_DENY_FILE=FILE (outside this repository) also rejects the names listed in FILE. # MM_FONTS=DIR (the fonts brand.py draws from, brand-fonts/ in this repository; needs Playwright, fontTools and brotli) -# also builds brand/ twice, compares the hashes and compares the result with the brand/ in this -# repository. +# also builds brand/ twice, compares the hashes and compares the result with the brand/ in this repository. set -eu cd "$(dirname "$0")" export PYTHONDONTWRITEBYTECODE=1 -first=$(mktemp "${TMPDIR:-/tmp}/mm-gate.XXXXXX") -second=$(mktemp "${TMPDIR:-/tmp}/mm-gate.XXXXXX") -brand_one=$(mktemp -d "${TMPDIR:-/tmp}/mm-gate.XXXXXX") -brand_two=$(mktemp -d "${TMPDIR:-/tmp}/mm-gate.XXXXXX") -trap 'rm -rf "$first" "$second" "$brand_one" "$brand_two"' EXIT +# The build cuts fonts (fontTools, brotli) and encodes images (Pillow); the versions are pinned so that two +# machines write the same bytes. shots.py drives a browser through Playwright. +UV="uv run --quiet --with fonttools==4.68.0 --with brotli==1.2.1 --with pillow==13.0.0" +UV_SHOTS="uv run --quiet --with playwright==1.65.1" +data=$(mktemp -t mm-data.XXXXXX) +first=$(mktemp -t mm-gate.XXXXXX) +second=$(mktemp -t mm-gate.XXXXXX) +brand_one=$(mktemp -d -t mm-gate.XXXXXX) +brand_two=$(mktemp -d -t mm-gate.XXXXXX) +shots=$(mktemp -d -t mm-shots.XXXXXX) +trap 'rm -rf "$data" "$first" "$second" "$brand_one" "$brand_two" "$shots"' EXIT hashes() { python3 - "$1" <<'PY' import hashlib @@ -25,9 +34,24 @@ for path in sorted(root.rglob("*")): print(hashlib.sha256(path.read_bytes()).hexdigest(), path.relative_to(root).as_posix()) PY } -python3 build.py > /dev/null +browser() { + # $1: the folder that holds site.json and docs/; $2: the folder for the shots + if [ "${MM_SHOTS:-1}" = 0 ]; then + return 0 + fi + set -- "$1" "$2" + if [ -n "${MM_CHROME:-}" ]; then set -- "$@" --chrome "$MM_CHROME"; fi + if [ -n "${MM_AXE:-}" ]; then set -- "$@" --axe "$MM_AXE"; fi + site=$1 out=$2 + shift 2 + $UV_SHOTS python3 shots.py --site "$site" --out "$out" "$@" +} +# One fetch for the whole gate: both builds of every house read the same facts, so the comparison means something. +python3 fetch.py "$data" > /dev/null +echo FETCHED +$UV python3 build.py --data "$data" > /dev/null hashes docs > "$first" -python3 build.py > /dev/null +$UV python3 build.py --data "$data" > /dev/null hashes docs > "$second" if ! cmp -s "$first" "$second"; then echo "the two builds differ" @@ -53,34 +77,43 @@ if [ -n "${MM_FONTS:-}" ]; then else echo "BRAND SKIPPED: set MM_FONTS=brand-fonts to check brand/" fi -python3 check_site.py --self-test +$UV python3 check_site.py --data "$data" --self-test if [ -n "${MM_DENY_FILE:-}" ]; then - python3 check_site.py --deny "$MM_DENY_FILE" + $UV python3 check_site.py --data "$data" --deny "$MM_DENY_FILE" else - python3 check_site.py + $UV python3 check_site.py --data "$data" fi +browser . "$shots/machine-made" # Every house in houses/ builds from this generator: twice, the same, then its own checks. for house in houses/*/; do - copy=$(mktemp -d "${TMPDIR:-/tmp}/mm-house.XXXXXX") + copy=$(mktemp -d -t mm-house.XXXXXX) cp "$house/site.json" "$house/allow.json" "$copy/" - python3 build.py --site "$copy" > /dev/null + $UV python3 build.py --site "$copy" --data "$data" > /dev/null hashes "$copy/docs" > "$first" - python3 build.py --site "$copy" > /dev/null + $UV python3 build.py --site "$copy" --data "$data" > /dev/null hashes "$copy/docs" > "$second" if ! cmp -s "$first" "$second"; then echo "the two builds of $house differ" rm -rf "$copy" exit 1 fi - if ! python3 check_site.py --site "$copy"; then + if ! $UV python3 check_site.py --site "$copy" --data "$data"; then echo "the house site $house fails its checks" rm -rf "$copy" exit 1 fi + if ! browser "$copy" "$shots/$(basename "$house")"; then + echo "the house site $house fails its browser checks" + rm -rf "$copy" + exit 1 + fi rm -rf "$copy" done echo "HOUSES OK" -# -I skips the font files: binary data is not copy. check_site.py reads the licences. +if [ "${MM_SHOTS:-1}" = 0 ]; then + echo "SHOTS SKIPPED: the browser checks did not run" +fi +# -I skips the font and image files: binary data is not copy. check_site.py reads the licences. if grep -rniIE '\$[0-9]|tokens' docs/; then echo "grep found a forbidden word" exit 1 diff --git a/houses/boringquantsystems/allow.json b/houses/boringquantsystems/allow.json index 111ab90..f0cc4bd 100644 --- a/houses/boringquantsystems/allow.json +++ b/houses/boringquantsystems/allow.json @@ -2,13 +2,14 @@ "owner": "BoringQuantSystems", "self": "BoringQuantSystems", "line": "Boring on purpose. Deterministic infrastructure for non-deterministic systems.", - "blurb": "The best systems are the ones nobody talks about. BoringQuantSystems aims to be one of them.", "theme": { "ground": "#050507", + "surface": "#0e0e11", + "line": "#1f1f23", "text": "#ecebe6", "muted": "#8b8b90", "accent": "#3ddc97", - "font": "machine-made Warp" + "face": "warp" }, "sites": [ [ diff --git a/houses/boringquantsystems/site.json b/houses/boringquantsystems/site.json index 4a8c7a6..ceb8eee 100644 --- a/houses/boringquantsystems/site.json +++ b/houses/boringquantsystems/site.json @@ -3,13 +3,14 @@ "title": "BoringQuantSystems", "owner": "BoringQuantSystems", "line": "Boring on purpose. Deterministic infrastructure for non-deterministic systems.", - "blurb": "The best systems are the ones nobody talks about. BoringQuantSystems aims to be one of them.", "theme": { "ground": "#050507", + "surface": "#0e0e11", + "line": "#1f1f23", "text": "#ecebe6", "muted": "#8b8b90", "accent": "#3ddc97", - "font": "machine-made Warp" + "face": "warp" }, "nav": [ { @@ -33,6 +34,7 @@ "groups": [ { "title": "Engines", + "nav": "Engines", "projects": [ { "repo": "nanobook", diff --git a/houses/openfluids/allow.json b/houses/openfluids/allow.json index 8d48ff4..e5850f5 100644 --- a/houses/openfluids/allow.json +++ b/houses/openfluids/allow.json @@ -2,13 +2,14 @@ "owner": "openfluids", "self": "openfluids", "line": "Open tools for fluid flows: state-of-the-art methods, ultra-modern low-memory code, for humans and agents.", - "blurb": "Open code for fluid mechanics.", "theme": { "ground": "#0d1116", + "surface": "#141a21", + "line": "#252c33", "text": "#e6eef2", "muted": "#8395a0", "accent": "#5cc8d6", - "font": "machine-made Sans" + "face": "heddle" }, "sites": [ [ diff --git a/houses/openfluids/site.json b/houses/openfluids/site.json index 3f3e0d1..cd31791 100644 --- a/houses/openfluids/site.json +++ b/houses/openfluids/site.json @@ -2,13 +2,14 @@ "name": "openfluids", "owner": "openfluids", "line": "Open tools for fluid flows: state-of-the-art methods, ultra-modern low-memory code, for humans and agents.", - "blurb": "Open code for fluid mechanics.", "theme": { "ground": "#0d1116", + "surface": "#141a21", + "line": "#252c33", "text": "#e6eef2", "muted": "#8395a0", "accent": "#5cc8d6", - "font": "machine-made Sans" + "face": "heddle" }, "nav": [ { @@ -32,6 +33,7 @@ "groups": [ { "title": "Stability", + "nav": "Stability", "projects": [ { "repo": "linstabpy", @@ -48,6 +50,7 @@ }, { "title": "Analysis", + "nav": "Analysis", "projects": [ { "repo": "openmodalpy", @@ -75,6 +78,7 @@ }, { "title": "Solvers", + "nav": "Solvers", "projects": [ { "repo": "dolfinx-rans", @@ -84,6 +88,7 @@ }, { "title": "Runs", + "nav": "Runs", "projects": [ { "repo": "hpckit", diff --git a/img/org/boringquantsystems-avatar.png b/img/org/boringquantsystems-avatar.png new file mode 100644 index 0000000..8bf335b Binary files /dev/null and b/img/org/boringquantsystems-avatar.png differ diff --git a/img/org/openfluids-avatar.png b/img/org/openfluids-avatar.png new file mode 100644 index 0000000..8eb315c Binary files /dev/null and b/img/org/openfluids-avatar.png differ diff --git a/publish.sh b/publish.sh index 714b003..aceb1a5 100644 --- a/publish.sh +++ b/publish.sh @@ -1,24 +1,33 @@ #!/bin/sh # Build one house site from this generator into the docs/ of its own Pages repository. -# Usage: sh publish.sh HOUSE PAGES_REPO_DIR (HOUSE is a folder name in houses/) -# Run gate.sh first. Commit and push in the Pages repository through a pull request. +# Usage: sh publish.sh HOUSE PAGES_REPO_DIR [FACTS.json] (HOUSE is a folder name in houses/) +# FACTS.json is the file fetch.py wrote; without it, publish.sh fetches once. Use the same file for every house of +# one change, so the houses show the same facts. Run gate.sh first. Commit and push in the Pages repository through +# a pull request. set -eu house=${1:?name a house in houses/} target=${2:?name the Pages repository folder} -# Resolve the target before moving into the generator, so a relative path means the caller's folder. +# Resolve the paths before moving into the generator, so a relative path means the caller's folder. target=$(cd "$target" && pwd) +facts=${3:-} +if [ -n "$facts" ]; then facts=$(cd "$(dirname "$facts")" && pwd)/$(basename "$facts"); fi cd "$(dirname "$0")" +UV="uv run --quiet --with fonttools==4.68.0 --with brotli==1.2.1 --with pillow==13.0.0" if [ "$target" = "$(pwd)" ]; then echo "the target is this generator repository; name the house's own Pages repository" exit 2 fi [ -f "houses/$house/site.json" ] || { echo "houses/$house/site.json is missing"; exit 2; } [ -d "$target/.git" ] || { echo "$target is not a git repository"; exit 2; } -work=$(mktemp -d "${TMPDIR:-/tmp}/mm-publish.XXXXXX") +work=$(mktemp -d -t mm-publish.XXXXXX) trap 'rm -rf "$work"' EXIT +if [ -z "$facts" ]; then + facts="$work/facts.json" + python3 fetch.py "$facts" > /dev/null +fi cp "houses/$house/site.json" "houses/$house/allow.json" "$work/" -python3 build.py --site "$work" > /dev/null -python3 check_site.py --site "$work" +$UV python3 build.py --site "$work" --data "$facts" > /dev/null +$UV python3 check_site.py --site "$work" --data "$facts" rm -rf "$target/docs" cp -R "$work/docs" "$target/docs" echo "built houses/$house into $target/docs" diff --git a/shots.py b/shots.py index 75200ab..0254903 100644 --- a/shots.py +++ b/shots.py @@ -1,35 +1,50 @@ #!/usr/bin/env python3 -"""Screenshots of a house site, and the layout checks. Needs Playwright; build.py and check_site.py do not. +"""Screenshots of a house site, and the checks that need a browser. Needs Playwright; build.py does not. + + uv run --with playwright==1.65.1 python3 shots.py [--site DIR] [--out DIR] [--chrome PATH] [--axe FILE] -Usage: python3 shots.py [--site DIR] [--out DIR] [--chrome PATH] --site the folder that holds docs/ (default: this repository) ---out where the PNG files go (390 and 1280 px); default ./shots/ in this repository (git ignores it) +--out where the PNG files and report.json go; default ./shots/ in this repository (git ignores it) --chrome a Chrome or Chromium binary, when Playwright has no browser of its own +--axe axe.min.js of axe-core; with it, axe runs on the home page and the 404 page and every violation fails + +The site is served over HTTP the way GitHub Pages serves it: a missing path gets 404.html with status 404. -The scroll check runs at 320, 360, 390, 720, 1000, 1280 and 1920 px. The same run checks that every -font face the page uses loaded, that all text is a machine-made font at weight 400 and normal style (no -faux bold or italic), that no image failed to load and every image has width and height, that no line of -copy has 70 characters or more, that the page asks for no file outside docs/, that the plate images are -equal in height with equal gaps, that exactly one entry of the top bar is marked and is not a link, and -that the screenshots have the width asked for. At 390 px it also checks the 16 px side margin and that -every link is at least 44 px high. +At 320, 360, 390, 720, 1000, 1280 and 1920 px the run checks: no sideways scroll and no element past the right edge +outside a scrolling or clipping box; every font face the page uses loaded, all text in a machine-made font at weight +400 and normal style (no faux bold or italic); no image failed to load and every image has width and height; no line +of reading text has 70 characters or more; the page asks for no file outside the site; in each plate grid the images +are equal in height with equal gaps; exactly one entry of bar 1 is marked and it is not a link; one h1 and no skipped +heading level; Latest names no repository twice. At 1280 and 1920 px no facts line wraps. At 390 px the side margins +are 16 px and every link is at least 44 px high. At 390 and 1280 px, on the home page and the 404 page, no glyph is +drawn in a system font (Chrome's platform-fonts query). The 404 page is loaded at a nested missing path and must load +its fonts and images. Shots: home and 404 at 390 and 1280 px, full page. """ import argparse +import functools +import http.server import json import sys +import threading from itertools import pairwise from pathlib import Path +from typing import Any -from playwright.sync_api import sync_playwright +from playwright.sync_api import BrowserContext, Page, sync_playwright ROOT = Path(__file__).resolve().parent FIT_WIDTHS = (320, 360, 390, 720, 1000, 1280, 1920) SHOT_WIDTHS = (390, 1280) HEIGHT = 900 MAX_LINE = 70 +FAMILIES = {"weft": "mm Weft", "sans": "mm Sans", "heddle": "mm Heddle", "warp": "mm Warp"} FONTS_LOADED = "() => [...document.fonts].map(f => [f.family.replace(/^[\"']|[\"']$/g, ''), f.style, f.status])" IMAGES_LOADED = "() => [...document.images].every(i => i.complete && i.naturalWidth > 0)" +SCROLL_ALL = """async () => { + for (let y = 0; y < document.body.scrollHeight; y += innerHeight / 2) { scrollTo(0, y); await new Promise(r => setTimeout(r, 80)); } + scrollTo(0, 0); +}""" LONGEST_LINE = """() => { let longest = 0; for (const p of document.querySelectorAll("main p, main .ds, footer p")) { @@ -50,8 +65,6 @@ } return longest; }""" - - # Every element that holds text: its computed family, weight and style. TEXT_FACES = """() => { const out = []; @@ -65,119 +78,247 @@ } return out; }""" -# The geometry of the page: images, plates, links, the top bar and the side margins. +# The geometry of the page: images per plate grid, links, bar 1, the side margins, elements past the right edge. GEOMETRY = """() => { const rect = (e) => { const r = e.getBoundingClientRect(); return [r.left, r.top, r.width, r.height]; }; - const plates = [...document.querySelectorAll(".plate img")].map(rect); - const links = [...document.querySelectorAll("a:not(.skip)")].map((a) => [a.textContent.trim().slice(0, 20), a.getBoundingClientRect().height]); - const wrap = document.querySelector("main").getBoundingClientRect(); + const grids = [...document.querySelectorAll("ul.grid")].map((g) => [...g.querySelectorAll(".plate img")].map(rect)); + const links = [...document.querySelectorAll("a:not(.skip)")].map((a) => [a.textContent.trim().slice(0, 20) || a.getAttribute("aria-label"), a.getBoundingClientRect().height]); + const wrap = document.querySelector("main > *").getBoundingClientRect(); + const width = document.documentElement.clientWidth; + const contained = (e) => { for (let p = e.parentElement; p; p = p.parentElement) { const o = getComputedStyle(p).overflowX; if (o !== "visible") return true; } return false; }; + const past = [...document.body.querySelectorAll("*")].filter((e) => !e.closest(".skip, .vh") && e.getBoundingClientRect().right > width + 0.5 && !contained(e)).map((e) => e.tagName + "." + e.className); return { - plates, links, left: wrap.left, right: document.documentElement.clientWidth - wrap.right, + grids, links, left: wrap.left, right: width - wrap.right, past, unsized: [...document.images].filter((i) => !i.getAttribute("width") || !i.getAttribute("height")).length, - current: [...document.querySelectorAll(".bar [aria-current]")].map((e) => e.tagName), - barLinks: document.querySelectorAll(".bar a").length, + current: [...document.querySelectorAll(".b1 [aria-current]")].map((e) => e.tagName), + barLinks: document.querySelectorAll(".b1 a").length, }; }""" +PROBE = """() => { + const levels = [...document.querySelectorAll("h1, h2, h3, h4, h5, h6")].map((h) => +h.tagName[1]); + const lines = (el) => { const r = document.createRange(); r.selectNodeContents(el); return new Set([...r.getClientRects()].filter((x) => x.width > 0).map((x) => Math.round(x.top))).size; }; + const wrapped = [...document.querySelectorAll(".facts")].filter((el) => lines(el) > 1).map((el) => el.textContent.trim()); + const latest = [...document.querySelectorAll(".latest li > a")].map((a) => a.textContent.trim()); + return {levels, wrapped, latest, facts: document.querySelectorAll("main .grid:not(.g3) .plate .facts").length, plates: document.querySelectorAll("main .grid:not(.g3) .plate").length}; +}""" +BYTES = """() => { + const out = {font: 0, image: 0}; + performance.getEntriesByType("resource").forEach((e) => { + const n = e.name.split("?")[0]; + const b = e.encodedBodySize || e.transferSize || 0; + if (/\\.woff2$/.test(n)) out.font += b; + else if (/\\.(avif|webp|jpe?g|png|svg)$/.test(n)) out.image += b; + }); + return out; +}""" -def plate_problems(plates: list[list[float]]) -> list[str]: - """Equal heights, and equal horizontal gaps inside every row and from row to row.""" +class Pages(http.server.SimpleHTTPRequestHandler): + """GitHub Pages: a missing path gets 404.html with status 404.""" + + def log_message(self, *args: object) -> None: + pass + + def send_error(self, code: int, message: str | None = None, explain: str | None = None) -> None: + page = Path(self.directory) / "404.html" + if code != 404 or not page.is_file(): + super().send_error(code, message, explain) + return + body = page.read_bytes() + self.send_response(404) + self.send_header("Content-Type", "text/html; charset=utf-8") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + +def serve(docs: Path) -> tuple[http.server.ThreadingHTTPServer, str]: + server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), functools.partial(Pages, directory=str(docs))) + threading.Thread(target=server.serve_forever, daemon=True).start() + return server, f"http://127.0.0.1:{server.server_address[1]}/" + + +def plate_problems(grids: list[list[list[float]]]) -> list[str]: + """In each plate grid: equal image heights, and equal horizontal gaps inside every row.""" problems = [] - heights = {round(h, 1) for _, _, _, h in plates} - if len(heights) > 1: - problems.append(f"plate images differ in height: {sorted(heights)}") - gaps = set() - rows: dict[int, list[list[float]]] = {} - for plate in plates: - rows.setdefault(round(plate[1]), []).append(plate) - for row in rows.values(): - row.sort() - gaps |= {round(b[0] - (a[0] + a[2]), 1) for a, b in pairwise(row)} - if len(gaps) > 1: - problems.append(f"gaps between plate images differ: {sorted(gaps)}") + for grid in grids: + heights = {round(h, 1) for _, _, _, h in grid} + if len(heights) > 1: + problems.append(f"plate images differ in height: {sorted(heights)}") + gaps = set() + rows: dict[int, list[list[float]]] = {} + for plate in grid: + rows.setdefault(round(plate[1]), []).append(plate) + for row in rows.values(): + row.sort() + gaps |= {round(b[0] - (a[0] + a[2]), 1) for a, b in pairwise(row)} + if len(gaps) > 1: + problems.append(f"gaps between plate images differ: {sorted(gaps)}") return problems -def png_width(path: Path) -> int: - return int.from_bytes(path.read_bytes()[16:20], "big") +def system_fonts(context: BrowserContext, page: Page) -> list[str]: + """Every text node drawn, even in part, in a font that is not a web font of the page.""" + cdp = context.new_cdp_session(page) + cdp.send("DOM.enable") + cdp.send("CSS.enable") + root = cdp.send("DOM.getDocument", {"depth": -1, "pierce": False})["root"] + bad: list[str] = [] + + def walk(node: dict[str, Any]) -> None: + if node.get("nodeName") in ("SCRIPT", "STYLE", "HEAD", "TITLE"): + return + kids = node.get("children", []) + if any(c.get("nodeType") == 3 and c.get("nodeValue", "").strip() for c in kids): + fonts = cdp.send("CSS.getPlatformFontsForNode", {"nodeId": node["nodeId"]})["fonts"] + text = "".join(c.get("nodeValue", "") for c in kids if c.get("nodeType") == 3).strip() + bad.extend(f'{f["familyName"]} x{f["glyphCount"]} in "{text[:30]}"' for f in fonts if not f.get("isCustomFont")) + for c in kids: + walk(c) + + walk(root) + cdp.detach() + return bad def main() -> None: - parser = argparse.ArgumentParser(description="Screenshots of docs/index.html") + parser = argparse.ArgumentParser(description="Screenshots and browser checks of docs/") parser.add_argument("--site", type=Path, default=ROOT) parser.add_argument("--out", type=Path, default=ROOT / "shots") parser.add_argument("--chrome", default=None) + parser.add_argument("--axe", type=Path, default=None) args = parser.parse_args() out = args.out out.mkdir(parents=True, exist_ok=True) - docs_dir = args.site.resolve() / "docs" - url = (docs_dir / "index.html").as_uri() - docs = docs_dir.as_uri() + "/" - theme_font = json.loads((args.site / "site.json").read_text(encoding="utf-8"))["theme"]["font"] - wanted_faces = {"machine-made Weft", theme_font} - # Every face of a family the page uses is declared; only the faces the text uses must be loaded. A face - # the page does not use (an italic that no text asks for) stays unloaded, and none may fail. - report = [] - with sync_playwright() as pw: - browser = pw.chromium.launch(executable_path=args.chrome) if args.chrome else pw.chromium.launch() - for width in FIT_WIDTHS: - ctx = browser.new_context(viewport={"width": width, "height": HEIGHT}, color_scheme="dark") - page = ctx.new_page() - outside: list[str] = [] - page.on("request", lambda req, outside=outside: req.url.startswith(docs) or outside.append(req.url)) - page.goto(url, wait_until="networkidle") - for img in page.query_selector_all("img[loading=lazy]"): - img.scroll_into_view_if_needed() - page.wait_for_load_state("networkidle") - page.evaluate("document.fonts.ready") - page.evaluate("window.scrollTo(0, 0)") - page.wait_for_timeout(300) - metrics = page.evaluate( - "({scrollWidth: document.documentElement.scrollWidth, innerWidth: window.innerWidth})" - ) - entry = {"width": width, **metrics} - entry["fits"] = metrics["scrollWidth"] <= metrics["innerWidth"] - entry["longest_line"] = page.evaluate(LONGEST_LINE) - entry["measure_ok"] = entry["longest_line"] < MAX_LINE - statuses = page.evaluate(FONTS_LOADED) - entry["fonts_ok"] = ( - all(st == "loaded" for _, style, st in statuses if style == "normal") - and all(st != "error" for _, _, st in statuses) - and wanted_faces <= {f for f, _, _ in statuses} - ) - faces = page.evaluate(TEXT_FACES) - entry["faces_bad"] = sorted({f"{tag} {fam} {w} {st}" for tag, fam, w, st in faces - if not fam.startswith("machine-made ") or w != "400" or st != "normal"}) - geometry = page.evaluate(GEOMETRY) - entry["geometry_bad"] = plate_problems(geometry["plates"]) - if geometry["unsized"]: - entry["geometry_bad"].append(f"{geometry['unsized']} images have no width and height") - if len(geometry["current"]) != 1 or geometry["current"][0] != "SPAN" or geometry["barLinks"] != 3: - entry["geometry_bad"].append("the top bar must hold one marked span and three links") - if width == 390: - if round(geometry["left"], 1) != 16 or round(geometry["right"], 1) != 16: - entry["geometry_bad"].append(f"side margins at 390 px are {geometry['left']} and {geometry['right']}, not 16") - short = [(name, round(h, 1)) for name, h in geometry["links"] if h < 44] - if short: - entry["geometry_bad"].append(f"links below 44 px high at 390 px: {short}") - entry["images_ok"] = page.evaluate(IMAGES_LOADED) - entry["outside"] = outside - if width in SHOT_WIDTHS: - path = out / f"home-{width}.png" - page.screenshot(path=str(path), full_page=True) - entry["shot"] = str(path) - entry["shot_width"] = png_width(path) - entry["shot_ok"] = entry["shot_width"] == width - report.append(entry) - ctx.close() - browser.close() - print(json.dumps(report, indent=1)) - ok = all( - r["fits"] and r["measure_ok"] and r["fonts_ok"] and r["images_ok"] and not r["outside"] and r.get("shot_ok", True) - and not r["faces_bad"] and not r["geometry_bad"] - for r in report - ) - if not ok: + docs = args.site.resolve() / "docs" + face = json.loads((args.site / "site.json").read_text(encoding="utf-8"))["theme"]["face"] + wanted = {FAMILIES["weft"], FAMILIES["sans"], FAMILIES[face]} + axe = args.axe.read_text(encoding="utf-8") if args.axe else None + # A report from an earlier run must not stand beside the shots of this one. + (out / "report.json").unlink(missing_ok=True) + server, base = serve(docs) + report: list[dict] = [] + try: + with sync_playwright() as pw: + launch = {"executable_path": args.chrome, "args": ["--no-sandbox"]} if args.chrome else {} + browser = pw.chromium.launch(**launch) + for width in FIT_WIDTHS: + ctx = browser.new_context(viewport={"width": width, "height": HEIGHT}, color_scheme="dark", device_scale_factor=1) + page = ctx.new_page() + outside: list[str] = [] + page.on("request", lambda req, outside=outside: req.url.startswith(base) or outside.append(req.url)) + page.goto(base, wait_until="networkidle") + page.evaluate("document.fonts.ready") + first = page.evaluate(BYTES) + page.evaluate(SCROLL_ALL) + page.wait_for_load_state("networkidle") + page.wait_for_timeout(300) + entry: dict = {"page": "index", "width": width} + metrics = page.evaluate("({scrollWidth: document.documentElement.scrollWidth, innerWidth: window.innerWidth})") + entry.update(metrics) + problems: list[str] = [] + if metrics["scrollWidth"] > metrics["innerWidth"]: + problems.append(f"the page scrolls sideways: {metrics['scrollWidth']} > {metrics['innerWidth']}") + entry["longest_line"] = page.evaluate(LONGEST_LINE) + if entry["longest_line"] >= MAX_LINE: + problems.append(f"a line of copy has {entry['longest_line']} characters") + statuses = page.evaluate(FONTS_LOADED) + if not (all(st == "loaded" for _, _, st in statuses) and wanted <= {f for f, _, _ in statuses}): + problems.append(f"fonts not loaded: {statuses}") + faces = page.evaluate(TEXT_FACES) + bad_faces = sorted({f"{tag} {fam} {w} {st}" for tag, fam, w, st in faces if fam not in wanted or w != "400" or st != "normal"}) + if bad_faces: + problems.append(f"text not in a machine-made face at 400 normal: {bad_faces[:4]}") + geometry = page.evaluate(GEOMETRY) + problems += plate_problems(geometry["grids"]) + if geometry["past"]: + problems.append(f"elements past the right edge: {geometry['past'][:4]}") + if geometry["unsized"]: + problems.append(f"{geometry['unsized']} images have no width and height") + if geometry["current"] != ["SPAN"] or geometry["barLinks"] != 3: + problems.append("bar 1 must hold one marked span and three links") + if width == 390: + if round(geometry["left"], 1) != 16 or round(geometry["right"], 1) != 16: + problems.append(f"side margins at 390 px are {geometry['left']} and {geometry['right']}, not 16") + short = [(name, round(h, 1)) for name, h in geometry["links"] if h < 44] + if short: + problems.append(f"links below 44 px high at 390 px: {short}") + probe = page.evaluate(PROBE) + levels = probe["levels"] + if levels.count(1) != 1 or levels[0] != 1 or any(b - a > 1 for a, b in pairwise(levels)): + problems.append(f"headings: {levels}") + if width >= 1280 and probe["wrapped"]: + problems.append(f"facts lines wrap at {width} px: {probe['wrapped']}") + if len(set(probe["latest"])) != len(probe["latest"]) or len(probe["latest"]) > 3: + problems.append(f"Latest repeats a repository: {probe['latest']}") + if probe["facts"] != probe["plates"]: + problems.append(f"{probe['plates'] - probe['facts']} plates have no facts line") + if not page.evaluate(IMAGES_LOADED): + problems.append("an image failed to load") + if outside: + problems.append(f"requests outside the site: {outside[:3]}") + if width in SHOT_WIDTHS: + shot = out / f"home-{width}.png" + page.screenshot(path=str(shot), full_page=True) + entry["shot"] = str(shot) + entry["bytes"] = {"first_view": first, "all": page.evaluate(BYTES)} + misses = system_fonts(ctx, page) + if misses: + problems.append(f"glyphs drawn in a system font: {misses[:3]}") + if width == 1280 and axe: + page.add_script_tag(content=axe) + found = page.evaluate("async () => (await axe.run(document, {resultTypes: ['violations']})).violations.map(v => [v.id, v.nodes.length])") + entry["axe"] = found + if found: + problems.append(f"axe violations: {found}") + entry["problems"] = problems + report.append(entry) + ctx.close() + # The 404 page, where GitHub Pages serves it: at any missing path. + for width in SHOT_WIDTHS: + ctx = browser.new_context(viewport={"width": width, "height": HEIGHT}, color_scheme="dark", device_scale_factor=1) + page = ctx.new_page() + failed: list[str] = [] + page.on("response", lambda r, failed=failed: r.status >= 400 and r.request.resource_type != "document" and failed.append(r.url)) + response = page.goto(base + "no/such/page", wait_until="networkidle") + page.evaluate("document.fonts.ready") + page.wait_for_timeout(300) + problems = [] + if response is None or response.status != 404: + problems.append("a missing path does not answer 404") + if failed: + problems.append(f"the 404 page fails to load {failed[:3]}") + statuses = page.evaluate(FONTS_LOADED) + if not (all(st == "loaded" for _, _, st in statuses) and wanted <= {f for f, _, _ in statuses}): + problems.append(f"404 fonts not loaded: {statuses}") + if not page.evaluate(IMAGES_LOADED): + problems.append("a 404 image failed to load") + if page.evaluate("document.documentElement.scrollWidth > window.innerWidth"): + problems.append("the 404 page scrolls sideways") + misses = system_fonts(ctx, page) + if misses: + problems.append(f"404 glyphs drawn in a system font: {misses[:3]}") + shot = out / f"404-{width}.png" + page.screenshot(path=str(shot), full_page=True) + entry = {"page": "404", "width": width, "shot": str(shot)} + if width == 1280 and axe: + page.add_script_tag(content=axe) + found = page.evaluate("async () => (await axe.run(document, {resultTypes: ['violations']})).violations.map(v => [v.id, v.nodes.length])") + entry["axe"] = found + if found: + problems.append(f"404 axe violations: {found}") + entry["problems"] = problems + report.append(entry) + ctx.close() + browser.close() + except Exception as exc: # noqa: BLE001 a failed render is a result: record it and fail + report.append({"page": "render", "width": 0, "problems": [f"a render failed: {exc.__class__.__name__}: {str(exc)[:200]}"]}) + finally: + server.shutdown() + (out / "report.json").write_text(json.dumps(report, indent=1) + "\n", encoding="utf-8") + bad = [f"{r['page']}@{r['width']}: {p}" for r in report for p in r["problems"]] + print("\n".join(bad) if bad else f"SHOTS OK ({len(report)} renders)") + if bad: sys.exit(1) diff --git a/site.json b/site.json index 1e1383c..40a3009 100644 --- a/site.json +++ b/site.json @@ -2,13 +2,14 @@ "name": "machine-made", "owner": "machine-made", "line": "A home-built, asynchronous factory for scientific software.", - "blurb": "In 1804 the Jacquard loom wove patterns read from punched cards. The pattern came from a person; the cloth came from the machine. The name and the mark come from those cards.", "theme": { "ground": "#0a0a0b", + "surface": "#141416", + "line": "#26262a", "text": "#ecebe6", "muted": "#8b8b90", "accent": "#e5251c", - "font": "machine-made Weft" + "face": "weft" }, "nav": [ { @@ -32,6 +33,7 @@ "groups": [ { "title": "Type", + "nav": "Type", "projects": [ { "repo": "type", @@ -42,6 +44,7 @@ }, { "title": "Science and numerics", + "nav": "Science", "projects": [ { "repo": "minuit2-rs", @@ -67,6 +70,7 @@ }, { "title": "Tools for agents", + "nav": "Agents", "projects": [ { "repo": "alexandria", @@ -96,6 +100,7 @@ }, { "title": "Desktop", + "nav": "Desktop", "projects": [ { "repo": "pdf-next", diff --git a/src/style.css b/src/style.css deleted file mode 100644 index 57aaddc..0000000 --- a/src/style.css +++ /dev/null @@ -1,288 +0,0 @@ -/* The colours, the fonts and the sizes of a house come first (:root). */ - -:root { - --gutter: 16px; - --max: 1200px; -} - -@media (min-width: 720px) { - :root { - --gutter: 24px; - } -} - -@media (min-width: 1100px) { - :root { - --gutter: 32px; - } -} - -*, -*::before, -*::after { - box-sizing: border-box; -} - -html { - color-scheme: dark; - -webkit-text-size-adjust: 100%; - text-size-adjust: 100%; -} - -body { - margin: 0; - min-height: 100vh; - padding-block: 14px 22px; - background: var(--bg); - color: var(--fg); - font: 400 var(--fs) / 1.55 var(--font); - -webkit-font-smoothing: antialiased; -} - -h1, -h2, -p, -ul { - margin: 0; -} - -ul { - padding: 0; - list-style: none; -} - -img { - display: block; - max-width: 100%; - height: auto; -} - -a { - color: inherit; - text-decoration: none; -} - -a:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 3px; - border-radius: 2px; -} - -.skip { - position: absolute; - top: -5rem; - left: var(--gutter); - z-index: 10; - padding: 8px 16px; - background: var(--fg); - color: var(--bg); - font-family: var(--mono); - font-size: 0.75rem; -} - -.skip:focus { - top: 8px; -} - -.wrap { - width: min(100% - 2 * var(--gutter), var(--max)); - margin-inline: auto; -} - -/* The top bar: the three sites and the type site. Weft sets it on every house. The current site is - marked and is not a link. The footer repeats the four names as links. */ -.bar { - display: flex; - flex-wrap: wrap; - gap: 0 16px; - margin-bottom: 14px; - font: 400 0.75rem / 1 var(--mono); - letter-spacing: 0.04em; -} - -.bar a, -.bar span { - display: inline-flex; - align-items: center; - padding-block: 6px; - color: var(--muted); - overflow-wrap: anywhere; -} - -.bar [aria-current="page"] { - color: var(--fg); - text-decoration: underline 2px var(--accent); - text-underline-offset: 6px; -} - -/* On a narrow screen every link is at least 44 px high. */ -@media (max-width: 720px) { - .bar a, - .bar span, - footer a { - min-height: 44px; - } -} - -/* The banner is the image of the GitHub profile. Its top and bottom edges fade into the ground. */ -.banner { - display: block; - width: 100%; - aspect-ratio: 1408 / 469; - object-fit: cover; - mask-image: linear-gradient(transparent, #000 10%, #000 90%, transparent); -} - -.duo { - display: grid; - grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); - gap: 20px; - align-items: end; - margin-top: 20px; -} - -.line { - font-size: var(--ls); - line-height: 1.3; - text-wrap: balance; - word-spacing: var(--ws); -} - -.blurb { - max-width: 52ch; - word-spacing: var(--ws); - font-size: calc(var(--fs) * 0.88); - color: var(--muted); -} - -@media (max-width: 520px) { - .duo { - grid-template-columns: 1fr; - } -} - -/* A small group label, set in Weft with a square of the accent colour. */ -.lbl { - display: flex; - align-items: center; - gap: 8px; - margin: 32px 0 10px; - font: 400 0.71875rem / 1 var(--mono); - letter-spacing: 0.08em; - text-transform: uppercase; - color: var(--muted); -} - -.lbl::before { - content: ""; - width: 6px; - height: 6px; - background: var(--accent); -} - -.grid { - display: grid; - grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); - gap: 14px 12px; -} - -.plate { - display: grid; - align-content: start; - gap: 4px; - min-width: 0; -} - -.pic { - display: block; - overflow: hidden; -} - -.plate img { - display: block; - width: 100%; - aspect-ratio: 3 / 1; - object-fit: cover; - outline: 1px solid var(--edge); - outline-offset: -1px; - border-radius: 2px; -} - -.plate .ds { - word-spacing: var(--ws); - font-size: calc(var(--fs) * 0.8); - color: var(--muted); - line-height: 1.35; - overflow-wrap: anywhere; -} - -/* The small link after a description: always underlined, so a touch screen shows it too. */ -.ds a { - color: var(--fg); - text-decoration: underline 1px var(--accent); - text-underline-offset: 0.2em; -} - -@media (max-width: 720px) { - .ds a { - display: flex; - align-items: center; - width: fit-content; - min-height: 44px; - } -} - -footer { - margin-top: 40px; - font: 400 0.71875rem / 1 var(--mono); - letter-spacing: 0.04em; - color: var(--muted); -} - -/* The footer line: the four links, set like the top bar. Each link but the last draws a dot after its name, - so a dot stays on the line of the name it follows. */ -footer p { - display: flex; - flex-wrap: wrap; - align-items: center; - gap: 0 0.5em; -} - -footer a { - display: inline-flex; - align-items: center; - gap: 0.5em; - padding-block: 6px; -} - -footer a:not(:last-child)::after { - content: ""; - width: 3px; - height: 3px; - background: var(--muted); - border-radius: 50%; -} - -/* Hover effects only for pointers that hover. Motion only when the reader has not asked for less. */ -@media (hover: hover) { - .pic:hover img { - outline-color: var(--accent); - } - - .ds a:hover { - text-decoration-thickness: 2px; - } -} - -@media (prefers-reduced-motion: no-preference) { - a, - img { - transition: color 0.2s ease, transform 0.2s ease; - } -} - -@media (hover: hover) and (prefers-reduced-motion: no-preference) { - .pic:hover img { - transform: scale(1.02); - } -} diff --git a/src/system.css b/src/system.css new file mode 100644 index 0000000..0e2474c --- /dev/null +++ b/src/system.css @@ -0,0 +1,222 @@ +/* machine-made web system. One file for machine-made, openfluids, BoringQuantSystems and type. + A page sets only its house tokens (ground, surface, line, text, muted, accent) and its banner. + + TYPE SCALE: ratio 1.25 (major third) on 1rem = 16 px. Every text style is one step. + step -1 0.8rem 12.8 px Weft meta: bar 1, bar 2 sections, section labels, plate facts, footer, table keys + step 0 1rem 16 px Sans reading text: captions, latest entries, table values, notes + step 1 1.25rem 20 px proposal page small headings only + step 2 1.5625rem 25 px bar-2 wordmark (type) + step 2-3 fluid 25 -> 31.25 px between 390 and 1280 px: the house line (--t-line) + step 3-5 fluid 31.25 -> 48.8 px between 390 and 1280 px: tester lines (--t-display) + step 4 2.441rem 39 px family tiles on the type site + SPACING: 4 8 12 16 24 32 48 64 96 px, nothing else. + GRID: 12 columns, 24 px gutter, 1200 px content at most, 16 px side margin on a phone. + ACCENT: four uses only. Bar 1 marker, bar 2 marker, section-label cell, link underline. */ +:root { + --step--1: 0.8rem; + --step-0: 1rem; + --step-1: 1.25rem; + --step-2: 1.5625rem; + --step-3: 1.953rem; + --step-4: 2.441rem; + --step-5: 3.052rem; + --t-line: clamp(1.5625rem, 1.391rem + 0.702vw, 1.953rem); + --t-display: clamp(1.953rem, 1.472rem + 1.975vw, 3.052rem); + --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px; --sp-9: 96px; + --side: var(--sp-4); + --gutter: var(--sp-5); + --max: 1200px; + --bar1: 40px; + --bar2: 64px; + --b1h: 41px; /* bar 1 plus its line: where bar 2 starts to stick */ + --f-weft: "mm Weft", ui-monospace, monospace; + --f-sans: "mm Sans", system-ui, sans-serif; + --f-heddle: "mm Heddle", "mm Sans", system-ui, sans-serif; + --f-warp: "mm Warp", serif; + --ease: cubic-bezier(0.2, 0, 0, 1); +} +@media (min-width: 720px) { :root { --side: var(--sp-5); } } +@media (min-width: 1100px) { :root { --side: var(--sp-6); } } + +*, *::before, *::after { box-sizing: border-box; } +html { color-scheme: dark; background: var(--ground); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; scroll-padding-block-start: calc(var(--bar2) + var(--sp-4)); } +body { margin: 0; min-height: 100dvh; background: var(--ground); color: var(--text); font: 400 var(--step-0)/1.5 var(--f-sans); } +h1, h2, h3, p, ul, ol, figure { margin: 0; } +ul, ol { padding: 0; list-style: none; } +img { display: block; max-width: 100%; height: auto; } +a { color: inherit; text-decoration: none; } +:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; } +.wrap { width: 100%; max-width: calc(var(--max) + 2 * var(--side)); margin-inline: auto; padding-left: max(var(--side), env(safe-area-inset-left)); padding-right: max(var(--side), env(safe-area-inset-right)); } +.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } +.skip { position: absolute; top: calc(-1 * var(--sp-8)); left: var(--sp-4); z-index: 10; padding: var(--sp-2) var(--sp-4); background: var(--text); color: var(--ground); font: 400 var(--step--1)/1 var(--f-weft); } +.skip:focus { top: var(--sp-2); } +.n { font-family: var(--f-weft); font-variant-numeric: tabular-nums; font-feature-settings: "ss01" 1; } + +/* Bar 1: the four sites, same order and face everywhere. Scrolls away. On a phone it scrolls sideways. */ +.b1 { border-bottom: 1px solid var(--line); } +.b1 ul { display: flex; align-items: center; gap: var(--sp-5); height: var(--bar1); font: 400 var(--step--1)/1 var(--f-weft); white-space: nowrap; overflow-x: auto; scrollbar-width: none; } +.b1 ul::-webkit-scrollbar { display: none; } +.b1 li { flex: none; height: 100%; } +.b1 a, .b1 span { display: inline-flex; align-items: center; height: 100%; color: var(--muted); } +@media (hover: hover) { .b1 a:hover { color: var(--text); } } +.b1 [aria-current] { color: var(--text); text-decoration: underline 2px var(--accent); text-underline-offset: 6px; } + +/* Bar 2: logo left, sections right. Sticks to the top; its bottom line shows only after scrolling. */ +.b2 { position: sticky; top: 0; z-index: 5; background: var(--ground); border-bottom: 1px solid transparent; } +@media (prefers-reduced-motion: no-preference) { + @supports (animation-timeline: scroll()) { + .b2 { animation: b2-line linear both; animation-timeline: scroll(root); animation-range: var(--b1h) calc(var(--b1h) + 1px); } + @keyframes b2-line { to { border-bottom-color: var(--line); } } + } +} +.b2 .wrap { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-5); height: var(--bar2); } +.logo { display: inline-flex; align-items: center; gap: var(--sp-3); flex: none; color: var(--text); } +.logo img, .logo svg { width: 28px; height: 28px; border-radius: 4px; } +.logo svg { fill: currentColor; border-radius: 0; } +.logo .r { fill: var(--accent); } +.wm { font: 650 var(--step-2)/1 var(--f-heddle); letter-spacing: -0.01em; font-stretch: 100%; } +.secs { display: flex; align-items: center; gap: var(--sp-5); min-width: 0; font: 400 var(--step--1)/1 var(--f-weft); white-space: nowrap; overflow-x: auto; scrollbar-width: none; } +.secs::-webkit-scrollbar { display: none; } +.secs a { display: inline-flex; align-items: center; height: 44px; position: relative; flex: none; } +@media (hover: hover) { .secs a:hover { color: var(--muted); } } +.secs [aria-current]::after { content: ""; position: absolute; left: 0; right: 0; bottom: var(--sp-2); height: 2px; background: var(--accent); } +@media (max-width: 719px) { + .b1 ul { flex-wrap: wrap; height: auto; column-gap: var(--sp-4); row-gap: 0; padding-block: var(--sp-1); overflow: visible; } + .b1 li { height: 44px; } + :root { --b1h: 97px; } + .logo { min-height: 44px; } + .secs { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - var(--sp-6)), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - var(--sp-6)), transparent); padding-right: var(--sp-6); } + .b2 .wrap { justify-content: flex-start; gap: var(--sp-4); } + .secs { gap: var(--sp-4); } +} + +/* Banner: one rule for the three houses. 3:1 at every width; on a phone the empty 6 % at each side is cut. */ +.banner { margin-top: var(--sp-5); } +.banner img { width: 100%; aspect-ratio: 1408 / 469; object-fit: cover; -webkit-mask-image: linear-gradient(transparent, #000 10%, #000 90%, transparent); mask-image: linear-gradient(transparent, #000 10%, #000 90%, transparent); } +@media (max-width: 719px) { .banner img { aspect-ratio: 1240 / 469; } } + +/* The house line: one size on all four sites. */ +.line { margin-top: var(--sp-6); max-width: 28em; font-weight: 400; font-size: var(--t-line); line-height: 1.25; text-wrap: pretty; hyphens: none; } +@media (min-width: 720px) { .line { text-wrap: balance; } } +.line.weft { font-family: var(--f-weft); } +.line.heddle { font-family: var(--f-heddle); font-weight: 400; letter-spacing: -0.01em; } +.line.warp { font-family: var(--f-warp); letter-spacing: -0.01em; } +.nb { white-space: nowrap; } +.warp { font-variant-numeric: oldstyle-nums proportional-nums; } +.warp .sc { font-variant-caps: all-small-caps; letter-spacing: 0.04em; } +.fit1 { white-space: nowrap; } +@media (max-width: 519px) { .heddle.fit1, .wm { font-stretch: 80%; } } + +/* A row of the page grid: label in columns 1-3, content in columns 4-12. */ +.row { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--gutter); margin-top: var(--sp-7); padding-top: var(--sp-5); border-top: 1px solid var(--line); } +.row.tight { margin-top: var(--sp-6); } +.row > * { grid-column: 4 / 13; min-width: 0; } +.row > .lbl { grid-column: 1 / 4; } +.lbl { display: flex; align-items: center; align-self: start; gap: var(--sp-2); min-height: 20px; font: 400 var(--step--1)/1.4 var(--f-weft); letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); } +.mk { flex: none; width: 11px; height: 11px; } +.mk .o { fill: var(--line); } +.mk .on { fill: var(--accent); } +@media (max-width: 859px) { + .row > *, .row > .lbl { grid-column: 1 / -1; } + .row > .lbl { margin-bottom: var(--sp-4); } +} + +/* Plates: image 3:1, no inner padding, caption 8 px below, facts 4 px below the caption. */ +.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-6) var(--gutter); } +.grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } +@media (max-width: 999px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } } +@media (min-width: 520px) { .grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } } +@media (max-width: 519px) { .grid, .grid.g2 { grid-template-columns: minmax(0, 1fr); gap: var(--sp-5); } } +.plate { display: grid; align-content: start; min-width: 0; } +.pic { display: block; border-radius: 2px; } +.pic img, .tile { width: 100%; aspect-ratio: 3 / 1; object-fit: cover; border-radius: 2px; outline: 1px solid var(--line); outline-offset: -1px; } +.ds { margin-top: var(--sp-2); font: 400 var(--step-0)/1.4 var(--f-sans); color: var(--muted); text-wrap: pretty; } +.facts { margin-top: var(--sp-1); font: 400 var(--step--1)/1.4 var(--f-weft); color: var(--muted); font-variant-numeric: tabular-nums; font-feature-settings: "ss01" 1; font-variation-settings: "FRAG" 0; } +.facts { overflow: hidden; } +.facts > span { display: inline-flex; flex-wrap: wrap; margin-left: calc(-1 * var(--sp-4)); } +.facts > span > span { white-space: nowrap; } +.facts > span > span::before { content: "\00b7"; display: inline-block; width: var(--sp-4); text-align: center; } +a.u, .ds a { color: var(--text); text-decoration: underline 1px var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: from-font; } +.ds a { display: inline-block; padding-block: var(--sp-3); margin-block: calc(-1 * var(--sp-3)); } +@media (hover: hover) { + .plate:hover .pic img, .plate:hover .tile { filter: brightness(1.02); } + .plate:hover .facts { font-variation-settings: "FRAG" 40; } +} +.plate:focus-within .facts { font-variation-settings: "FRAG" 40; } +@media (prefers-reduced-motion: no-preference) { + .pic img, .tile { transition: filter 240ms var(--ease); } + .facts { transition: font-variation-settings 240ms var(--ease); } +} +@media (prefers-reduced-motion: reduce) { .plate:focus-within .facts { font-variation-settings: "FRAG" 0; } } +@media (hover: hover) and (prefers-reduced-motion: reduce) { .plate:hover .facts { font-variation-settings: "FRAG" 0; } } + +/* Latest: the three most recent releases. A row of cells on a wide screen, a list on a phone. */ +.latest { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4) var(--gutter); } +.latest.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } +.latest.n1 { grid-template-columns: minmax(0, 1fr); } +.latest.n2 { grid-template-columns: repeat(3, minmax(0, 1fr)); } +.latest.n1 li { grid-template-columns: auto auto; justify-content: start; align-items: baseline; gap: var(--sp-4); } +.latest li { display: grid; gap: var(--sp-1); min-width: 0; } +.latest a { justify-self: start; color: var(--text); text-decoration: underline 1px var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: from-font; } +.latest .facts { margin-top: 0; } +@media (max-width: 859px) { .latest.n4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } } +@media (max-width: 519px) { + .latest, .latest.n1, .latest.n2, .latest.n4 { grid-template-columns: minmax(0, 1fr); gap: 0; border-top: 1px solid var(--line); } + .latest li, .latest.n1 li { grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: var(--sp-4); padding-block: var(--sp-3); border-bottom: 1px solid var(--line); } + .latest a { padding-block: var(--sp-3); margin-block: calc(-1 * var(--sp-3)); } +} + +/* Footer: one line, the four names. */ +footer { margin-top: var(--sp-8); padding-bottom: max(var(--sp-6), env(safe-area-inset-bottom)); } +footer .fl { padding-top: var(--sp-4); border-top: 1px solid var(--line); overflow: hidden; } +footer ul { display: flex; flex-wrap: wrap; align-items: center; margin-left: calc(-1 * var(--sp-6)); font: 400 var(--step--1)/1 var(--f-weft); color: var(--muted); } +footer li { display: inline-flex; align-items: center; } +footer li::before { content: "\00b7"; width: var(--sp-6); text-align: center; } +footer a { display: inline-flex; align-items: center; min-height: 44px; } +@media (hover: hover) { footer a:hover { color: var(--text); } } + +/* Type site: tester, family tiles, release table. Same grid as everything else. */ +.tester { display: grid; gap: 0; } +.trow { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--gutter); padding-block: var(--sp-4); border-bottom: 1px solid var(--line); } +.trow:first-child { padding-top: 0; } +.tmeta { grid-column: 1 / 4; display: grid; align-content: start; gap: var(--sp-2); font: 400 var(--step--1)/1.4 var(--f-weft); color: var(--muted); } +.tmeta b { font-weight: 400; color: var(--text); } +.tline { grid-column: 4 / 13; min-width: 0; font-size: var(--t-display); line-height: 1.1; overflow-wrap: break-word; outline-offset: var(--sp-1); caret-color: var(--text); } +.tline.weft { font-family: var(--f-weft); } +.tline.sans { font-family: var(--f-sans); letter-spacing: -0.01em; } +.tline.heddle { font-family: var(--f-heddle); letter-spacing: -0.01em; } +.tline.warp { font-family: var(--f-warp); } +.full .tline.weft { font-family: "mm Weft Full", var(--f-weft); } +.full .tline.sans { font-family: "mm Sans Full", var(--f-sans); } +.full .tline.heddle { font-family: "mm Heddle Full", var(--f-heddle); } +.full .tline.warp { font-family: "mm Warp Full", var(--f-warp); } +.tin { display: none; width: 100%; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: 2px; background: var(--surface); color: var(--text); font: 400 var(--step-0)/1.5 var(--f-sans); } +.tin::placeholder { color: var(--muted); } +.js .tin { display: block; } +.tester { grid-column: 1 / 13; margin-top: var(--sp-5); } +.ctl { display: none; grid-template-columns: minmax(0, 1fr) 3.5em; align-items: center; gap: var(--sp-2); } +.js .ctl { display: grid; } +.ctl span { grid-column: 1 / -1; } +.ctl input { width: 100%; margin: 0; accent-color: var(--text); } +.ctl output { text-align: end; color: var(--text); } +@media (max-width: 859px) { + .tmeta, .tline { grid-column: 1 / -1; } + .tmeta { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); margin-bottom: var(--sp-3); } + .tmeta b { grid-column: 1 / -1; } +} +.tile { display: grid; align-items: center; justify-items: start; padding-inline: var(--sp-5); background: var(--surface); color: var(--text); overflow: hidden; white-space: nowrap; font-size: var(--step-4); line-height: 1; } +.tile.weft { font-family: var(--f-weft); font-feature-settings: "ss01" 1; } +.tile.sans { font-family: var(--f-sans); font-weight: 500; letter-spacing: -0.02em; } +.tile.heddle { font-family: var(--f-heddle); font-weight: 700; } +.tile.warp { font-family: var(--f-warp); } +@media (max-width: 389px) { .tile { font-size: var(--step-3); } .heddle.fit1 { font-stretch: 70%; } } +.table { border-top: 1px solid var(--line); } +.table li { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: var(--sp-4); padding-block: var(--sp-3); border-bottom: 1px solid var(--line); } +.table .k { font: 400 var(--step--1)/1.9 var(--f-weft); color: var(--muted); } +.table p { max-width: 66ch; } +.more { margin-top: var(--sp-5); } +@media (max-width: 519px) { .table li { grid-template-columns: minmax(0, 1fr); gap: 0; } } + +/* Not found: the same header, one line and a way back. */ +.nf { min-height: 50dvh; } +.nf p + p { margin-top: var(--sp-4); }