pageList

tcmts.site.pageList · #vpwye3jv · term · runs anywhere

The site's pages, in the order the index (docs/README.md) lists them: its ## headings are sections, the links in their tables pages.

import { resolvePath } from "#codebase/tcmts/site";
import type { Page } from "#codebase/tcmts/site";

export function pageList(index: string): Page[] {
  const pages: Page[] = [{ src: "docs/README.md", file: "index.html", label: "index", n: 0 }];
  let section: string | undefined;
  for (const line of index.split("\n")) {
    const h = /^## (.+)$/.exec(line);
    if (h) section = h[1]!.trim();
    const m = /^\| \[([^\]]+)\]\(([^)]+)\) \|/.exec(line);
    if (!m) continue;
    const src = resolvePath("docs", m[2]!);
    const name = src === "examples/README.md" ? "examples" : src.slice(src.lastIndexOf("/") + 1).replace(/\.md$/, "");
    pages.push({ src, file: `${name}.html`, label: m[1]!.toLowerCase(), n: pages.length, ...(section ? { section } : {}) });
  }
  return pages;
}

uses

used by