Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 262ea20b22f9f37dbc1ba6206788e566b6e5b774
parent 797704fbd0a4a0dcaf9a06ed2353a02ce193f927
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun, 11 Oct 2026 14:48:54 -0400

homepage: articles — compose's reports stage under /articles/, the routes, the nav, the latest few

Release 26 A3. `compose homepage` gains the reports stage over the article
store (articlesReportHost) into homepage/public: articles, moments, clips,
posts, history, exports and feeds under the /articles/ base, PROJECT_URL the
absolute one; a moment's record opens in the listed public site that
publishes its channel (channel-sites.json + the site's siteUrl), or nowhere.
It stamps homepage-build.json {audience, articles}. `--private` carries
every published article (A4's private build).

The stage serves under the host's base: ReportHost.base (a site's
/reports/, the homepage's /articles/) threads through compose's paths,
downloads, feeds (lib/report/feeds.ts takes an optional base), history and
exports; the views' own derived paths (stills, video, the index link) are
moved by a shim in compose until views.ts takes the base (A5).

The homepage renders the shared components: /articles/, /articles/<id>/,
/articles/<id>/history/ and /m/<key>/, honest empty states (a placeholder
param) on a build:nodata tree; "Articles" in the header and footer nav
(the md nav's gap tightened so five links fit at 768 px); Latest Articles on
the home page when there are any. Tests: compose-homepage over a temp corpus,
the articles reader, an e2e spec over export's report fixture rebased to
/articles/ (E2E_ARTICLES_PUBLIC_DIR, dev only).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
M.gitignore | 7+++++++
MENVIRONMENT.md | 3+++
Acommon/bin/compose-homepage.test.ts | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/bin/compose-homepage.ts | 82++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mcommon/lib/envVars.ts | 2++
Mcommon/lib/report/feeds.ts | 45+++++++++++++++++++++++++++++----------------
Mcommon/lib/report/routes.ts | 4++++
Mcommon/publish/composeReports.ts | 96++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
Mcommon/publish/composeReportsArticles.test.ts | 22++++++++++++++++------
Mcommon/publish/reportExports.ts | 11++++++++---
Mcommon/publish/reportHistory.ts | 21++++++++++++++-------
Mcommon/publish/reportHost.ts | 7+++++++
Ahomepage/app/articles/[reportId]/history/page.tsx | 36++++++++++++++++++++++++++++++++++++
Ahomepage/app/articles/[reportId]/page.tsx | 37+++++++++++++++++++++++++++++++++++++
Ahomepage/app/articles/page.tsx | 20++++++++++++++++++++
Mhomepage/app/components/Header.tsx | 9++++++---
Ahomepage/app/lib/articles.test.ts | 32++++++++++++++++++++++++++++++++
Ahomepage/app/lib/articles.ts | 45+++++++++++++++++++++++++++++++++++++++++++++
Mhomepage/app/lib/nav.ts | 6++++--
Ahomepage/app/m/[...moment]/page.tsx | 43+++++++++++++++++++++++++++++++++++++++++++
Mhomepage/app/page.tsx | 36+++++++++++++++++++++++++++++++++++-
Ahomepage/e2e/articles.spec.ts | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ahomepage/e2e/fixture-articles.ts | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mhomepage/e2e/marketing.spec.ts | 11++++++-----
Mhomepage/playwright.config.ts | 12++++++++++++
25 files changed, 785 insertions(+), 69 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -103,6 +103,12 @@ yarn-error.log* # Note this does NOT cover /homepage/public/_headers — the `_headers` rule above # is scoped to /export/public, so the homepage's stays tracked. /homepage/public/downloads +# The articles `compose homepage` writes (release 26: articles/, m/, media/ +# — the clips are binary, a Tailwind hazard as below) and the build's stamp. +/homepage/public/articles/ +/homepage/public/m/ +/homepage/public/media/ +/homepage/public/homepage-build.json # The published source: the git mirror (archilyzer.git: packs, info/refs), the # raw tree and manifest.json, all written by `archilyzer source publish` # (common/publish/source.ts). Ignored for Tailwind as much as for git: Tailwind @@ -161,6 +167,7 @@ yarn-error.log* /homepage/e2e/.e2e-sites/ # the e2e's fixture publish for /source/ (homepage/e2e/fixture-source.ts) /homepage/e2e/.e2e-source/ +/homepage/e2e/.e2e-articles/ # site config /settings.json diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md @@ -132,6 +132,7 @@ Every local server's default port, from `common/lib/ports.mjs`. The primary chec | `OLLAMA_STUB_PORT` | `11435` | Digest-lane stub server in the editor e2e suite. A worktree adds its offset (`pnpm wt list`). | common/lib/ports.mjs | | `HOMEPAGE_DEV_PORT` | `3030` | Homepage real dev (`pnpm dev:homepage`). A worktree adds its offset (`pnpm wt list`). | common/lib/ports.mjs | | `HOMEPAGE_PORT` | `3031` | Homepage static `serve out` (start:homepage). A worktree adds its offset (`pnpm wt list`). | common/lib/ports.mjs | +| `HOMEPAGE_PRIVATE_PORT` | `3032` | The private homepage build, `serve out-private` (start:private). A worktree adds its offset (`pnpm wt list`). | common/lib/ports.mjs | | `HOMEPAGE_E2E_PORT` | `3040` | Homepage's own Playwright suite. A worktree adds its offset (`pnpm wt list`). | common/lib/ports.mjs | | `HUB_PORT` | `3041` | Export's hub Playwright suite (e2e:hub). A worktree adds its offset (`pnpm wt list`). | common/lib/ports.mjs | | `REPORT_SITE_E2E_PORT` | `3042` | Export's cited report-site Playwright suite (e2e:report). A worktree adds its offset (`pnpm wt list`). | common/lib/ports.mjs | @@ -153,6 +154,7 @@ The publish pipeline sets these for a process it spawns. Listed so a reader know | `REPORTS_ALLOW_MISSING_MEDIA` | off | `1` lets a report citation whose evidence media was not prepared through compose (`--allow-missing-media`): its moment page renders without a clip. Off, compose fails with the list. | common/bin/compose-site.ts | | `ARCHIVES_READONLY` | off | `1` inside a docker-mode build container: materialize archives, never write the shared cache. | common/bin/compose-site.ts | | `GGML_BACKEND_PATH` | settings.tts.orpheus.ggmlBackendPath | The ggml backend llama-server loads (Vulkan by default), set for the Orpheus server the editor starts — from `settings.tts.orpheus.ggmlBackendPath`, never the environment. | common/lib/ttsApps.ts | +| `HOMEPAGE_DIST_DIR` | unset (`homepage/out`) | Where the homepage's `next build` writes its export; `archilyzer build homepage --private` sets it to `out-private`, so the private build never replaces the deployable `homepage/out`. | homepage/next.config.ts, common/publish/build.ts | | `HOMEPAGE_PUBLIC_DIR` | `<repo>/homepage/public` | Where `compose homepage` and `source publish` write. | common/bin/compose-homepage.ts, common/publish/source.ts | ## Docker @@ -231,6 +233,7 @@ Read only by a test harness, a fake binary or a test-mode branch. Never set one | `E2E_RETRIES` | `0` | Retries per shard (`--retries N` wins); 0 keeps a sharded run comparable to a serial one. | scripts/run-sharded-e2e.mjs | | `E2E_IMAGE` | `yt-dlp-transcript-browser-e2e` | The sharded e2e run's image tag. | scripts/run-sharded-e2e.mjs | | `E2E_SKIP_BUILD` | off | `1` reuses the sharded e2e image instead of rebuilding it (`--no-build`). | scripts/run-sharded-e2e.mjs | +| `E2E_ARTICLES_PUBLIC_DIR` | unset (the pages read `homepage/public`) | The fixture public dir the homepage's e2e dev server reads the articles and moments from while it holds `articles/index.json`; set by `homepage/playwright.config.ts`, ignored by a production build. | homepage/app/lib/articles.ts | | `E2E_SOURCE_PUBLIC_DIR` | unset (the page reads `homepage/public`) | The fixture publish the homepage's e2e dev server reads the `/source/` page from while it holds a manifest; set by `homepage/playwright.config.ts`, written and removed by `homepage/e2e/source-history.spec.ts`, ignored by a production build. | homepage/app/lib/source.ts | | `E2E_EXPECT_SOURCE` | off (both states pass) | `1` makes the homepage suite's `/source/` specs fail on the empty state; a gate that ran `archilyzer source publish` first sets it. | homepage/e2e/source.spec.ts | | `E2E_HOMEPAGE_SUMMARY_FILE` | `homepage/public/homepage-summary.json` | The synthetic summary the homepage's e2e dev server reads; set by `homepage/playwright.config.ts`, ignored by a production build. | homepage/app/lib/summary.ts | diff --git a/common/bin/compose-homepage.test.ts b/common/bin/compose-homepage.test.ts @@ -0,0 +1,139 @@ +// `compose homepage`'s articles stage (release 26 A3/A4), over a temp corpus: +// the public compose carries only public articles, the private one every +// published article; both stamp homepage-build.json; a moment's record opens +// in the listed public site that publishes its channel. +// +// Run with: node_modules/.bin/tsx --test bin/compose-homepage.test.ts + +import { after, test } from "node:test"; +import assert from "node:assert/strict"; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +const ROOT = mkdtempSync(path.join(tmpdir(), "compose-homepage-")); +const PUBLIC = path.join(ROOT, "homepage-public"); +Object.assign(process.env, { + TRANSCRIPTS_DIR: path.join(ROOT, "transcripts"), + SAVED_VIDEOS_DIR: path.join(ROOT, "saved-videos"), + SITES_DIR: path.join(ROOT, "transcripts", "sites"), + SETTINGS_FILE: path.join(ROOT, "settings.json"), + EXPORT_PUBLIC_DIR: path.join(ROOT, "public"), + EXPORT_INDEX_DIR: path.join(ROOT, ".export-index"), + EXPORT_BUILDS_DIR: path.join(ROOT, ".export-builds"), + HOMEPAGE_PUBLIC_DIR: PUBLIC, +}); +delete process.env.ARTICLES_DIR; +after(() => rmSync(ROOT, { recursive: true, force: true })); + +const { getPaths } = await import("../lib/paths"); +const { buildIndex } = await import("../controller/buildIndex"); +const { articleDir, configureArticle } = await import("../lib/report/registry"); +const { main, channelSiteUrlOf } = await import("./compose-homepage"); +const { REPORT_MEDIA_FORMAT, REPORT_MEDIA_VERSION } = await import("../publish/reportMedia"); + +const paths = getPaths(); +const put = (file: string, value: unknown) => { + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, typeof value === "string" ? value : JSON.stringify(value, null, 2)); +}; +const readJson = <T = Record<string, unknown>>(file: string): T => JSON.parse(readFileSync(file, "utf8")) as T; +const ts = (s: number) => new Date(s * 1000).toISOString().slice(11, 23); +const QUOTE = "The bridge opened in the spring, I was there for it."; + +put(paths.settingsFile, {}); +put(path.join(paths.channelsDir, "vids", "config.json"), { handling: "youtube", name: "Vids", url: "https://www.youtube.com/@vids/videos" }); +put(path.join(paths.channelsDir, "vids", "data", "abc1", "metadata.info.json"), { + id: "abc1", + title: "A stream", + channel: "vids", + upload_date: "20260110", + duration: 600, + webpage_url: "https://www.youtube.com/watch?v=abc1", + extractor_key: "Youtube", +}); +put( + path.join(paths.channelsDir, "vids", "data", "abc1", "transcript.en.vtt"), + `WEBVTT\nKind: captions\nLanguage: en\n\n${ts(10)} --> ${ts(20)} align:start position:0%\n${QUOTE}<${ts(10)}><c></c>\n`, +); +put(path.join(paths.sitesDir, "listed", "site.json"), { + siteId: "listed", + siteTitle: "Listed", + groups: [{ id: "default", name: "All", selectedByDefault: true }], + defaultGroupId: "default", + channels: [{ slug: "vids", groupId: "default" }], + siteUrl: "https://listed.example.test", +}); +const article = (id: string, over: Record<string, unknown> = {}) => ({ + format: "archilyzer-report", + version: 1, + id, + kind: "sweep", + title: `Article ${id}`, + citations: { c1: { kind: "video", channel: "vids", id: "abc1", start: 10, end: 20, quote: QUOTE } }, + sections: [{ id: "s", title: "S", body: "Said [this](cite:c1)." }], + ...over, +}); +put(path.join(articleDir(paths, "open"), "report.json"), article("open")); +put(path.join(articleDir(paths, "closed"), "report.json"), article("closed")); +await configureArticle("open", { published: true, audience: "public" }, paths); +await configureArticle("closed", { published: true }, paths); +// The articles' prepared media, as `reports prepare --article` leaves it. +const media = path.join(paths.exportIndexDir, "articles", "report-media"); +const hash = "0".repeat(31) + "1"; +put(path.join(media, `${hash}.mp4`), "video"); +put(path.join(media, `${hash}.json`), { span: { from: 10, to: 20 } }); +put(path.join(media, "index.json"), { + format: REPORT_MEDIA_FORMAT, + version: REPORT_MEDIA_VERSION, + siteId: "articles", + preparedAt: "2026-10-11T00:00:00.000Z", + moments: { "vids/abc1/10.00-20.00": { kind: "video", file: `${hash}.mp4`, bytes: 5, sha256: "f".repeat(64), width: null, height: null, durationSec: 10 } }, + problems: [], +}); +await buildIndex({ paths, onLog: () => {} }); + +const quietly = async (fn: () => Promise<void>) => { + const log = console.log; + console.log = () => {}; + try { + await fn(); + } finally { + console.log = log; + } +}; + +test("a public compose carries the public article only, stamped public; its moment opens in the listed site", async () => { + await quietly(() => main({ paths, audience: "public" })); + const index = readJson<{ reports: { id: string; href: string }[] }>(path.join(PUBLIC, "articles", "index.json")); + assert.deepEqual(index.reports.map((r) => [r.id, r.href]), [["open", "/articles/open/"]]); + assert.deepEqual(readJson(path.join(PUBLIC, "homepage-build.json")), { + format: "archilyzer-homepage-build", + version: 1, + audience: "public", + articles: ["open"], + }); + const moment = readJson<{ record: { corpusUrl?: string } }>(path.join(PUBLIC, "m", "vids", "abc1", "10.00-20.00", "moment.json")); + assert.equal(moment.record.corpusUrl, "https://listed.example.test/?v=vids%2Fabc1&t=10"); + assert.ok(existsSync(path.join(PUBLIC, "media", "clips", "vids", "abc1", "10.00-20.00.mp4"))); + assert.ok(existsSync(path.join(PUBLIC, "homepage-summary.json")), "the landing data is composed as before"); +}); + +test("a private compose carries every published article, stamped private", async () => { + await quietly(() => main({ paths, audience: "private" })); + const index = readJson<{ reports: { id: string }[] }>(path.join(PUBLIC, "articles", "index.json")); + assert.deepEqual(index.reports.map((r) => r.id), ["open", "closed"]); + assert.equal(readJson(path.join(PUBLIC, "homepage-build.json")).audience, "private"); +}); + +test("channelSiteUrlOf: the first listed site with a public URL; none for a channel no listed site has", () => { + const sites = [ + { siteId: "a", siteUrl: undefined }, + { siteId: "b", siteUrl: "https://b.example.test/" }, + { siteId: "p", siteUrl: "https://p.example.test", audience: "private" }, + ] as never; + const of = channelSiteUrlOf({ x: ["a", "b"], y: ["p"] }, sites); + assert.equal(of("x"), "https://b.example.test"); + assert.equal(of("y"), undefined); + assert.equal(of("z"), undefined); +}); diff --git a/common/bin/compose-homepage.ts b/common/bin/compose-homepage.ts @@ -7,6 +7,23 @@ // public/stats/{manifest,page-NNNN}.json <- whole-pool stats (every channel) // public/channel-sites.json <- channel slug -> [siteId, ...] // public/homepage-summary.json <- small cross-site landing summary +// public/articles/, m/, media/ <- the ARTICLES (release 26 A3): the +// reports stage +// (publish/composeReports.ts) over +// the article store, under the +// /articles/ base +// public/homepage-build.json <- the build's audience and the +// articles it carries (the stamp +// lib/builtExport.ts audits) +// +// THE AUDIENCE. A public compose (the default) carries only the published +// articles whose report.json says `audience: "public"`; `--private` +// (`audience: "private"`) every published article, for the local-only private +// build (`archilyzer build homepage --private`), which is never deployed. The +// post visibility rule applies by that audience. A moment's record opens in +// the listed public site that publishes its channel (channel-sites.json and +// the site's `siteUrl`, absolute), or nowhere. Links and feeds are absolute +// on PROJECT_URL. // // None of the three names an unlisted site (site.json `listed: false`) or holds // a channel only unlisted sites expose (lib/siteSchema.ts isListedSite). @@ -18,7 +35,12 @@ import path from "node:path"; import { getPaths, type Paths } from "../lib/paths"; import { writeJsonAtomic as writeJsonAtomicShared } from "../lib/jsonFile-server"; import { buildPoolSummary } from "../controller/poolSummary"; -import { isListedSite } from "../lib/site"; +import { isListedSite, parseSiteUrl, type Site } from "../lib/site"; +import { PROJECT_URL } from "../lib/project"; +import type { ReportAudience } from "../lib/report/schema"; +import type { ChannelSitesMap } from "../lib/homepageSummary"; +import { articlesReportHost } from "../publish/reportHost"; +import { composeHostReports } from "../publish/composeReports"; import { runIfEntryPoint } from "./_cli"; // Where the homepage Next.js app serves static assets from. Overridable for e2e @@ -35,8 +57,36 @@ function writeJsonAtomic(filePath: string, value: unknown): Promise<void> { return writeJsonAtomicShared(filePath, value, { indent: 0, newline: false }); } -export async function main(opts: { paths?: Paths } = {}): Promise<void> { +// The stamp a homepage build carries (public/ → out/): which audience it was +// composed for and the articles in it. lib/builtExport.ts reads it. +export const HOMEPAGE_BUILD_FILE = "homepage-build.json"; +export const HOMEPAGE_BUILD_FORMAT = "archilyzer-homepage-build"; + +// channel slug → the public URL of the first listed site that publishes it +// (a listed site is never private: lib/siteSchema.ts isListedSite), or none. +export function channelSiteUrlOf(channelSites: ChannelSitesMap, sites: readonly Site[]): (slug: string) => string | undefined { + const urlOf = new Map(sites.filter(isListedSite).map((s) => [s.siteId, parseSiteUrl(s.siteUrl)])); + return (slug) => { + for (const id of channelSites[slug] ?? []) { + const url = urlOf.get(id); + if (url) return url; + } + return undefined; + }; +} + +export async function main( + opts: { + paths?: Paths; + // Default "public". + audience?: ReportAudience; + // Let an article citation without prepared media through (its moment then + // renders without a clip). + allowMissingMedia?: boolean; + } = {}, +): Promise<void> { const paths = opts.paths ?? getPaths(); + const audience = opts.audience ?? "public"; const publicDir = homepagePublicDir(paths.monorepoRoot); const statsDir = path.join(publicDir, "stats"); @@ -64,6 +114,27 @@ export async function main(opts: { paths?: Paths } = {}): Promise<void> { summary, ); + // The articles: the reports stage over the article store, under /articles/. + // It fails (and the build with it) on a problem, as a site's compose does. + const host = await articlesReportHost(paths, { + audience, + siteUrl: PROJECT_URL, + channelSiteUrl: channelSiteUrlOf(channelSites, sites), + }); + const composed = await composeHostReports({ + paths, + host, + publicDir, + allowMissingMedia: opts.allowMissingMedia === true, + log: (line) => console.log(line), + }); + await writeJsonAtomicShared( + path.join(publicDir, HOMEPAGE_BUILD_FILE), + { format: HOMEPAGE_BUILD_FORMAT, version: 1, audience, articles: composed.reports.map((r) => r.id) }, + { mkdir: true }, + ); + console.log(`compose-homepage: ${composed.reports.length} ${audience} article(s), ${composed.moments.length} moment(s).`); + const unlisted = sites.filter((s) => !isListedSite(s)).length; console.log( `compose-homepage: ${Object.keys(channelSites).length} channel(s) mapped across ${sites.length - unlisted} listed site(s)` + @@ -74,4 +145,9 @@ export async function main(opts: { paths?: Paths } = {}): Promise<void> { ); } -runIfEntryPoint(import.meta.url, () => main()); +runIfEntryPoint(import.meta.url, () => + main({ + audience: process.argv.includes("--private") ? "private" : "public", + allowMissingMedia: process.argv.includes("--allow-missing-media"), + }), +); diff --git a/common/lib/envVars.ts b/common/lib/envVars.ts @@ -161,6 +161,7 @@ const DECLARED: EnvVarDecl[] = [ { name: "REPORTS_ALLOW_MISSING_MEDIA", audience: "internal", default: "off", readBy: "common/bin/compose-site.ts", doc: "`1` lets a report citation whose evidence media was not prepared through compose (`--allow-missing-media`): its moment page renders without a clip. Off, compose fails with the list." }, { name: "ARCHIVES_READONLY", audience: "internal", default: "off", readBy: "common/bin/compose-site.ts", doc: "`1` inside a docker-mode build container: materialize archives, never write the shared cache." }, { name: "GGML_BACKEND_PATH", audience: "internal", default: "settings.tts.orpheus.ggmlBackendPath", readBy: "common/lib/ttsApps.ts", doc: "The ggml backend llama-server loads (Vulkan by default), set for the Orpheus server the editor starts — from `settings.tts.orpheus.ggmlBackendPath`, never the environment." }, + { name: "HOMEPAGE_DIST_DIR", audience: "internal", default: "unset (`homepage/out`)", readBy: "homepage/next.config.ts, common/publish/build.ts", doc: "Where the homepage's `next build` writes its export; `archilyzer build homepage --private` sets it to `out-private`, so the private build never replaces the deployable `homepage/out`." }, { name: "HOMEPAGE_PUBLIC_DIR", audience: "internal", default: "`<repo>/homepage/public`", readBy: "common/bin/compose-homepage.ts, common/publish/source.ts", doc: "Where `compose homepage` and `source publish` write." }, // ── docker: the container's set ──────────────────────────────────────── @@ -229,6 +230,7 @@ const DECLARED: EnvVarDecl[] = [ { name: "E2E_RETRIES", audience: "test", default: "`0`", readBy: "scripts/run-sharded-e2e.mjs", doc: "Retries per shard (`--retries N` wins); 0 keeps a sharded run comparable to a serial one." }, { name: "E2E_IMAGE", audience: "test", default: "`yt-dlp-transcript-browser-e2e`", readBy: "scripts/run-sharded-e2e.mjs", doc: "The sharded e2e run's image tag." }, { name: "E2E_SKIP_BUILD", audience: "test", default: "off", readBy: "scripts/run-sharded-e2e.mjs", doc: "`1` reuses the sharded e2e image instead of rebuilding it (`--no-build`)." }, + { name: "E2E_ARTICLES_PUBLIC_DIR", audience: "test", default: "unset (the pages read `homepage/public`)", readBy: "homepage/app/lib/articles.ts", doc: "The fixture public dir the homepage's e2e dev server reads the articles and moments from while it holds `articles/index.json`; set by `homepage/playwright.config.ts`, ignored by a production build." }, { name: "E2E_SOURCE_PUBLIC_DIR", audience: "test", default: "unset (the page reads `homepage/public`)", readBy: "homepage/app/lib/source.ts", doc: "The fixture publish the homepage's e2e dev server reads the `/source/` page from while it holds a manifest; set by `homepage/playwright.config.ts`, written and removed by `homepage/e2e/source-history.spec.ts`, ignored by a production build." }, { name: "E2E_EXPECT_SOURCE", audience: "test", default: "off (both states pass)", readBy: "homepage/e2e/source.spec.ts", doc: "`1` makes the homepage suite's `/source/` specs fail on the empty state; a gate that ran `archilyzer source publish` first sets it." }, { name: "E2E_HOMEPAGE_SUMMARY_FILE", audience: "test", default: "`homepage/public/homepage-summary.json`", readBy: "homepage/app/lib/summary.ts", doc: "The synthetic summary the homepage's e2e dev server reads; set by `homepage/playwright.config.ts`, ignored by a production build." }, diff --git a/common/lib/report/feeds.ts b/common/lib/report/feeds.ts @@ -18,6 +18,7 @@ import { citationAnchor } from "../citations/inline"; import { reportDateMs } from "./entries"; import { markdownToHtml, siteLink } from "./exportHtml"; +import { SITE_REPORTS_BASE, type ReportBase } from "./routes"; import { REPORT_FEED_FORMATS, reportFeedPath, @@ -33,12 +34,14 @@ export const JSON_FEED_VERSION = "https://jsonfeed.org/version/1.1"; export type ReportFeedOptions = { // The site's public URL: absolute http(s) (lib/siteSchema.ts parseSiteUrl). siteUrl: string; + // Where the build serves its reports (./routes.ts); a site's by default. + base?: ReportBase; }; // A report's feed URLs on the site. -export function reportFeedUrls(siteUrl: string, reportId: string): ReportFeeds { +export function reportFeedUrls(siteUrl: string, reportId: string, base: ReportBase = SITE_REPORTS_BASE): ReportFeeds { return Object.fromEntries( - REPORT_FEED_FORMATS.map((f) => [f, siteLink(siteUrl, reportFeedPath(reportId, f))!]), + REPORT_FEED_FORMATS.map((f) => [f, siteLink(siteUrl, reportFeedPath(reportId, f, base))!]), ) as ReportFeeds; } @@ -79,21 +82,31 @@ export function rfc3339Date(v: string | undefined): string | undefined { } // The report's page on the site. -function pageUrlOf(view: Pick<ReportPageView, "id">, siteUrl: string): string { - return siteLink(siteUrl, reportPagePath(view.id))!; +function pageUrlOf(view: Pick<ReportPageView, "id">, siteUrl: string, base: ReportBase = SITE_REPORTS_BASE): string { + return siteLink(siteUrl, reportPagePath(view.id, base))!; } // An entry's permalink: the page at its anchor (a reference id is safe in a // fragment as it is). -export function entryUrl(view: Pick<ReportPageView, "id">, entry: Pick<EntryView, "id">, siteUrl: string): string { - return `${pageUrlOf(view, siteUrl)}#${entry.id}`; +export function entryUrl( + view: Pick<ReportPageView, "id">, + entry: Pick<EntryView, "id">, + siteUrl: string, + base: ReportBase = SITE_REPORTS_BASE, +): string { + return `${pageUrlOf(view, siteUrl, base)}#${entry.id}`; } // An entry's body as HTML for a feed reader: citation markers link to their // references on the report's page; a fragment link goes to the page; a // site-root link to the site. -export function entryContentHtml(view: Pick<ReportPageView, "id" | "citations">, entry: EntryView, siteUrl: string): string { - const page = pageUrlOf(view, siteUrl); +export function entryContentHtml( + view: Pick<ReportPageView, "id" | "citations">, + entry: EntryView, + siteUrl: string, + base: ReportBase = SITE_REPORTS_BASE, +): string { + const page = pageUrlOf(view, siteUrl, base); return markdownToHtml( entry.body, (id) => { @@ -120,8 +133,8 @@ function feedDate(view: ReportPageView): string | undefined { // RSS 2.0 (with an Atom self link, as validators ask). export function renderReportRss(view: ReportPageView, opts: ReportFeedOptions): string { - const page = pageUrlOf(view, opts.siteUrl); - const self = reportFeedUrls(opts.siteUrl, view.id).rss; + const page = pageUrlOf(view, opts.siteUrl, opts.base); + const self = reportFeedUrls(opts.siteUrl, view.id, opts.base).rss; const built = rfc822Date(feedDate(view)); const out: string[] = [ `<?xml version="1.0" encoding="UTF-8"?>`, @@ -135,7 +148,7 @@ export function renderReportRss(view: ReportPageView, opts: ReportFeedOptions): `<generator>Archilyzer</generator>`, ]; for (const e of view.entries ?? []) { - const url = entryUrl(view, e, opts.siteUrl); + const url = entryUrl(view, e, opts.siteUrl, opts.base); const pub = rfc822Date(e.date); out.push( `<item>`, @@ -143,7 +156,7 @@ export function renderReportRss(view: ReportPageView, opts: ReportFeedOptions): `<link>${escapeXml(url)}</link>`, `<guid isPermaLink="true">${escapeXml(url)}</guid>`, ...(pub ? [`<pubDate>${pub}</pubDate>`] : []), - `<description>${escapeXml(entryContentHtml(view, e, opts.siteUrl))}</description>`, + `<description>${escapeXml(entryContentHtml(view, e, opts.siteUrl, opts.base))}</description>`, `</item>`, ); } @@ -174,18 +187,18 @@ export function renderReportJsonFeed(view: ReportPageView, opts: ReportFeedOptio return { version: JSON_FEED_VERSION, title: reportFullTitle(view), - home_page_url: pageUrlOf(view, opts.siteUrl), - feed_url: reportFeedUrls(opts.siteUrl, view.id).json, + home_page_url: pageUrlOf(view, opts.siteUrl, opts.base), + feed_url: reportFeedUrls(opts.siteUrl, view.id, opts.base).json, description: feedDescription(view), items: (view.entries ?? []).map((e) => { - const url = entryUrl(view, e, opts.siteUrl); + const url = entryUrl(view, e, opts.siteUrl, opts.base); const published = rfc3339Date(e.date); const modified = rfc3339Date(e.updated); return { id: url, url, title: e.title, - content_html: entryContentHtml(view, e, opts.siteUrl), + content_html: entryContentHtml(view, e, opts.siteUrl, opts.base), ...(published ? { date_published: published } : {}), ...(modified ? { date_modified: modified } : {}), }; diff --git a/common/lib/report/routes.ts b/common/lib/report/routes.ts @@ -18,6 +18,10 @@ export type ReportBase = `/${string}/`; // A site's reports. export const SITE_REPORTS_BASE: ReportBase = "/reports/"; +// The homepage's articles (release 26 A3: the article store, published by the +// project homepage at /articles/<id>/). +export const ARTICLES_BASE: ReportBase = "/articles/"; + const BASE_RE = /^\/(?:[a-z0-9][a-z0-9-]*\/)+$/; // Whether `v` is a usable base: lowercase path segments, slashes on both ends. diff --git a/common/publish/composeReports.ts b/common/publish/composeReports.ts @@ -114,7 +114,7 @@ import { MOMENTS_INDEX_PATH, REPORT_INDEX_FORMAT, REPORT_VIEWS_VERSION, - REPORTS_INDEX_PATH, + reportsIndexPath, buildReportPageView, citedInViews, evidenceClipPath, @@ -148,11 +148,54 @@ import { import { publishableStoreExports, storeReportFileSha256, type PublishableReportExports } from "./reportExportFiles"; import { publishReportHistory, readReportHistoryView, reportHistoryRef, storeHistoryGitDir } from "./reportHistory"; import { hostCorpusLink, siteReportHost, type ReportHost } from "./reportHost"; +import { SITE_REPORTS_BASE, reportBaseDir, type ReportBase } from "../lib/report/routes"; import type { ReportHistoryRef, ReportHistoryView } from "../lib/report/revisions"; // The public dir's entries this stage owns. Every compose removes them first. +// A host serving under another base owns that base's directory in place of +// `reports` (reportPublicEntries). export const REPORT_PUBLIC_ENTRIES: readonly string[] = ["reports", "m", "media"]; +export function reportPublicEntries(base: ReportBase = SITE_REPORTS_BASE): string[] { + return [reportBaseDir(base), "m", "media"]; +} + +// THE BASE SHIM. lib/report/views.ts's view builders (buildReportPageView, +// reportIndexEntry) name a site's base for the paths they derive themselves — +// a still, the report's video, the index entry's link. A host serving under +// another base (the homepage's /articles/) has them moved here, until the +// builders take the base themselves (release 26 A5). +function rebased(p: string | undefined, id: string, base: ReportBase): string | undefined { + const from = `${SITE_REPORTS_BASE}${id}/`; + return p !== undefined && p.startsWith(from) ? `${base}${id}/${p.slice(from.length)}` : p; +} + +function rebaseView(view: ReportPageView, base: ReportBase): ReportPageView { + if (base === SITE_REPORTS_BASE) return view; + const citations = Object.fromEntries( + Object.entries(view.citations).map(([k, c]) => + c.kind === "source" && c.image ? [k, { ...c, image: rebased(c.image, view.id, base) }] : [k, c], + ), + ) as ReportPageView["citations"]; + return { + ...view, + citations, + ...(view.video + ? { + video: { + ...view.video, + src: rebased(view.video.src, view.id, base)!, + ...(view.video.poster ? { poster: rebased(view.video.poster, view.id, base) } : {}), + }, + } + : {}), + }; +} + +function rebaseIndexEntry(entry: ReportIndexEntry, base: ReportBase): ReportIndexEntry { + return base === SITE_REPORTS_BASE ? entry : { ...entry, href: rebased(entry.href, entry.id, base)! }; +} + // The transcript lines a moment page shows either side of its span, and at // most how many: bounded context, never the record (plans/report-sites.md, // Risks 5). @@ -762,7 +805,7 @@ export async function resolveReports(opts: ResolveReportsOptions): Promise<Resol return entry?.kind === "post" ? `/media/${entry.file}` : undefined; }; const views: ReportPageView[] = reports.map((report) => - buildReportPageView(report, { + rebaseView(buildReportPageView(report, { record: (c) => recordViews.get(c)!, post: (c) => { const post = postsByChannel.get(c.channel)?.get(c.id); @@ -771,13 +814,13 @@ export async function resolveReports(opts: ResolveReportsOptions): Promise<Resol downloads: opts.downloads?.(report.id), history: opts.history?.(report.id), feeds: opts.feeds?.(report.id), - }), + }), host.base), ); const index: ReportIndexView = { format: REPORT_INDEX_FORMAT, version: REPORT_VIEWS_VERSION, - reports: views.map(reportIndexEntry), + reports: views.map((v) => rebaseIndexEntry(reportIndexEntry(v), host.base)), }; const moments: MomentPageView[] = []; @@ -800,7 +843,7 @@ export async function resolveReports(opts: ResolveReportsOptions): Promise<Resol ...(c.speaker ? { speaker: c.speaker } : {}), ...(c.date ? { date: c.date } : {}), ...(c.verification ? { verification: c.verification } : {}), - citedIn: citedInViews(entries, views), + citedIn: citedInViews(entries, views, host.base), } as const; if (c.kind === "post") { const post = postsByChannel.get(c.channel)!.get(c.id)!; @@ -877,7 +920,7 @@ export async function composeHostReports(opts: ComposeHostReportsOptions): Promi // Whatever an earlier compose left. rm removes a link, never its target (a // worktree's public/ entries may be links into the primary checkout). - for (const entry of REPORT_PUBLIC_ENTRIES) { + for (const entry of reportPublicEntries(host.base)) { await rm(path.join(publicDir, entry), { recursive: true, force: true }); } if (host.published.length === 0) { @@ -900,9 +943,9 @@ export async function composeHostReports(opts: ComposeHostReportsOptions): Promi for (const id of host.published) { const gitDir = storeHistoryGitDir(host, id); try { - const view = await readReportHistoryView(gitDir, { reportId: id, siteUrl: host.siteUrl }); + const view = await readReportHistoryView(gitDir, { reportId: id, siteUrl: host.siteUrl, base: host.base }); if (!view) continue; - const ref = reportHistoryRef(view, await storeReportFileSha256(host, id)); + const ref = reportHistoryRef(view, await storeReportFileSha256(host, id), host.base); if (!ref.current) log(`[reports] ${id}: report.json changed since revision ${ref.revision} — export again to commit it`); histories.set(id, { view, ref, gitDir }); } catch (e) { @@ -919,28 +962,32 @@ export async function composeHostReports(opts: ComposeHostReportsOptions): Promi const { reports, views, index, moments, mediaOf, cacheDir, allowed } = await resolveReports({ ...opts, history: (id) => histories.get(id)?.ref, - feeds: siteUrl ? (id) => reportFeedUrls(siteUrl, id) : undefined, + feeds: siteUrl ? (id) => reportFeedUrls(siteUrl, id, host.base) : undefined, downloads: (id) => ({ ...Object.fromEntries( - REPORT_EXPORT_FORMATS.filter((f) => exportsOf.get(id)?.files[f]).map((f) => [f, reportExportDownloadPath(id, f)]), + REPORT_EXPORT_FORMATS.filter((f) => exportsOf.get(id)?.files[f]).map((f) => [f, reportExportDownloadPath(id, f, host.base)]), ), - json: reportCitationsDownloadPath(id, "json"), - csv: reportCitationsDownloadPath(id, "csv"), + json: reportCitationsDownloadPath(id, "json", host.base), + csv: reportCitationsDownloadPath(id, "csv", host.base), }), }); // ─── Writing ─── - await writeOut(publicDir, REPORTS_INDEX_PATH, json(index)); + await writeOut(publicDir, reportsIndexPath(host.base), json(index)); for (let i = 0; i < reports.length; i++) { const report = reports[i]; const view = views[i]; - await writeOut(publicDir, reportViewPath(report.id), json(view)); - await writeOut(publicDir, reportCitationsDownloadPath(report.id, "json"), json(citationSet(report, view))); - await writeOut(publicDir, reportCitationsDownloadPath(report.id, "csv"), citationsCsv(view)); + await writeOut(publicDir, reportViewPath(report.id, host.base), json(view)); + await writeOut(publicDir, reportCitationsDownloadPath(report.id, "json", host.base), json(citationSet(report, view))); + await writeOut(publicDir, reportCitationsDownloadPath(report.id, "csv", host.base), citationsCsv(view)); if (siteUrl && view.feeds) { - await writeOut(publicDir, reportFeedPath(report.id, "rss"), renderReportRss(view, { siteUrl })); - await writeOut(publicDir, reportFeedPath(report.id, "json"), json(renderReportJsonFeed(view, { siteUrl }))); + await writeOut(publicDir, reportFeedPath(report.id, "rss", host.base), renderReportRss(view, { siteUrl, base: host.base })); + await writeOut( + publicDir, + reportFeedPath(report.id, "json", host.base), + json(renderReportJsonFeed(view, { siteUrl, base: host.base })), + ); log(`[reports] ${report.id}: feeds of ${view.entries?.length ?? 0} timeline entr${view.entries?.length === 1 ? "y" : "ies"}.`); } if (report.video && view.video) { @@ -958,11 +1005,11 @@ export async function composeHostReports(opts: ComposeHostReportsOptions): Promi const exported = exportsOf.get(report.id)?.files ?? {}; for (const f of REPORT_EXPORT_FORMATS) { const src = exported[f]; - if (src) await copyOut(publicDir, src, reportExportDownloadPath(report.id, f)); + if (src) await copyOut(publicDir, src, reportExportDownloadPath(report.id, f, host.base)); } const history = histories.get(report.id); if (history) { - const files = await publishReportHistory({ gitDir: history.gitDir, publicDir, view: history.view }); + const files = await publishReportHistory({ gitDir: history.gitDir, publicDir, view: history.view, base: host.base }); log(`[reports] ${report.id}: revision ${history.ref.revision}, history published (${files.length} repository files).`); } } @@ -1010,12 +1057,15 @@ const defined = <T extends object>(o: T): T => // The site-root routes the reports add to a sitemap: the index, each report // (and its history page, when it has one), each moment page. -export function reportRoutes(composed: Pick<ComposedReports, "reports" | "moments" | "histories">): string[] { +export function reportRoutes( + composed: Pick<ComposedReports, "reports" | "moments" | "histories">, + base: ReportBase = SITE_REPORTS_BASE, +): string[] { if (composed.reports.length === 0) return []; const histories = new Set(composed.histories ?? []); return [ - "/reports/", - ...composed.reports.flatMap((r) => (histories.has(r.id) ? [r.href, reportHistoryPagePath(r.id)] : [r.href])), + base, + ...composed.reports.flatMap((r) => (histories.has(r.id) ? [r.href, reportHistoryPagePath(r.id, base)] : [r.href])), ...composed.moments.map((k) => momentPath(k)), ]; } diff --git a/common/publish/composeReportsArticles.test.ts b/common/publish/composeReportsArticles.test.ts @@ -179,15 +179,25 @@ test("a private build: every published article in index.json's order, any corpus const composed = await composeHostReports({ paths, host, publicDir: OUT, settings: X_PRIVATE, ...quiet }); assert.deepEqual(composed.reports.map((r) => r.id), ["art-priv", "art-pub"]); assert.deepEqual(composed.moments, [`${LONE}/abc123/10.00-20.00`, `${X}/1800`]); - const index = readJson<{ reports: { id: string }[] }>(path.join(OUT, "reports", "index.json")); - assert.deepEqual(index.reports.map((r) => r.id), ["art-priv", "art-pub"]); + // Served under the homepage's base, /articles/: its files and its links. + const index = readJson<{ reports: { id: string; href: string }[] }>(path.join(OUT, "articles", "index.json")); + assert.deepEqual(index.reports.map((r) => [r.id, r.href]), [ + ["art-priv", "/articles/art-priv/"], + ["art-pub", "/articles/art-pub/"], + ]); + const page = readJson<{ downloads?: { json?: string } }>(path.join(OUT, "articles", "art-pub", "page.json")); + assert.equal(page.downloads?.json, "/articles/art-pub/citations.json"); + assert.equal(existsSync(path.join(OUT, "reports")), false); assert.ok(existsSync(path.join(OUT, "media", "clips", LONE, "abc123", "10.00-20.00.mp4"))); assert.ok(existsSync(path.join(OUT, "media", "posts", X, "1800", "shot.png"))); // The draft is not published. - assert.equal(existsSync(path.join(OUT, "reports", "art-draft")), false); + assert.equal(existsSync(path.join(OUT, "articles", "art-draft")), false); // No archive named for the channel: the record links nowhere. - const moment = readJson<{ record: { corpusUrl?: string } }>(path.join(OUT, "m", LONE, "abc123", "10.00-20.00", "moment.json")); + const moment = readJson<{ record: { corpusUrl?: string }; citedIn: { href: string }[] }>( + path.join(OUT, "m", LONE, "abc123", "10.00-20.00", "moment.json"), + ); assert.equal(moment.record.corpusUrl, undefined); + assert.match(moment.citedIn[0].href, /^\/articles\/art-pub\//); // Feeds and history use the homepage's base (PROJECT_URL by default). assert.equal(host.siteUrl, "https://archilyzer.pages.dev"); // export/public is not this stage's output root here. @@ -204,8 +214,8 @@ test("a public build: only public articles; a record links into the listed site assert.deepEqual(composed.reports.map((r) => r.id), ["art-pub"]); // The earlier build's output is gone, the private article's post with it. assert.deepEqual( - filesUnder(OUT).filter((f) => !f.startsWith("reports/art-pub/")), - ["m/index.json", `m/${LONE}/abc123/10.00-20.00/moment.json`, `media/clips/${LONE}/abc123/10.00-20.00.mp4`, "reports/index.json"], + filesUnder(OUT).filter((f) => !f.startsWith("articles/art-pub/")), + ["articles/index.json", "m/index.json", `m/${LONE}/abc123/10.00-20.00/moment.json`, `media/clips/${LONE}/abc123/10.00-20.00.mp4`], ); const moment = readJson<{ record: { corpusUrl?: string } }>(path.join(OUT, "m", LONE, "abc123", "10.00-20.00", "moment.json")); assert.equal(moment.record.corpusUrl, `https://lone.example.test/?v=${encodeURIComponent(`${LONE}/abc123`)}&t=10`); diff --git a/common/publish/reportExports.ts b/common/publish/reportExports.ts @@ -106,6 +106,7 @@ import { import type { ReportMediaIndex } from "./reportMedia"; import { storeReportDir, storeReportFile } from "../lib/report/store"; import { siteReportHost, type ReportHost } from "./reportHost"; +import { isReportBase } from "../lib/report/routes"; import { commitReportRevision, pendingRevision, @@ -320,7 +321,7 @@ function within(base: string, rel: string): string | undefined { } function reportFiles(host: ReportHost, view: ReportPageView, resolved: ResolvedSiteReports): ReportFiles { - const own = `/reports/${view.id}/`; + const own = `${host.base}${view.id}/`; return { local: (p) => { if (p.startsWith(own)) return within(storeReportDir(host, view.id), p.slice(own.length)); @@ -340,8 +341,12 @@ function reportFiles(host: ReportHost, view: ReportPageView, resolved: ResolvedS // A site-root path's place in the evidence pack: the site's media under // media/, the report's own files (its stills) under media/report/. function packPathOf(view: ReportPageView, sitePath: string): string | undefined { - const own = `/reports/${view.id}/`; - if (sitePath.startsWith(own)) return `media/report/${sitePath.slice(own.length)}`; + // The report's own files are under its base (a site's /reports/, the + // homepage's /articles/): `<base><id>/…`. + const at = sitePath.indexOf(`/${view.id}/`); + if (at >= 0 && isReportBase(sitePath.slice(0, at + 1))) { + return `media/report/${sitePath.slice(at + view.id.length + 2)}`; + } if (sitePath.startsWith("/media/")) return sitePath.slice(1); return undefined; } diff --git a/common/publish/reportHistory.ts b/common/publish/reportHistory.ts @@ -73,6 +73,7 @@ import { cleanGitEnv } from "./sourceAudit"; export { REPORT_HISTORY_REPO_FILE_RE }; import { siteReportDir } from "./reportMedia"; import { storeReportDir, type ReportStore } from "../lib/report/store"; +import type { ReportBase } from "../lib/report/routes"; export const REPORT_HISTORY_GIT_DIRNAME = "history-git"; export const REVISION_EXPORTS_FILENAME = "exports.json"; @@ -359,7 +360,7 @@ function emptyReport(like: Report): Report { // no revisions. `clone` is what `git clone` takes. export async function readReportHistoryView( gitDir: string, - o: { reportId: string; siteUrl?: string }, + o: { reportId: string; siteUrl?: string; base?: ReportBase }, ): Promise<ReportHistoryView | null> { const stored = await readStoredRevisions(gitDir); if (stored.length === 0) return null; @@ -380,7 +381,7 @@ export async function readReportHistoryView( prev = report; } const base = o.siteUrl?.trim().replace(/\/+$/, ""); - const repo = reportHistoryRepoPath(o.reportId); + const repo = reportHistoryRepoPath(o.reportId, o.base); return { format: REPORT_HISTORY_FORMAT, version: REPORT_HISTORY_VERSION, @@ -395,12 +396,16 @@ export async function readReportHistoryView( // What the report's page shows: the newest revision, current when the // report.json now is that revision's. -export function reportHistoryRef(view: ReportHistoryView, currentSha256: string | null): ReportHistoryRef { +export function reportHistoryRef( + view: ReportHistoryView, + currentSha256: string | null, + base?: ReportBase, +): ReportHistoryRef { const last = view.revisions[view.revisions.length - 1]; return { revision: last.revision, date: last.date, - href: reportHistoryPagePath(view.reportId), + href: reportHistoryPagePath(view.reportId, base), current: currentSha256 === last.reportSha256, }; } @@ -457,16 +462,18 @@ export async function stageReportHistoryRepo(gitDir: string, destDir: string): P } // Publish a report's history under `publicDir`: history.json and the clone, -// at `reports/<id>/history/`. Answers the clone's files. +// at `<base><id>/history/` (`reports/<id>/history/` for a site). Answers the +// clone's files. export async function publishReportHistory(o: { gitDir: string; publicDir: string; view: ReportHistoryView; + base?: ReportBase; }): Promise<string[]> { - const viewFile = path.join(o.publicDir, ...reportHistoryViewPath(o.view.reportId).split("/").filter(Boolean)); + const viewFile = path.join(o.publicDir, ...reportHistoryViewPath(o.view.reportId, o.base).split("/").filter(Boolean)); await mkdir(path.dirname(viewFile), { recursive: true }); await writeFile(viewFile, `${JSON.stringify(o.view, null, 2)}\n`); - const repoDir = path.join(o.publicDir, ...reportHistoryRepoPath(o.view.reportId).split("/").filter(Boolean)); + const repoDir = path.join(o.publicDir, ...reportHistoryRepoPath(o.view.reportId, o.base).split("/").filter(Boolean)); return stageReportHistoryRepo(o.gitDir, repoDir); } diff --git a/common/publish/reportHost.ts b/common/publish/reportHost.ts @@ -37,9 +37,14 @@ import { } from "../lib/siteSchema"; import { publishedArticleIds } from "../lib/report/registry"; import { isReportId, type ReportAudience } from "../lib/report/schema"; +import { ARTICLES_BASE, SITE_REPORTS_BASE, type ReportBase } from "../lib/report/routes"; import { articleReportStore, siteReportStore, storeReportFile, type ReportStore } from "../lib/report/store"; export type ReportHost = ReportStore & { + // Where the build serves these reports (lib/report/routes.ts): a site's + // SITE_REPORTS_BASE, the homepage's ARTICLES_BASE. Every path compose + // writes and every link it builds hangs off it. + base: ReportBase; // A history commit's author (./reportHistory.ts) and an export's heading. title: string; // The public base a feed, an export's links and the history clone use @@ -68,6 +73,7 @@ export function siteReportHost(paths: Pick<Paths, "sitesDir" | "exportSitesIndex const cited = isCitedSite(site); return { ...siteReportStore(paths, site.siteId), + base: SITE_REPORTS_BASE, title: site.siteTitle?.trim() || site.siteId, siteUrl: parseSiteUrl(site.siteUrl), accent: site.accent, @@ -110,6 +116,7 @@ export async function articlesReportHost( const isChannel = new Map<string, boolean>(); return { ...articleReportStore(paths), + base: ARTICLES_BASE, title: PROJECT_NAME, siteUrl: opts.siteUrl === null ? undefined : (parseSiteUrl(opts.siteUrl ?? PROJECT_URL) ?? undefined), audience, diff --git a/homepage/app/articles/[reportId]/history/page.tsx b/homepage/app/articles/[reportId]/history/page.tsx @@ -0,0 +1,36 @@ +import type { Metadata } from "next"; +import { REPORT_PLACEHOLDER_ID, reportFullTitle } from "yt-dlp-transcript-common/lib/report/views"; +import ReportHistory from "yt-dlp-transcript-common/components/report/ReportHistory"; +import { EmptyState } from "yt-dlp-transcript-common/components/report/parts"; +import { PageShell } from "../../../components/PageShell"; +import { ARTICLES_ROUTE_BASE, articleIds, readArticleHistory } from "../../../lib/articles"; + +// /articles/<id>/history/: the article's revisions, from +// /articles/<id>/history/history.json; one with none published says so. +export const dynamicParams = false; + +export function generateStaticParams(): { reportId: string }[] { + const ids = articleIds(); + return (ids.length > 0 ? ids : [REPORT_PLACEHOLDER_ID]).map((reportId) => ({ reportId })); +} + +type Params = { params: Promise<{ reportId: string }> }; + +export async function generateMetadata({ params }: Params): Promise<Metadata> { + const view = readArticleHistory((await params).reportId); + if (!view) return { title: "No history" }; + return { title: `Revision history — ${reportFullTitle(view)}` }; +} + +export default async function ArticleHistoryPage({ params }: Params) { + const view = readArticleHistory((await params).reportId); + return ( + <PageShell> + {view ? ( + <ReportHistory view={view} base={ARTICLES_ROUTE_BASE} /> + ) : ( + <EmptyState title="No history">This article has no published revision history.</EmptyState> + )} + </PageShell> + ); +} diff --git a/homepage/app/articles/[reportId]/page.tsx b/homepage/app/articles/[reportId]/page.tsx @@ -0,0 +1,37 @@ +import type { Metadata } from "next"; +import { REPORT_PLACEHOLDER_ID } from "yt-dlp-transcript-common/lib/report/views"; +import ReportArticle from "yt-dlp-transcript-common/components/report/ReportArticle"; +import { EmptyState } from "yt-dlp-transcript-common/components/report/parts"; +import { PageShell } from "../../components/PageShell"; +import { ARTICLES_ROUTE_BASE, articleIds, readArticleView, reportMetadata } from "../../lib/articles"; + +// /articles/<id>/: one article, from /articles/<id>/page.json. Static: every +// article the build carries, nothing else; with none, the one placeholder page +// (a static export refuses an empty generateStaticParams), which says so. +export const dynamicParams = false; + +export function generateStaticParams(): { reportId: string }[] { + const ids = articleIds(); + return (ids.length > 0 ? ids : [REPORT_PLACEHOLDER_ID]).map((reportId) => ({ reportId })); +} + +type Params = { params: Promise<{ reportId: string }> }; + +export async function generateMetadata({ params }: Params): Promise<Metadata> { + const view = readArticleView((await params).reportId); + if (!view) return { title: "No articles" }; + return reportMetadata(view); +} + +export default async function ArticlePage({ params }: Params) { + const view = readArticleView((await params).reportId); + return ( + <PageShell> + {view ? ( + <ReportArticle view={view} base={ARTICLES_ROUTE_BASE} /> + ) : ( + <EmptyState title="No articles">No article has been published yet.</EmptyState> + )} + </PageShell> + ); +} diff --git a/homepage/app/articles/page.tsx b/homepage/app/articles/page.tsx @@ -0,0 +1,20 @@ +import type { Metadata } from "next"; +import ReportIndex from "yt-dlp-transcript-common/components/report/ReportIndex"; +import { PageShell } from "../components/PageShell"; +import { readArticleIndex } from "../lib/articles"; + +export const metadata: Metadata = { title: "Articles" }; + +// /articles/: every article this build carries, in the article store's order +// (reports/index.json). An honest empty index on a tree with none. +export default function ArticlesPage() { + return ( + <PageShell> + <ReportIndex + index={readArticleIndex()} + heading="Articles" + empty={{ title: "No articles", message: "No article has been published yet." }} + /> + </PageShell> + ); +} diff --git a/homepage/app/components/Header.tsx b/homepage/app/components/Header.tsx @@ -32,7 +32,7 @@ function NavList({ className }: { className?: string }) { ); } -// The project site's header: a hairline bar with the wordmark and the four +// The project site's header: a hairline bar with the wordmark and the five // destinations (Changelog is in the footer only; lib/nav.ts). It carried NO // links at all before this — the page it sat above was the whole site. // @@ -123,7 +123,10 @@ export default function Header() { </Link> <div className="ml-auto flex min-w-0 items-center gap-8"> <nav aria-label="Main" className="hidden md:block"> - <NavList className="gap-6" /> + {/* 16 px between links up to lg, 24 px from it: with five links + (Articles, release 26) the 768 px bar holds the wordmark, the + nav and a three-link row only so. */} + <NavList className="gap-4 lg:gap-6" /> </nav> <div className="flex min-w-0 items-center"> {narrow > 0 && ( @@ -151,7 +154,7 @@ export default function Header() { </div> </div> {/* Below `md` the nav drops to its own rule rather than collapsing behind - a menu button — four links do not earn a disclosure widget, and they + a menu button — five links do not earn a disclosure widget, and they fit a 320 px rule. Only one of the two navs is ever in the accessibility tree (the other is display:none), but they carry distinct labels so a test or a screen reader can never conflate them. diff --git a/homepage/app/lib/articles.test.ts b/homepage/app/lib/articles.test.ts @@ -0,0 +1,32 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { articlesPublicDir } from "./articles"; +import { FOOTER_NAV, HEADER_NAV } from "./nav"; + +// Run with: pnpm --filter homepage test +// +// Where /articles/ reads (release 26 A3): public/, or the e2e fixture outside a +// production build while it holds an index; and the nav names it always. + +test("the fixture dir is read only outside a production build, and only while it holds an article index", () => { + const fixture = fs.mkdtempSync(path.join(os.tmpdir(), "homepage-articles-")); + try { + const env = { E2E_ARTICLES_PUBLIC_DIR: fixture }; + assert.equal(articlesPublicDir(env, "/pub"), "/pub", "no index yet"); + fs.mkdirSync(path.join(fixture, "articles")); + fs.writeFileSync(path.join(fixture, "articles", "index.json"), "{}"); + assert.equal(articlesPublicDir(env, "/pub"), fixture); + assert.equal(articlesPublicDir({ ...env, NODE_ENV: "production" }, "/pub"), "/pub"); + assert.equal(articlesPublicDir({}, "/pub"), "/pub"); + } finally { + fs.rmSync(fixture, { recursive: true, force: true }); + } +}); + +test("Articles is in the header and the footer, unconditionally", () => { + assert.ok(HEADER_NAV.some((n) => n.href === "/articles/" && n.label === "Articles")); + assert.ok(FOOTER_NAV.some((n) => n.href === "/articles/")); +}); diff --git a/homepage/app/lib/articles.ts b/homepage/app/lib/articles.ts @@ -0,0 +1,45 @@ +import fs from "node:fs"; +import path from "node:path"; +import { createReportReader, reportMetadata } from "yt-dlp-transcript-common/lib/report/reader-server"; +import { ARTICLES_BASE } from "yt-dlp-transcript-common/lib/report/routes"; + +// THE ARTICLES (release 26 A3): the reports the project homepage publishes, +// read by the shared reader (common/lib/report/reader-server.ts) under +// /articles/ from what `compose homepage` wrote into public/ — articles/, +// m/ and media/, through the same reports stage a site's compose runs +// (publish/composeReports.ts over publish/reportHost.ts articlesReportHost). +// +// A build:nodata tree has none: every reader answers "none", /articles/ +// renders its empty index and the nav stays unconditional (./nav.ts). +// +// E2E_ARTICLES_PUBLIC_DIR names a fixture public dir to read instead — but +// ONLY outside a production build, and only while it holds an article index +// (the source.ts rule): `next build` runs with NODE_ENV=production. +export function articlesPublicDir( + env: Readonly<Record<string, string | undefined>> = process.env, + publicDir: string = path.join(/* turbopackIgnore: true */ process.cwd(), "public"), +): string { + const fixture = env.NODE_ENV !== "production" ? env.E2E_ARTICLES_PUBLIC_DIR : undefined; + if (fixture && fs.existsSync(path.join(/* turbopackIgnore: true */ fixture, "articles", "index.json"))) return fixture; + return publicDir; +} + +const reader = createReportReader({ publicDir: () => articlesPublicDir(), base: ARTICLES_BASE }); + +export const ARTICLES_ROUTE_BASE = reader.base; +export const readArticleIndex = () => reader.readReportIndex(); +export const articleIds = () => reader.reportIds(); +export const readArticleView = (id: string) => reader.readReportView(id); +export const readArticleHistory = (id: string) => reader.readReportHistory(id); +export const momentKeys = () => reader.momentKeys(); +export const readMomentView = (key: string) => reader.readMomentView(key); + +// The newest few, for the home page: the index's order is the operator's +// (reports/index.json), so "latest" is by date, newest first. +export function latestArticles(n: number) { + const reports = readArticleIndex()?.reports ?? []; + const at = (r: { updated?: string; published?: string }) => Date.parse(r.updated ?? r.published ?? "") || 0; + return [...reports].sort((a, b) => at(b) - at(a)).slice(0, n); +} + +export { reportMetadata }; diff --git a/homepage/app/lib/nav.ts b/homepage/app/lib/nav.ts @@ -1,13 +1,14 @@ // The site's navigation, declared once. Order is editorial: what the software // is, where its code lives, how to get it, what this deployment has done, what -// changed. +// it has published (the articles, release 26), what changed. // // HEADER_NAV the header's links; // FOOTER_NAV the footer's "Sections" and the 404 page: the header's links, // then Changelog, which is in the footer only. // // Every entry must resolve on a `build:nodata` tree — /stats/ renders an honest -// no-data panel and /source/ an honest "nothing published" rather than 404ing — +// no-data panel, /source/ an honest "nothing published" and /articles/ an +// honest empty index rather than 404ing — // so the nav never has to be conditional. export type NavItem = { href: string; label: string }; @@ -16,6 +17,7 @@ export const HEADER_NAV: readonly NavItem[] = [ { href: "/source/", label: "Source" }, { href: "/downloads/", label: "Downloads" }, { href: "/stats/", label: "Stats" }, + { href: "/articles/", label: "Articles" }, ]; export const FOOTER_NAV: readonly NavItem[] = [ diff --git a/homepage/app/m/[...moment]/page.tsx b/homepage/app/m/[...moment]/page.tsx @@ -0,0 +1,43 @@ +import type { Metadata } from "next"; +import { MOMENT_PLACEHOLDER_KEY } from "yt-dlp-transcript-common/lib/report/views"; +import MomentArticle from "yt-dlp-transcript-common/components/report/MomentArticle"; +import { EmptyState } from "yt-dlp-transcript-common/components/report/parts"; +import { PageShell } from "../../components/PageShell"; +import { momentKeys, readMomentView } from "../../lib/articles"; + +// /m/<channel>/<id>/<start>-<end>/ (a span) and /m/<channel>/<id>/ (a post): +// one moment the articles cite, from /m/<key>/moment.json. Its record opens in +// the listed public archive that publishes the channel — compose wrote that +// absolute link into the view — or nowhere. Static: with none, one placeholder. +export const dynamicParams = false; + +export function generateStaticParams(): { moment: string[] }[] { + const keys = momentKeys(); + return (keys.length > 0 ? keys : [MOMENT_PLACEHOLDER_KEY]).map((k) => ({ moment: k.split("/") })); +} + +type Params = { params: Promise<{ moment: string[] }> }; + +async function keyOf(params: Params["params"]): Promise<string> { + return (await params).moment.map((s) => decodeURIComponent(s)).join("/"); +} + +export async function generateMetadata({ params }: Params): Promise<Metadata> { + const view = readMomentView(await keyOf(params)); + if (!view) return { title: "No moments" }; + const who = view.record.title ?? view.record.channelTitle ?? view.record.channel; + return { title: `“${view.quote.length > 60 ? `${view.quote.slice(0, 57)}…` : view.quote}” — ${who}` }; +} + +export default async function MomentPage({ params }: Params) { + const view = readMomentView(await keyOf(params)); + return ( + <PageShell> + {view ? ( + <MomentArticle view={view} /> + ) : ( + <EmptyState title="No moments">No article cites a moment yet.</EmptyState> + )} + </PageShell> + ); +} diff --git a/homepage/app/page.tsx b/homepage/app/page.tsx @@ -4,6 +4,7 @@ import { FamilyStats } from "./components/FamilyStats"; import { ArchiveCards } from "./components/ArchiveCards"; import { loadSummary } from "./lib/summary"; import { currentHomepage } from "./lib/homepage"; +import { latestArticles } from "./lib/articles"; // The project's front page. It says what Archilyzer is, shows what it has // built, and offers the download. @@ -15,7 +16,8 @@ import { currentHomepage } from "./lib/homepage"; // Copy rules, kept deliberately: short declarative sentences, no eyebrow over // every band, no subtitles under the headings or the cards, headings in Title // Case (the hub shelf matches). The page has two headings after -// the H1 and both name what is under them. +// the H1 and both name what is under them, and a third, Latest Articles, when +// the build carries any (release 26: the newest three, linking /articles/). const CONTAINER = "w-full max-w-6xl mx-auto px-5 sm:px-6"; @@ -32,6 +34,7 @@ export default function Home() { // The URL comes from homepage.json (the hub's own build reads it too). const HUB_LINK_ENABLED = false; const hubUrl = HUB_LINK_ENABLED ? (currentHomepage().siteUrl ?? null) : null; + const articles = latestArticles(3); return ( <> @@ -126,6 +129,37 @@ export default function Home() { </section> )} + {/* ── Latest Articles ──────────────────────────────────────────────── */} + {articles.length > 0 && ( + <section data-latest-articles="" className="border-t border-[var(--border)]"> + <div className={`${CONTAINER} py-14 sm:py-20`}> + <h2 className="mb-8 font-display text-2xl font-semibold text-[var(--foreground)]"> + Latest Articles + </h2> + <ul className="flex max-w-3xl flex-col gap-5"> + {articles.map((a) => ( + <li key={a.id} className="flex flex-col gap-1"> + {a.series && <span className="label-machine">{a.series}</span>} + <Link + href={a.href} + className="font-display text-lg font-semibold text-[var(--foreground)] underline decoration-[var(--border-strong)] underline-offset-4 hover:decoration-[var(--foreground)]" + > + {a.title} + </Link> + {a.subtitle && <span className="text-[var(--muted-foreground)]">{a.subtitle}</span>} + </li> + ))} + </ul> + <Link + href="/articles/" + className="mt-8 inline-block text-[var(--foreground)] underline decoration-[var(--border-strong)] underline-offset-4 hover:decoration-[var(--foreground)]" + > + All articles + </Link> + </div> + </section> + )} + {/* ── What It Does ─────────────────────────────────────────────────── */} {/* Three short paragraphs, not three titled panels: without titles, three one-sentence items read as prose, not as a feature grid. */} diff --git a/homepage/e2e/articles.spec.ts b/homepage/e2e/articles.spec.ts @@ -0,0 +1,67 @@ +import path from "node:path"; +import { test, expect } from "@playwright/test"; +import { + FIXTURE_ARCHIVE_URL, + FIXTURE_ARTICLES_NAME, + FIXTURE_ARTICLE_ID, + FIXTURE_LINKED_MOMENT, + clearFixtureArticles, + writeFixtureArticles, +} from "./fixture-articles"; + +// The homepage's articles (release 26 A3): the nav's Articles, /articles/ and +// an article, its moments — one opening in the listed archive that publishes +// its channel, one in none — and the home page's Latest Articles. The fixture +// (e2e/fixture-articles.ts) is written for this file and removed after it; the +// empty index is checked with it gone. + +const DIR = () => path.resolve(test.info().project.testDir, FIXTURE_ARTICLES_NAME); + +test.describe.configure({ mode: "serial" }); + +test("with none, /articles/ is an honest empty index and the home page names no article", async ({ page }) => { + clearFixtureArticles(DIR()); + const res = await page.goto("/articles/"); + expect(res?.status()).toBe(200); + await expect(page.getByText("No articles", { exact: true })).toBeVisible(); + await page.goto("/"); + await expect(page.locator("[data-latest-articles]")).toHaveCount(0); +}); + +test.describe("with articles", () => { + test.beforeAll(() => writeFixtureArticles(DIR())); + test.afterAll(() => clearFixtureArticles(DIR())); + + test("the nav's Articles opens the index; an article reads under /articles/", async ({ page }) => { + await page.goto("/"); + await page.getByRole("navigation", { name: "Main", exact: true }).getByRole("link", { name: "Articles" }).click(); + await expect(page).toHaveURL(/\/articles\/$/); + const card = page.locator("[data-report-index] a").first(); + await expect(card).toHaveAttribute("href", `/articles/${FIXTURE_ARTICLE_ID}/`); + await card.click(); + await expect(page).toHaveURL(new RegExp(`/articles/${FIXTURE_ARTICLE_ID}/$`)); + await expect(page.getByRole("heading", { level: 1 })).toContainText("Checking an example article"); + // Its downloads and history hang off the same base. + await expect(page.locator(`a[href="/articles/${FIXTURE_ARTICLE_ID}/citations.json"]`).first()).toBeAttached(); + }); + + test("a moment opens in the listed archive that publishes its channel, or in none", async ({ page }) => { + await page.goto(`/m/${FIXTURE_LINKED_MOMENT}/`); + await expect(page.getByRole("link", { name: "Open in the archive" })).toHaveAttribute( + "href", + new RegExp(`^${FIXTURE_ARCHIVE_URL.replace(/\./g, "\\.")}/\\?v=`), + ); + const res = await page.goto("/m/demo-podcast/ep-042/610.50-628.00/"); + expect(res?.status()).toBe(200); + await expect(page.getByText("Like I said before, spring twenty nineteen.", { exact: false }).first()).toBeVisible(); + await expect(page.getByRole("link", { name: "Open in the archive" })).toHaveCount(0); + }); + + test("the home page shows the latest articles and links them all", async ({ page }) => { + await page.goto("/"); + const latest = page.locator("[data-latest-articles]"); + await expect(latest.getByRole("heading", { name: "Latest Articles" })).toBeVisible(); + await expect(latest.locator(`a[href="/articles/${FIXTURE_ARTICLE_ID}/"]`)).toBeVisible(); + await expect(latest.getByRole("link", { name: "All articles" })).toHaveAttribute("href", "/articles/"); + }); +}); diff --git a/homepage/e2e/fixture-articles.ts b/homepage/e2e/fixture-articles.ts @@ -0,0 +1,61 @@ +import fs from "node:fs"; +import path from "node:path"; + +// A FIXTURE ARTICLE PUBLISH for /articles/ and /m/ (release 26 A3). The pages +// read the directory E2E_ARTICLES_PUBLIC_DIR names instead of public/ while it +// holds articles/index.json (app/lib/articles.ts, honoured only outside a +// production build), so a spec shows them with articles whatever this checkout +// has composed. e2e/articles.spec.ts writes it and removes it after: with it +// gone, /articles/ is the honest empty index again (no-data and marketing read +// that). playwright.config.ts clears it before the server starts. +// +// Its data is export's report-site fixture (export/fixtures/report-site/ +// public: the view JSON compose writes), as compose writes it for the homepage: +// under /articles/ rather than /reports/, and one moment opening in the listed +// public archive that publishes its channel (an absolute corpusUrl) — the +// others in none. The binary media is not copied: nothing here is served. + +export const FIXTURE_ARTICLES_NAME = ".e2e-articles"; +export const FIXTURE_ARTICLE_ID = "demo-factcheck"; +export const FIXTURE_ARCHIVE_URL = "https://archive.example.test"; +export const FIXTURE_LINKED_MOMENT = "demo-channel/abc123/3126.00-3151.00"; + +// Resolved from the cwd, as playwright.config.ts resolves the fixtures: the suite runs in homepage/. +const SOURCE = path.resolve(process.cwd(), "..", "export", "fixtures", "report-site", "public"); + +function copyJson(from: string, to: string, edit?: (v: Record<string, unknown>) => void): void { + const text = fs.readFileSync(from, "utf8").replaceAll('"/reports/', '"/articles/'); + const value = JSON.parse(text) as Record<string, unknown>; + edit?.(value); + fs.mkdirSync(path.dirname(to), { recursive: true }); + fs.writeFileSync(to, JSON.stringify(value, null, 2)); +} + +function walk(dir: string, rel = ""): string[] { + const out: string[] = []; + for (const e of fs.readdirSync(dir, { withFileTypes: true })) { + const r = rel ? `${rel}/${e.name}` : e.name; + if (e.isDirectory()) out.push(...walk(path.join(dir, e.name), r)); + else if (e.name.endsWith(".json")) out.push(r); + } + return out; +} + +export function writeFixtureArticles(dest: string): void { + clearFixtureArticles(dest); + for (const rel of walk(path.join(SOURCE, "reports"))) { + copyJson(path.join(SOURCE, "reports", rel), path.join(dest, "articles", rel)); + } + for (const rel of walk(path.join(SOURCE, "m"))) { + copyJson(path.join(SOURCE, "m", rel), path.join(dest, "m", rel), (v) => { + if (rel === `${FIXTURE_LINKED_MOMENT}/moment.json`) { + const record = v.record as Record<string, unknown>; + record.corpusUrl = `${FIXTURE_ARCHIVE_URL}/?v=demo-channel%2Fabc123&t=3126`; + } + }); + } +} + +export function clearFixtureArticles(dest: string): void { + fs.rmSync(dest, { recursive: true, force: true }); +} diff --git a/homepage/e2e/marketing.spec.ts b/homepage/e2e/marketing.spec.ts @@ -38,15 +38,15 @@ test("the hub link, when there is one, leaves for the hub", async ({ page }) => await expect(hub).toHaveAttribute("href", /^https?:\/\/[^/]/); }); -// The header carries four destinations; the footer's "Sections" carries the -// same four and Changelog, which is in the footer only (app/lib/nav.ts). -const HEADER_LINKS = ["Docs", "Source", "Downloads", "Stats"]; +// The header carries five destinations; the footer's "Sections" carries the +// same five and Changelog, which is in the footer only (app/lib/nav.ts). +const HEADER_LINKS = ["Docs", "Source", "Downloads", "Stats", "Articles"]; const FOOTER_LINKS = [...HEADER_LINKS, "Changelog"]; const linkNames = (nav: import("@playwright/test").Locator) => nav.getByRole("link").evaluateAll((els) => els.map((e) => e.textContent?.trim())); -test("the header nav has four links and no Changelog; the footer's has five", async ({ +test("the header nav has five links and no Changelog; the footer's has six", async ({ page, }) => { for (const width of [360, 1280]) { @@ -60,7 +60,7 @@ test("the header nav has four links and no Changelog; the footer's has five", as }); test("Changelog is reachable from the footer on every page", async ({ page }) => { - for (const path of ["/", "/docs/", "/source/", "/downloads/", "/stats/", "/changelog/", "/no-such-page/"]) { + for (const path of ["/", "/docs/", "/source/", "/downloads/", "/stats/", "/articles/", "/changelog/", "/no-such-page/"]) { await page.goto(path); await expect( page.getByRole("navigation", { name: "Footer" }).getByRole("link", { name: "Changelog" }), @@ -78,6 +78,7 @@ test("every nav destination resolves", async ({ page }) => { ["Source", "/source/"], ["Downloads", "/downloads/"], ["Stats", "/stats/"], + ["Articles", "/articles/"], ["Changelog", "/changelog/"], ]) { const res = await page.request.get(path); diff --git a/homepage/playwright.config.ts b/homepage/playwright.config.ts @@ -12,6 +12,7 @@ import { writeFixtureSettings, } from "./e2e/fixture-social"; import { FIXTURE_SOURCE_NAME, clearFixtureSource } from "./e2e/fixture-source"; +import { FIXTURE_ARTICLES_NAME, clearFixtureArticles } from "./e2e/fixture-articles"; // Homepage e2e. Runs against `next dev` (default mode) so it reflects uncommitted // source. Kill any stale dev server on the port between runs. @@ -45,6 +46,12 @@ import { FIXTURE_SOURCE_NAME, clearFixtureSource } from "./e2e/fixture-source"; // a production build). e2e/source-history.spec.ts // writes a fixture publish there and removes it; // empty, the page reads public/ +// E2E_ARTICLES_PUBLIC_DIR set below on the dev server: the directory +// /articles/ and /m/ read WHILE it holds +// articles/index.json (app/lib/articles.ts, +// ignored by a production build). +// e2e/articles.spec.ts writes a fixture there +// (e2e/fixture-articles.ts) and removes it const PORT = portFor("HOMEPAGE_E2E_PORT"); const baseURL = `http://localhost:${PORT}`; @@ -68,6 +75,10 @@ fs.mkdirSync(FIXTURE_SITES_DIR, { recursive: true }); const FIXTURE_SOURCE_DIR = path.resolve(process.cwd(), "e2e", FIXTURE_SOURCE_NAME); clearFixtureSource(FIXTURE_SOURCE_DIR); +// The fixture articles: none until e2e/articles.spec.ts writes them. +const FIXTURE_ARTICLES_DIR = path.resolve(process.cwd(), "e2e", FIXTURE_ARTICLES_NAME); +clearFixtureArticles(FIXTURE_ARTICLES_DIR); + // E2E_MODE (start | dev), the editor's and umtool's switch: those suites // default to `start`, a production build the stamp vouches for // (scripts/e2e-stamp.mjs). This suite always runs under `next dev`: the homepage is a @@ -116,6 +127,7 @@ export default defineConfig({ SETTINGS_FILE: FIXTURE_SETTINGS, SITES_DIR: FIXTURE_SITES_DIR, E2E_SOURCE_PUBLIC_DIR: FIXTURE_SOURCE_DIR, + E2E_ARTICLES_PUBLIC_DIR: FIXTURE_ARTICLES_DIR, }, }, use: {