diff --git a/.claude/skills/tetrak-ocr-design/SKILL.md b/.claude/skills/tetrak-ocr-design/SKILL.md index 89a49a8..3bbf36f 100644 --- a/.claude/skills/tetrak-ocr-design/SKILL.md +++ b/.claude/skills/tetrak-ocr-design/SKILL.md @@ -341,6 +341,31 @@ or a preview deploy served from a subdirectory — would reopen the trap. `site/tests/site.spec.ts` follows every internal link on every page and checks the masthead stays under the baseURL path. +## Share cards and structured data + +`baseof.html` publishes three things about a page besides its title, and all +three read the same sentence from `partials/description.html`: `description` +where the page has one, else the standfirst, else the site description. + +- `partials/social.html` writes the Open Graph tags. Twitter gets only + `twitter:card`; it falls back to the `og:` tags for the rest. +- `partials/share-card.html` returns the one share image, + `assets/images/design/share-card.png`. It is drawn by + `node scripts/render-share-card.mjs` from the design tokens and the home + page's standfirst, and committed. Re-run the script after changing that + standfirst. It is a PNG at a fixed, unfingerprinted address on purpose. +- `partials/structured-data.html` writes JSON-LD on three kinds of page: the + home page (Organization and WebSite), an article (TechArticle, with the + author from `data/authors.toml`) and a product page (SoftwareSourceCode). + +**A product page needs a `software` map in its front matter**: `name`, +`repository`, `licence` (an SPDX identifier such as `MIT` or `Apache-2.0`) and +`language`. A missing key fails the build. `params.profiles` in `hugo.toml` +lists the profiles published as the organisation's `sameAs`. + +`layouts/robots.txt` replaces Hugo's one-line default so that it names the +sitemap. + ## No mkdocs markup The site was migrated from mkdocs-material. Its extensions are **not** available diff --git a/site/assets/images/design/share-card.png b/site/assets/images/design/share-card.png new file mode 100644 index 0000000..99e80d8 Binary files /dev/null and b/site/assets/images/design/share-card.png differ diff --git a/site/config/_default/hugo.toml b/site/config/_default/hugo.toml index 9212424..f467c44 100644 --- a/site/config/_default/hugo.toml +++ b/site/config/_default/hugo.toml @@ -96,6 +96,11 @@ capitalizeListTitles = false # The organisation, which the masthead links to since October 2026: the site # describes several tools, each in its own repository under it. org = "https://github.com/scattercode" + # The profiles that are Tetrak's own and nothing else's, published as the + # organisation's `sameAs` in the home page's structured data + # (layouts/partials/structured-data.html). The GitHub organisation above is + # deliberately not among them: it holds other projects as well. + profiles = ["https://huggingface.co/tetrak", "https://pypi.org/org/tetrak/"] # The security watch at /security/ is built from sillybos's advisory record # (docs/advisories/record.json in that repository): one page per advisory diff --git a/site/content/armenian-ocr.md b/site/content/armenian-ocr.md index 222b589..66583bb 100644 --- a/site/content/armenian-ocr.md +++ b/site/content/armenian-ocr.md @@ -3,6 +3,11 @@ title: "Armenian text recognition" kicker: "Open source" standfirst: "A recogniser we trained ourselves for printed Armenian, published as a small library that adds the language to EasyOCR, with the model, the word list and the training data in the open." description: "tetrak-easyocr-armenian: an open-source Armenian OCR model for EasyOCR, trained on proofread Armenian texts, reading Eastern and Western Armenian in either orthography. Weights on Hugging Face, Apache 2.0." +software: + name: "tetrak-easyocr-armenian" + repository: "https://github.com/scattercode/tetrak-easyocr-armenian" + licence: "Apache-2.0" + language: "Python" --- ## What it is for diff --git a/site/content/ocr/_index.md b/site/content/ocr/_index.md index 1285760..c91f098 100644 --- a/site/content/ocr/_index.md +++ b/site/content/ocr/_index.md @@ -3,6 +3,11 @@ title: "Tetrak OCR" kicker: "Open source" standfirst: "Turns scans of unruly archive material into searchable text, on your own machine, choosing the best engine for each file and setting aside what it cannot read." description: "Tetrak OCR: a local-first tool that runs several OCR engines over scans of archival material, keeps the best transcript of each file, and sends what it cannot trust to a person." +software: + name: "tetrak" + repository: "https://github.com/scattercode/tetrak" + licence: "MIT" + language: "Python" --- Historical archives do not arrive as tidy, uniform PDFs. A real collection is a diff --git a/site/content/sillybos.md b/site/content/sillybos.md index f393cbc..630e53d 100644 --- a/site/content/sillybos.md +++ b/site/content/sillybos.md @@ -3,6 +3,11 @@ title: "sillybos" kicker: "Open source" standfirst: "A small library that decides, before any image library or PDF renderer opens a file, whether it is one of the formats you meant to read, within the limits you expect, and if not, why. Read the tag; don't unroll the scroll." description: "sillybos: a dependency-free Python library and command that checks a JPEG, PNG, TIFF or PDF before any decoder opens it: format from the first bytes, header limits, rare codings refused, a plain reason for each refusal. MIT licensed." +software: + name: "sillybos" + repository: "https://github.com/scattercode/sillybos" + licence: "MIT" + language: "Python" --- ## What it is for diff --git a/site/content/translit.md b/site/content/translit.md index 872b600..b2ad799 100644 --- a/site/content/translit.md +++ b/site/content/translit.md @@ -3,6 +3,11 @@ title: "Transliteration and cross-script search" kicker: "Open source" standfirst: "A small library that tells you which script a text is in, writes it in Latin letters by a named library standard, and reduces every spelling of a name to one form, so that one search finds them all." description: "tetrak-translit: open-source detection, transliteration and search folding for Armenian, Georgian, Russian and Syriac, with ALA-LC, ISO and national romanisation schemes. MIT licensed." +software: + name: "tetrak-translit" + repository: "https://github.com/scattercode/tetrak-translit" + licence: "MIT" + language: "Python" --- ## What it is for diff --git a/site/layouts/_default/baseof.html b/site/layouts/_default/baseof.html index 12ad2f1..c3ebc06 100644 --- a/site/layouts/_default/baseof.html +++ b/site/layouts/_default/baseof.html @@ -14,11 +14,9 @@ term.html is the case that forced it: a tag page's .Title is the tag, and a browser tab reading "ocr" says nothing about what is in it. */ -}} {{ block "title" . }}{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ .Title }} · {{ .Site.Title }}{{ end }}{{ end }} - {{- /* The standfirst is the sentence a page already writes to say what it is, - so an article with one does not need a second copy in `description`. - Falling straight through to the site description put the same - paragraph about OCR routing under every result. */ -}} - + {{- /* Resolved in a partial because the share card and the structured data + publish the same sentence, and the three must not drift apart. */ -}} + {{- /* The theme is read and applied before first paint, so a reader who chose dark never sees a flash of the paper ground. Inline and tiny by @@ -62,6 +60,11 @@ {{- errorf "baseof: no page at /articles -- the feed link cannot be built" }} {{- end }} + {{- /* How the page looks when its link is shared, and what it is in the + terms a search engine reads. Each partial says why it is there. */ -}} + {{- partial "social.html" . }} + {{- partial "structured-data.html" . }} + {{- /* Plausible, matching scattercode.dev and velostevie: no cookies, no consent banner, and both requests same-origin. The src is the first-party path proxied by functions/js/script.js.js at the diff --git a/site/layouts/partials/description.html b/site/layouts/partials/description.html new file mode 100644 index 0000000..48c37e4 --- /dev/null +++ b/site/layouts/partials/description.html @@ -0,0 +1,19 @@ +{{- /* + The one-sentence description of a page, returned so that a caller can write + {{ $d := partial "description.html" . }}. + + Three places publish it -- the meta description, the share card and the + structured data -- and they have to say the same thing: a search result that + describes a page one way and a link preview that describes it another reads + as two different pages. + + `description` wins where a page has one. Otherwise the standfirst is the + sentence a page already writes to say what it is, so an article with one + does not need a second copy in `description`. Falling straight through to + the site description put the same paragraph about OCR routing under every + search result. +*/ -}} +{{- $description := .Site.Params.description }} +{{- with .Params.standfirst }}{{ $description = . }}{{ end }} +{{- with .Description }}{{ $description = . }}{{ end }} +{{- return $description }} diff --git a/site/layouts/partials/share-card.html b/site/layouts/partials/share-card.html new file mode 100644 index 0000000..cad5602 --- /dev/null +++ b/site/layouts/partials/share-card.html @@ -0,0 +1,23 @@ +{{- /* + The site's share card, returned as an image resource so that a caller can + write {{ $card := partial "share-card.html" . }} and read .Permalink, .Width + and .Height from it. + + One card for every page. It is drawn by scripts/render-share-card.mjs from + the design tokens and the home page's standfirst, and committed; see that + script for why neither illustration in assets/images/design/ could do the + job. + + Not fingerprinted, unlike the stylesheet and the script. A link preview is + fetched once by somebody else's server and kept, so the address has to stay + where it was when the link was shared. + + A missing file fails the build, the same bargain the figure and lightbox + shortcodes make: a share card that 404s shows as a broken image in every + timeline the link reaches, and nothing on the site itself would look wrong. +*/ -}} +{{- $card := resources.Get "images/design/share-card.png" }} +{{- if not $card }} + {{- errorf "share-card: assets/images/design/share-card.png is missing -- run node scripts/render-share-card.mjs" }} +{{- end }} +{{- return $card }} diff --git a/site/layouts/partials/social.html b/site/layouts/partials/social.html new file mode 100644 index 0000000..8fc061d --- /dev/null +++ b/site/layouts/partials/social.html @@ -0,0 +1,63 @@ +{{- /* + What a link to this page looks like when it is shared: the Open Graph tags + that Mastodon, Bluesky, LinkedIn, Slack and most chat clients read to draw a + preview card. + + The site had none until November 2026, so a shared article arrived as a bare + URL -- for a site whose readers mostly come by somebody passing a link on. + + The title is the page's own, without the " · Tetrak" suffix the browser tab + carries: og:site_name says whose page it is, and a card that repeats the + name in the title wastes the line. A tag page is the exception baseof.html + and term.html already make. Its .Title is the bare tag, and a card titled + "ocr" says as little as a tab reading "ocr" did. The wording here has to + stay in step with the h1 in layouts/term.html. + + Twitter gets one tag. It falls back to og:title, og:description and og:image + for everything else, and a second copy of each would be three more places + for the card to disagree with itself. +*/ -}} +{{- $description := partial "description.html" . }} +{{- $card := partial "share-card.html" . }} + +{{- $title := .Title }} +{{- if .IsHome }} + {{- $title = site.Title }} +{{- else if eq .Kind "term" }} + {{- $title = printf "Tagged %s" .Title }} +{{- end }} + +{{- /* Only an article is an "article" to Open Graph: dated, signed and + tagged. A product page or a reference page is a page of a website. */ -}} +{{- $isArticle := and .IsPage (eq .Section "articles") }} + + + + + + + + + + + + {{- /* The card is the site's name over the home page's standfirst, so that + sentence is what it says to a reader who cannot see it. */ -}} + {{- with site.Home.Params.standfirst }} + + {{- end }} + {{- if $isArticle }} + + {{- /* .Lastmod is the file's last commit (enableGitInfo). An article is + often committed before the date it carries, and a page modified + before it was published is a claim nobody should have to parse. + Compared as days, because .Date is midnight and a commit made later + on publication day would otherwise count as a revision. */ -}} + {{- if gt (.Lastmod.Format "2006-01-02") (.Date.Format "2006-01-02") }} + + {{- end }} + {{- range .Params.tags }} + + {{- end }} + {{- end }} + diff --git a/site/layouts/partials/structured-data.html b/site/layouts/partials/structured-data.html new file mode 100644 index 0000000..019521d --- /dev/null +++ b/site/layouts/partials/structured-data.html @@ -0,0 +1,115 @@ +{{- /* + schema.org structured data, as JSON-LD: what a page is, said in the form a + search engine reads rather than infers. + + Three kinds of page get a block, and the rest get none. A block that only + repeated the title and the description would say nothing the has not + already said. + + - The home page says who publishes the site: an Organization, and the + WebSite it publishes. + - An article is a TechArticle: dated, signed, and published by that + organisation. The author comes from the same register as the byline + (partials/author.html), so the name a search engine reads is the name on + the page. + - A product page is a SoftwareSourceCode: a named package, its repository + and its licence, from the `software` map in its front matter. + + None of this earns a rich result. Search engines draw those for recipes and + reviews, not for libraries. It is here so that the four packages, the + articles and the name "Tetrak" are tied to one another by statement rather + than by guesswork. + + Each block is built as a dict and written by jsonify, never assembled as a + string: jsonify escapes whatever a title or a standfirst contains, including + the "" that would otherwise end the block early. +*/ -}} +{{- $home := site.Home.Permalink }} +{{- $description := partial "description.html" . }} +{{- $locale := site.Language.Locale | default "en-gb" }} + +{{- /* The organisation is named once and referred to by @id everywhere else, + so an article does not carry a second, thinner copy of it. */ -}} +{{- $orgID := printf "%s#organisation" $home }} +{{- $orgRef := dict "@type" "Organization" "@id" $orgID "name" site.Title "url" $home }} + +{{- $schema := dict }} + +{{- if .IsHome }} + {{- $org := merge $orgRef (dict "description" site.Params.description) }} + {{- /* Only the profiles that are Tetrak's and nothing else's. The GitHub + organisation in params.org holds other projects as well, so it is not + "the same as" Tetrak in the sense sameAs means. */ -}} + {{- with site.Params.profiles }} + {{- $org = merge $org (dict "sameAs" .) }} + {{- end }} + {{- $website := dict + "@type" "WebSite" + "@id" (printf "%s#website" $home) + "name" site.Title + "url" $home + "description" $description + "inLanguage" $locale + "publisher" (dict "@id" $orgID) }} + {{- $schema = dict "@context" "https://schema.org" "@graph" (slice $org $website) }} + +{{- else if and .IsPage (eq .Section "articles") }} + {{- $author := partial "author.html" . }} + {{- $person := dict "@type" "Person" "name" $author.name }} + {{- /* The LinkedIn profile is the one address that is this author's alone. + The about page holds both of us, and two people sharing a URL is two + people a search engine may merge. */ -}} + {{- with $author.linkedin }} + {{- $person = merge $person (dict "sameAs" (printf "https://www.linkedin.com/in/%s/" .)) }} + {{- end }} + {{- $card := partial "share-card.html" . }} + {{- $schema = dict + "@context" "https://schema.org" + "@type" "TechArticle" + "headline" .Title + "description" $description + "url" .Permalink + "mainEntityOfPage" .Permalink + "inLanguage" $locale + "datePublished" (.Date.Format "2006-01-02") + "author" $person + "publisher" $orgRef + "image" $card.Permalink }} + {{- /* The same guard, for the same reason, as article:modified_time in + partials/social.html. */ -}} + {{- if gt (.Lastmod.Format "2006-01-02") (.Date.Format "2006-01-02") }} + {{- $schema = merge $schema (dict "dateModified" (.Lastmod.Format "2006-01-02")) }} + {{- end }} + {{- with .Params.tags }} + {{- $schema = merge $schema (dict "keywords" (delimit . ", ")) }} + {{- end }} + +{{- else if isset .Params "software" }} + {{- /* Every key is required. A package with no repository or no licence is + not something to describe to a search engine by halves, and the build + failing here is how a fifth product page finds out what it owes. The + guards are chained so that one defect gives one message. */ -}} + {{- $software := .Params.software }} + {{- $missing := "" }} + {{- range slice "name" "repository" "licence" "language" }} + {{- if and (not $missing) (not (index $software .)) }}{{ $missing = . }}{{ end }} + {{- end }} + {{- if $missing }} + {{- errorf "structured-data: %q has a `software` map with no `%s` -- it needs name, repository, licence (an SPDX identifier) and language" .File.Path $missing }} + {{- else }} + {{- $schema = dict + "@context" "https://schema.org" + "@type" "SoftwareSourceCode" + "name" $software.name + "description" $description + "url" .Permalink + "codeRepository" $software.repository + "programmingLanguage" $software.language + "license" (printf "https://spdx.org/licenses/%s" $software.licence) + "publisher" $orgRef }} + {{- end }} +{{- end }} + +{{- with $schema }} + +{{- end }} diff --git a/site/layouts/robots.txt b/site/layouts/robots.txt new file mode 100644 index 0000000..0331fb9 --- /dev/null +++ b/site/layouts/robots.txt @@ -0,0 +1,16 @@ +{{- /* + Hugo's built-in robots.txt is a single "User-agent: *" line. That allows + everything, which is what the site wants, but it leaves out the one thing a + crawler reads this file to find: where the sitemap is. A crawler that has + never been told about the site in a webmaster console has no other way to + learn it. + + The empty Disallow is the standard way to say "nothing is off limits". The + first version of the protocol requires at least one rule per group. + + No leading slash on the path: see "the baseURL trap" in the design skill. +*/ -}} +User-agent: * +Disallow: + +Sitemap: {{ "sitemap.xml" | absURL }} diff --git a/site/scripts/render-share-card.mjs b/site/scripts/render-share-card.mjs new file mode 100644 index 0000000..e101091 --- /dev/null +++ b/site/scripts/render-share-card.mjs @@ -0,0 +1,167 @@ +/** + * Render the site's share card: the image a link to tetrak.dev shows when it + * is pasted into Mastodon, Bluesky, LinkedIn, Slack or a chat window. + * + * Until November 2026 the site declared no Open Graph image at all, so a + * shared link arrived as a bare URL. The two illustrations already in + * assets/images/design/ are both about the OCR tool, and since brief 017 the + * site is the home of every Tetrak tool and of the services, so neither can + * stand for the whole site. This draws a card from the design system itself: + * the paper ground, a clay rule, the name in Playfair Display and the home + * page's standfirst in Source Serif 4. + * + * The standfirst is read from content/_index.md rather than typed in here, so + * the card says what the home page says. It does not follow an edit on its + * own, though: the output is a committed PNG, so re-run this after changing + * the home page's standfirst. + * + * Rendered in the Chromium that Playwright already installs, with the fonts + * vendored in assets/fonts/, the same way scripts/render-mermaid.mjs draws the + * diagrams. It is not part of `prebuild`: the build host has no browser, and + * the card changes about as often as the site's name does. + * + * PNG, not WebP, because several link-preview scrapers still do not read + * WebP. 1200 by 630 is the size Open Graph consumers crop least. + * layouts/partials/social.html publishes the file and reads its dimensions. + * + * Prerequisites: `npm install` and `npx playwright install chromium`. + * + * Run, from site/: + * node scripts/render-share-card.mjs + */ + +import { readFileSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { chromium } from "@playwright/test"; + +const SITE = join(import.meta.dirname, ".."); +const FONTS = join(SITE, "assets", "fonts"); +const HOME = join(SITE, "content", "_index.md"); +const OUT = join(SITE, "assets", "images", "design", "share-card.png"); + +const WIDTH = 1200; +const HEIGHT = 630; + +// The light-theme tokens from assets/scss/_tokens.scss. A share card has no +// dark rendition: the page it is pasted into chooses the surround, not us. +const TOKENS = { + paper: "#f7f3ec", + ink: "#1e1c19", + inkSoft: "#6d675e", + clay: "#b08d4f", + clayDeep: "#8a6a33" +}; + +/** One front-matter string from the home page, or a failure that says which. */ +function frontMatter(key) { + const source = readFileSync(HOME, "utf8"); + const match = source.match(new RegExp(`^${key}:\\s*"(.*)"\\s*$`, "m")); + if (!match) { + throw new Error(`render-share-card: no quoted \`${key}\` in content/_index.md`); + } + return match[1]; +} + +/** A vendored font as a data URI, so the page needs no server to load it. */ +function fontFace(family, file, weight) { + const data = readFileSync(join(FONTS, file)).toString("base64"); + return `@font-face { + font-family: "${family}"; + font-weight: ${weight}; + src: url("data:font/woff2;base64,${data}") format("woff2"); + }`; +} + +const escapeHtml = text => + text.replace(/&/g, "&").replace(//g, ">"); + +const title = frontMatter("title"); +const standfirst = frontMatter("standfirst"); + +const html = ` + + + + + + +
+
tetrak.dev
+

