// Builds landing/*.html from site/pages and site/partials. No dependencies: `node site/build.mjs`. // Pages start with a comment of `key: value` lines (title, description, path, family, robots, // shareTitle, shareDescription, shareImage, shareImageAlt). The default share card is site/og-card.html, // saved as landing/img/social-card.png; the Toolkit page uses site/og-toolkit.html, saved as landing/img/toolkit-card.png. // {{release…}} values come from landing/updates/latest.json, which the Mac release script writes. import { readFileSync, readdirSync, writeFileSync } from "node:fs"; const root = new URL("./", import.meta.url); const read = path => readFileSync(new URL(path, root), "utf8"); const partial = name => read(`partials/${name}.html`).trimEnd(); const include = html => html.replace(/\{\{> (\w+)\}\}/g, (_, name) => include(partial(name))); const fill = (html, values) => html.replace(/\{\{(\w+)\}\}/g, (_, key) => values[key] ?? ""); const latest = JSON.parse(read("../landing/updates/latest.json")); const escape = text => text.replace(/&/g, "&").replace(/ name.endsWith(".html"))) { const [, front, body] = read(`pages/${file}`).match(/^\n([\s\S]*)$/); const page = Object.fromEntries(front.split("\n").map(line => line.split(/:\s*(.*)/s).slice(0, 2))); const values = { ...release, ...page, counterAssets: page.path === "/" ? '\n' : "", content: fill(include(body.trimEnd()), release), family: page.family === "true" ? partial("family") + "\n\n" : "", homeBand: page.path === "/" ? partial("branchband") + "\n\n" : "", robots: page.robots ? `\n` : "", shareTitle: page.shareTitle ?? page.title, shareDescription: page.shareDescription ?? page.description, shareImage: page.shareImage ?? "/img/social-card.png?v=people-decide", shareImageAlt: page.shareImageAlt ?? "Glimmer. Our social network, where people decide.", jsonld: page.family === "true" ? partial("jsonld") + "\n" : "", }; const html = fill(include(partial("layout")), values); writeFileSync(new URL(`../landing/${file}`, root), html + "\n"); console.log(`landing/${file}`); }