From 012686999c878793c1d01ee9ca6e4833274f7f1f Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Mon, 26 Oct 2026 13:34:43 -0400 Subject: [PATCH] Docs: imported pages carry their source as front matter, and the build fails on raw syntax The importer put an MDX comment under each imported self-host page's front matter. Those pages are Markdown, so the comment printed under the title. It now writes source and sourceCommit front matter instead. check:output reads every built page's visible text (and each Markdown twin outside code) and fails on an MDX comment, a component tag printed as text, an escaped brace, an admonition marker or a double-escaped entity. --- docs/lib/source.ts | 3 ++ docs/scripts/check-output.mjs | 8 +++++ docs/scripts/import-platform.mjs | 5 ++- docs/scripts/import-platform.test.mjs | 11 +++++- docs/scripts/lib/raw-syntax.mjs | 48 +++++++++++++++++++++++++++ docs/scripts/raw-syntax.test.mjs | 33 ++++++++++++++++++ 6 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 docs/scripts/lib/raw-syntax.mjs create mode 100644 docs/scripts/raw-syntax.test.mjs diff --git a/docs/lib/source.ts b/docs/lib/source.ts index bc27addc..60e79a38 100644 --- a/docs/lib/source.ts +++ b/docs/lib/source.ts @@ -20,6 +20,9 @@ export const frontmatterSchema = pageSchema.extend({ editUrl: z.string().url().optional(), /** Written by a build script; the edit link goes to the script's source. */ generated: z.boolean().optional(), + /** Imported pages: the file they come from (repo/path) and the commit it was read at. */ + source: z.string().optional(), + sourceCommit: z.string().optional(), }); const docs = defineDocs({ diff --git a/docs/scripts/check-output.mjs b/docs/scripts/check-output.mjs index ca9846ce..d1c8c0b0 100644 --- a/docs/scripts/check-output.mjs +++ b/docs/scripts/check-output.mjs @@ -7,6 +7,9 @@ // - sitemap.xml lists every page; robots.txt points at it // - the plugin manifest schema and the bundled validator are published // - a 404 page exists +// - no page shows raw source syntax as text: an MDX comment, a component +// tag printed instead of rendered, an escaped brace or entity (and the +// Markdown twins carry none of it outside code) // - every page ever published (published-pages.json) is still a page or // has a redirect (redirects.json), and new pages are recorded @@ -16,6 +19,7 @@ import { fileURLToPath } from 'node:url'; import { files } from './lib/out.mjs'; import { checkMoves, exportedPages, readMoves } from './lib/moves.mjs'; import { proseProblems } from './lib/prose.mjs'; +import { markdownProse, rawSyntax, visibleText } from './lib/raw-syntax.mjs'; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const OUT = path.join(ROOT, 'out'); @@ -57,6 +61,9 @@ for (const segs of pages) { need(!/<\/?Diagram\b/.test(twin), `/${md}: a tag was not turned into text`); // Imported and generated pages follow the same rules as written ones. for (const p of proseProblems(twin, { allow: PROSE_ALLOW.filter((a) => twinOf(a.file) === md) })) need(false, `/${md}:${p.line}: ${p.rule}: ${p.text}`); + // Component tags stay in the twins on purpose (they read as structure); + // a comment, an escaped brace or a double-escaped entity never should. + for (const r of rawSyntax(markdownProse(twin)).filter((f) => f.rule !== 'jsx-tag')) need(false, `/${md}: raw ${r.rule} in the text: ${r.text}`); } if (llms) need(llms.includes(`(${SITE}/${md})`), `llms.txt: no link to /${md}`); if (sitemap) need(sitemap.includes(`${SITE}${url === '/' ? '/' : `${url}/`}`) || sitemap.includes(`${SITE}${url}`), `sitemap.xml: no ${url}`); @@ -65,6 +72,7 @@ for (const segs of pages) { const html = read(path.join(...(segs.length ? segs : ['.']), 'index.html')); need(html && / { const out = convertGuide('# Install on AWS\n\nDeploy CoderHelm into **your** account in one command.\n\n## Steps\n', 'docs/self-host/install.md', REF); - assert.match(out, /^---\ntitle: "Install on AWS"\ndescription: "Deploy CoderHelm into your account in one command."\neditUrl: "https:\/\/github.com\/CoderHelm\/coderhelm-platform\/blob\/main\/docs\/self-host\/install.md"\n---/); + assert.match(out, /^---\ntitle: "Install on AWS"\ndescription: "Deploy CoderHelm into your account in one command."\neditUrl: "https:\/\/github.com\/CoderHelm\/coderhelm-platform\/blob\/main\/docs\/self-host\/install.md"\nsource: "CoderHelm\/coderhelm-platform\/docs\/self-host\/install.md"\nsourceCommit: "[0-9a-f]{40}"\n---\n\n/); assert.ok(!out.includes('# Install on AWS'), 'the H1 becomes the page title, not a second heading'); assert.match(out, /## Steps/); }); @@ -30,3 +30,12 @@ test('guides are listed by their order front matter, the rest by name', () => { const order = new Map([['quick-start', 1], ['faq', 13], ['requirements', 2]]); assert.deepEqual(sortByOrder(['faq', 'zeta', 'quick-start', 'alpha', 'requirements'], order), ['quick-start', 'requirements', 'faq', 'alpha', 'zeta']); }); + +test('where a guide comes from is front matter, never a comment in the body (Markdown would print it)', () => { + const out = convertGuide('# Backups\n\nKeep a copy.\n', 'docs/self-host/backups.md', REF); + assert.match(out, /\nsource: "CoderHelm\/coderhelm-platform\/docs\/self-host\/backups.md"\n/); + assert.match(out, new RegExp(`\\nsourceCommit: "${REF}"\\n`)); + const body = out.slice(out.indexOf('\n---\n', 4) + 5); + assert.ok(!/\{\/\*|