]*\bopen\b/.test(article), 'Inline Contents must start collapsed');
if (name === 'abstract-and-section') assert(article.includes('href="#abstract">Abstract'));
}
const postFixture = readFileSync(join(temp, 'out/writing/post-test/index.html'), 'utf8');
assert(!postFixture.includes('/js/contents.'), 'Unsectioned article loads unused navigation');
assert(postFixture.includes('An italic subtitle for a post'), 'Post subtitle missing');
assert(postFixture.includes('katex-mathml'), 'Post math missing');
for (const article of [page, postFixture]) {
assert(article.includes('class="footnote-ref"'), 'Footnote reference missing');
assert(article.includes('class="footnote-backref"'), 'Footnote return link missing');
assert(article.includes('/js/footnotes.'), 'Footnote previews missing');
}
assert(postFixture.includes('A second paragraph'), 'Multi-paragraph footnote missing');
assert(postFixture.match(/class="footnote-ref"/g).length === 2, 'Repeated footnote references missing');
assert(!home.includes('/js/footnotes.'), 'Homepage loads unused footnote script');
const post = readFileSync(join(temp, 'out/writing/nodejs-workspaces/index.html'), 'utf8');
assert(!post.includes('katex.min.css'), 'Non-math post loads math assets');
const rss = readFileSync(join(temp, 'out/writing/rss.xml'), 'utf8');
assert(rss.includes('A “quoted” title'), 'RSS typography inconsistent');
for (const section of ['writing', 'writing/posts', 'writing/essays']) {
const description = readFileSync(`content/${section}/_index.md`, 'utf8').match(/^description: "(.*)"$/m)[1];
assert(
readFileSync(join(temp, `out/${section}/rss.xml`), 'utf8').includes(
`${description}`,
),
`${section}: RSS description ignored`,
);
}
assert(page.includes(''), 'Fenced code should use plain semantic markup');
assert(!page.includes('class="chroma"'), 'Unused syntax-token markup should not be generated');
for (const kind of ['posts', 'essays']) {
const archive = readFileSync(join(temp, `out/writing/${kind}/index.html`), 'utf8');
assert(archive.includes(`url=/#${kind}`), `Populated ${kind} archive should target its homepage section`);
}
for (const [shipped, upstream] of [
['static/licenses/katex.txt', 'node_modules/katex/LICENSE'],
['static/licenses/newsreader.txt', 'node_modules/@fontsource-variable/newsreader/LICENSE'],
])
assert.equal(readFileSync(shipped, 'utf8'), readFileSync(upstream, 'utf8'), `Outdated license: ${shipped}`);
const checks = join(temp, 'checks');
mkdirSync(checks);
const checkFile = join(checks, 'index.html');
writeFileSync(checkFile, 'Heading
Link');
checkSite(checks);
for (const [html, expected] of [
['Broken fragment', /missing fragment/],
['
', /broken asset or link/],
['', /duplicate id/],
['', /missing accessible control target/],
]) {
writeFileSync(checkFile, html);
assert.throws(() => checkSite(checks), expected);
}
const originalURL = process.env.SITE_BASE_URL;
try {
process.env.SITE_BASE_URL = 'https://alternate.example/';
assert.equal(siteBaseURL().href, process.env.SITE_BASE_URL);
writeFileSync(checkFile, 'Broken absolute link');
assert.throws(() => checkSite(checks), /broken asset or link/);
for (const url of [
'https://example.test/subpath/',
'file:///tmp/',
'https://example.test/?q=1',
'https://example.test/#hash',
'https://user:pass@example.test/',
]) {
process.env.SITE_BASE_URL = url;
assert.throws(siteBaseURL, /must be an HTTP\(S\) origin/);
}
} finally {
if (originalURL === undefined) delete process.env.SITE_BASE_URL;
else process.env.SITE_BASE_URL = originalURL;
}
const invalidFile = join(temp, 'content/writing/invalid.md');
for (const format of ['', 'format: typo\n']) {
writeFileSync(invalidFile, `---\ntitle: Invalid\ndate: 2026-01-01\n${format}---\nText.\n`);
const invalid = build();
assert.notEqual(invalid.status, 0, 'Invalid writing format must fail the build');
assert((invalid.stdout + invalid.stderr).includes('format must be post or essay'));
}
rmSync(invalidFile);
writeFileSync(
join(temp, 'content/writing/draft.md'),
'---\ntitle: Draft\ndate: 2026-01-01\nformat: post\ndraft: true\n---\nDraft text.\n',
);
assert.equal(build().status, 0);
assert(!existsSync(join(temp, 'out/writing/draft/index.html')), 'Draft leaked into the production build');
assert.equal(build('--buildDrafts').status, 0);
assert(existsSync(join(temp, 'out/writing/draft/index.html')), 'Draft preview omitted draft content');
console.log(
'Passed: math, equations, smart quotes, literal code, dates, subtitles, biography, filtered RSS, and conditional assets.',
);
} finally {
rmSync(temp, { recursive: true, force: true });
}