testPageLinksInTheAppAndStatically

tcmts.site.testPageLinksInTheAppAndStatically · #yii25wqj · term

A page links to the others by their files in the static site, and by paths without .html in the app (which renders only those on the server); code is highlighted, and a link to nothing is a problem.

import { highlighter, hrefFor, renderPage } from "#codebase/tcmts/site";
import assert from "node:assert/strict";

export const testPageLinksInTheAppAndStatically = async () => {
  const pages = [
    { src: "docs/README.md", file: "index.html", label: "index", n: 0 },
    { src: "docs/apps.md", file: "apps.html", label: "web apps", n: 1 },
  ];
  const md = "# Index\n\n## Start here\n\nSee [apps](apps.md#how), [nowhere](gone.md) and `code`.\n\n```ts\nconst x = 1;\n```\n";
  const hl = await highlighter();
  const live = renderPage(pages[0]!, pages, md, hl, () => false, true);
  assert.match(live.html, /<a href="apps#how">apps<\/a>/);
  assert.match(live.html, /class="shiki/);
  assert.deepEqual(live.toc, [{ id: "start-here", text: "Start here", num: "0.1" }]);
  assert.deepEqual(live.problems, ["link to gone.md: no such page"]);
  assert.match(renderPage(pages[0]!, pages, md, hl, () => false, false).html, /<a href="apps\.html#how">apps<\/a>/);
  assert.equal(hrefFor("index.html", true), "./");
  assert.equal(hrefFor("apps.html", true), "apps");
  assert.equal(hrefFor("apps.html", false), "apps.html");
}

uses