testBlogPostsRender
tcmts.site.testBlogPostsRender · #6khctrrs · function
import { highlighter, pageList, postDay, POSTS, renderPost, SOURCES } from "#codebase/tcmts/site";
import assert from "node:assert/strict";
export const testBlogPostsRender = async () => {
const hl = await highlighter();
const docs = new Set(pageList(SOURCES["docs/README.md"]!).map((p) => p.file));
for (const post of POSTS) {
const r = renderPost(post, hl, docs);
assert.deepEqual(r.problems, [], post.slug);
assert.ok(r.title && r.summary && r.description && post.author, post.slug);
assert.match(post.date, /^\d{4}-\d{2}-\d{2}$/);
assert.match(post.slug, /^[a-z0-9-]+$/);
}
// newest first
assert.deepEqual(
POSTS.map((p) => p.date),
POSTS.map((p) => p.date)
.toSorted()
.reverse(),
);
const bad = renderPost(
{ slug: "x", date: "2026-11-07", author: "a", md: "[a](/docs/nowhere.html) [b](other.md)" },
hl,
docs,
);
assert.equal(bad.problems.length, 3);
assert.equal(postDay("2026-11-07"), "7 November 2026");
// a definition, linked to its page in the code browser; the description is text
const linked = renderPost(
{
slug: "x",
date: "2026-11-07",
author: "a",
md: "# A `b` & c\n\nSee {@link tcmts.site.POSTS} & [the docs](/docs/apps.html).",
},
hl,
docs,
);
assert.equal(linked.title, "A b & c");
assert.match(linked.body, /<a href="\/docs\/code\/tcm\/site\/POSTS\.html" rel="external"/);
assert.equal(linked.description, "See POSTS & the docs.");
assert.doesNotMatch(linked.body, /<h1/);
}
uses