import { readFileSync } from "node:fs"; import { join } from "node:path"; import type { Hono } from "hono"; import { describeFile } from "../describe/describe.ts"; import { html } from "./html.ts"; import { cacheFor, type PageContext, page } from "./layout.ts"; import { renderParagraph, renderSiteMarkdown } from "./markdown.ts"; const SITE_DIR = join(import.meta.dir, "../../docs/site"); /** ยง21.10: `/docs` and `/support` are Markdown files in Kepr's repo, rendered once at startup. */ export function registerDocsPages(app: Hono, ctx: PageContext): void { for (const name of ["docs", "support"]) { const source = readFileSync(join(SITE_DIR, `${name}.md`), "utf8"); const intro = describeFile(`${name}.md`, source); const description = intro ? renderParagraph(intro, { repo: "", dir: "", at: null }).text : ""; const body = html`
${renderSiteMarkdown(source)}
`; app.get(`/${name}`, (c) => { cacheFor(c, false); return c.html(page(ctx, { title: name, description, path: `/${name}`, body })); }); } }