${escapeHtml(title)}

+

${escapeHtml(standfirst)}

+ +`; + +const browser = await chromium.launch(); +try { + const page = await browser.newPage({ + viewport: { width: WIDTH, height: HEIGHT }, + deviceScaleFactor: 1 + }); + await page.setContent(html); + // A screenshot taken before the faces have loaded is a card in Times. + // Passed as a string because it runs in the page, not in Node, where this + // file is linted and `document` does not exist. + await page.evaluate("document.fonts.ready.then(() => true)"); + writeFileSync(OUT, await page.screenshot({ type: "png" })); +} finally { + await browser.close(); +} + +console.log(`render-share-card: wrote ${OUT.slice(SITE.length + 1)} (${WIDTH}×${HEIGHT})`); diff --git a/site/tests/site.spec.ts b/site/tests/site.spec.ts index 0a51e75..20638f2 100644 --- a/site/tests/site.spec.ts +++ b/site/tests/site.spec.ts @@ -1,4 +1,4 @@ -import { expect, test, type APIRequestContext } from "@playwright/test"; +import { expect, test, type APIRequestContext, type Page } from "@playwright/test"; import { existsSync, readdirSync, readFileSync } from "node:fs"; import { join, relative } from "node:path"; @@ -937,3 +937,135 @@ test("the reading-order table agrees with the CSV it is generated from", async ( } } }); + +/** The JSON-LD blocks in a page's head, parsed. */ +async function structuredData(page: Page): Promise[]> { + const blocks = await page.locator('head script[type="application/ld+json"]').allTextContents(); + return blocks.map((block) => JSON.parse(block)); +} + +test("every page carries a share card, and the image it names is in the build", async ({ page, request, baseURL }) => { + // A link to this site is mostly passed on by hand -- a post, a message, an + // email -- and until November 2026 it arrived as a bare URL: the head had + // no Open Graph tags at all. Nothing on the site looks wrong when they are + // missing, which is why this asks every page. + const pages = await allPages(request, baseURL!); + test.setTimeout(Math.max(90_000, pages.length * 2_000)); + + const meta = (property: string) => + page.locator(`head meta[property="${property}"]`).getAttribute("content"); + + const lacking: string[] = []; + const images = new Set(); + + for (const url of pages) { + await page.goto(url, { waitUntil: "domcontentloaded" }); + const path = new URL(url).pathname; + + for (const property of ["og:title", "og:description", "og:url", "og:image", "og:image:alt"]) { + if (!(await meta(property))?.trim()) lacking.push(`${path} has no ${property}`); + } + + // The card and the search result describe the page in the same words. + const description = await page.locator('head meta[name="description"]').getAttribute("content"); + if ((await meta("og:description")) !== description) { + lacking.push(`${path} describes itself one way to search and another when shared`); + } + + const image = await meta("og:image"); + if (image) images.add(image); + } + + expect(lacking, lacking.join("\n")).toHaveLength(0); + + // An og:image that 404s is a broken image in every timeline the link + // reaches. Scrapers want an absolute URL and do not all read WebP. + expect(images.size, "no page named a share image").toBeGreaterThan(0); + for (const image of images) { + expect(image, "og:image must be absolute").toMatch(/^https?:\/\//); + const response = await request.get(image); + expect(response.status(), `${image} is not in the build`).toBe(200); + expect(response.headers()["content-type"]).toMatch(/^image\/(png|jpeg)/); + } +}); + +test("a tag page is shared as what it is, not as a bare tag", async ({ page }) => { + // The same correction term.html makes to the h1 and the browser tab: a card + // titled "ocr" tells the person it is sent to nothing. The two wordings live + // in different templates, so this is what holds them together. + await page.goto("articles/"); + await page.locator(".article-row .tag").first().click(); + + const heading = (await page.locator("main h1").textContent())!.trim(); + await expect(page.locator('head meta[property="og:title"]')).toHaveAttribute("content", heading); +}); + +test("an article's structured data says what the page says", async ({ page }) => { + // The block is for a machine, and nobody reads it, so it can go on naming + // the wrong author or the wrong day for as long as the page looks right. + // Checked against what a reader sees rather than against the front matter. + await page.goto("articles/"); + await page.locator(".article-row__title a").first().click(); + + const [article] = await structuredData(page); + expect(article["@type"]).toBe("TechArticle"); + expect(article.headline).toBe((await page.locator("main h1").textContent())!.trim()); + expect(article.datePublished).toBe(await page.locator(".article-meta time").getAttribute("datetime")); + expect(article.author.name).toBe((await page.locator(".article-author__name").textContent())!.trim()); + expect(article.publisher.name).toBe("Tetrak"); + + // Shared as an article, with the same date. + await expect(page.locator('head meta[property="og:type"]')).toHaveAttribute("content", "article"); + await expect(page.locator('head meta[property="article:published_time"]')) + .toHaveAttribute("content", article.datePublished); +}); + +test("each product page names its package, its repository and its licence", async ({ page }) => { + // The four pages the home page's tiles lead to. A fifth product needs a + // `software` map in its front matter, and this is where forgetting it shows. + await page.goto("./"); + const products = await page.locator(".grid.cards li > p:first-child a").evaluateAll( + as => as.map(a => (a as HTMLAnchorElement).href) + ); + expect(products).toHaveLength(4); + + for (const url of products) { + await page.goto(url); + const [software] = await structuredData(page); + expect(software?.["@type"], `${url} has no software block`).toBe("SoftwareSourceCode"); + expect(software.name).toBeTruthy(); + expect(software.license).toMatch(/^https:\/\/spdx\.org\/licenses\/[A-Za-z0-9.-]+$/); + + // The repository is typed into front matter, a second copy of a link the + // page already carries. It has to be one a reader can follow from here. + await expect( + page.locator(`a[href^="${software.codeRepository}"]`).first(), + `${url} names ${software.codeRepository} but does not link to it` + ).toBeAttached(); + } +}); + +test("the home page says who publishes the site", async ({ page }) => { + await page.goto("./"); + const [data] = await structuredData(page); + const types = data["@graph"].map((node: Record) => node["@type"]); + expect(types).toEqual(["Organization", "WebSite"]); + + const [organisation, website] = data["@graph"]; + expect(organisation.name).toBe("Tetrak"); + expect(website.publisher["@id"]).toBe(organisation["@id"]); +}); + +test("robots.txt points crawlers at a sitemap that exists", async ({ request, baseURL }) => { + // Hugo's built-in robots.txt is one line and names no sitemap, so a crawler + // that nobody has told about the site has no way to find the page list. + const robots = await (await request.get(new URL("robots.txt", baseURL!).href)).text(); + expect(robots).toMatch(/^User-agent: \*$/m); + // Nothing is off limits: an empty Disallow, and no other. + expect(robots.match(/^Disallow:.*$/gm)).toEqual(["Disallow:"]); + + const sitemap = robots.match(/^Sitemap: (\S+)$/m)?.[1]; + expect(sitemap, "robots.txt names no sitemap").toBeTruthy(); + expect(sitemap).toMatch(/^https?:\/\//); + expect((await request.get(sitemap!)).status()).toBe(200); +});