The paths changed in d003ea01
to start with a forward slash, this broke
the create folder detection logic as now it matched the first slash of
the path instead of sub-folder in the path. Fix by ignoring the first
character in the path.
40 lines
1 KiB
TypeScript
40 lines
1 KiB
TypeScript
import * as fs from "node:fs";
|
|
import * as posix from "node:path/posix";
|
|
import { prettify, htmlDocument } from "antihtml";
|
|
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),
|
|
)
|
|
)
|
|
)
|
|
}
|
|
|
|
const outDir = "build/web";
|
|
if (!fs.existsSync(outDir)) {
|
|
fs.mkdirSync(outDir);
|
|
}
|
|
|
|
for (const page of pages) {
|
|
const dirSep = page.ref.indexOf("/", 1);
|
|
if (dirSep !== -1) {
|
|
const dir = `${outDir}/${page.ref.slice(0, dirSep)}`;
|
|
if (!fs.existsSync(dir)) {
|
|
fs.mkdirSync(dir);
|
|
}
|
|
}
|
|
console.log(`writing ${outDir}${page.ref}`);
|
|
fs.writeFileSync(`${outDir}${page.ref}`, pageToHtml(page));
|
|
}
|
|
|
|
console.log(`writing ${outDir}/style.css`);
|
|
fs.writeFileSync(`${outDir}/style.css`, fs.readFileSync("public/style.css"));
|