2025-01-22 09:03:37 +01:00
|
|
|
import * as fs from "node:fs";
|
|
|
|
import * as posix from "node:path/posix";
|
2025-01-22 04:54:03 +01:00
|
|
|
import { prettify, htmlDocument } from "antihtml";
|
2025-01-22 09:03:37 +01:00
|
|
|
import { pages } from "./content/pages.js";
|
|
|
|
import type { Page } from "./content/types.js";
|
|
|
|
import { resolveRefs } from "./utils/resolve-refs.js";
|
|
|
|
|
|
|
|
function pageToHtml(page: Page) {
|
|
|
|
if (!page.ref.startsWith("/")) {
|
|
|
|
throw new Error(`ref "${page.ref}" for "${page.title}" is not absolute.`);
|
|
|
|
}
|
|
|
|
return htmlDocument(
|
|
|
|
prettify(
|
|
|
|
resolveRefs(
|
|
|
|
page.content,
|
|
|
|
posix.dirname(page.ref),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2025-01-21 07:56:15 +01:00
|
|
|
|
2025-01-22 04:54:03 +01:00
|
|
|
const outDir = "build/web";
|
|
|
|
if (!fs.existsSync(outDir)) {
|
|
|
|
fs.mkdirSync(outDir);
|
2025-01-21 07:56:15 +01:00
|
|
|
}
|
|
|
|
|
2025-01-22 04:54:03 +01:00
|
|
|
for (const page of pages) {
|
|
|
|
const dirSep = page.ref.indexOf("/");
|
|
|
|
if (dirSep !== -1) {
|
|
|
|
const dir = `${outDir}/${page.ref.slice(0, dirSep)}`;
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir);
|
|
|
|
}
|
|
|
|
}
|
2025-01-22 09:03:37 +01:00
|
|
|
console.log(`writing ${outDir}${page.ref}`);
|
|
|
|
fs.writeFileSync(`${outDir}${page.ref}`, pageToHtml(page));
|
2025-01-22 04:54:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`writing ${outDir}/style.css`);
|
|
|
|
fs.writeFileSync(`${outDir}/style.css`, fs.readFileSync("public/style.css"));
|