import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { en } from "../src/i18n/en.ts"; import { fr } from "../src/i18n/fr.ts"; import { ja } from "../src/i18n/ja.ts"; import { zh } from "../src/i18n/zh.ts"; const root = path.join(path.dirname(fileURLToPath(import.meta.url)), ".."); const outDir = path.join(root, "html"); const copies = { zh, en, ja, fr }; const LANGS = ["zh", "en", "ja", "fr"]; const htmlLang = { zh: "zh-CN", en: "en", ja: "ja", fr: "fr" }; const langLabels = { zh: "中文", en: "English", ja: "日本語", fr: "Français" }; function esc(value) { return String(value) .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll('"', """); } function assetPrefix(lang) { return lang === "zh" ? "" : "../"; } function pageHref(fromLang, toLang, page) { const file = page === "home" ? "index.html" : "about.html"; if (fromLang === toLang) return file; if (fromLang === "zh") return `${toLang}/${file}`; if (toLang === "zh") return `../${file}`; return `../${toLang}/${file}`; } function productHref(key, lang) { if (key === "massiveedit" && (lang === "en" || lang === "fr")) { return "/massiveedit/en/"; } return `/${key}/`; } const ICONS = { chevron: ``, moon: ``, sun: ``, menu: ``, }; function header(lang, page) { const L = copies[lang]; const prefix = assetPrefix(lang); const home = pageHref(lang, lang, "home"); const about = pageHref(lang, lang, "about"); const products = `${home}#products`; const nav = [ { label: L.nav.home, href: home, current: page === "home" }, { label: L.nav.products, href: products, current: false }, { label: L.nav.about, href: about, current: page === "about" }, ]; return ``; } function footer(lang) { const L = copies[lang]; return ``; } function homeMain(lang) { const L = copies[lang]; const products = [ { key: "smartbuddy", name: L.home.productBuddyName, en: L.home.productBuddyEn, body: L.home.productBuddyBody, cta: L.home.productBuddyCta, }, { key: "smartinput", name: L.home.productInputName, en: L.home.productInputEn, body: L.home.productInputBody, cta: L.home.productInputCta, }, { key: "smarthanzi", name: L.home.productHanziName, en: L.home.productHanziEn, body: L.home.productHanziBody, cta: L.home.productHanziCta, }, { key: "massiveedit", name: L.home.productEditName, en: L.home.productEditEn, body: L.home.productEditBody, cta: L.home.productEditCta, }, ]; return `

${esc(L.brand.strong)} · ${esc(L.brand.suffix)}

${esc(L.home.heroTitle)}

${esc(L.home.heroSubtitle)}

${esc(L.home.productsTitle)}

${esc(L.home.productsLead)}

${products .map( (product) => ``, ) .join("\n ")}
`; } function aboutMain(lang) { const L = copies[lang]; return `

${esc(L.brand.strong)} · ${esc(L.brand.suffix)}

${esc(L.about.heroTitle)}

${esc(L.about.heroLead)}

${esc(L.about.visionTitle)}

${esc(L.about.visionBody)}

${esc(L.about.missionTitle)}

${esc(L.about.missionBody)}

${esc(L.about.storyTitle)}

${esc(L.about.storyBody)}

${esc(L.about.teamTitle)}

${esc(L.about.teamBody)}

`; } function documentFor(lang, page) { const L = copies[lang]; const prefix = assetPrefix(lang); const meta = page === "home" ? L.home : L.about; const alternates = LANGS.map((code) => { const href = code === "zh" ? lang === "zh" ? page === "home" ? "index.html" : "about.html" : `../${page === "home" ? "index.html" : "about.html"}` : lang === "zh" ? `${code}/${page === "home" ? "index.html" : "about.html"}` : code === lang ? page === "home" ? "index.html" : "about.html" : `../${code}/${page === "home" ? "index.html" : "about.html"}`; return ``; }).join("\n "); const defaultHref = lang === "zh" ? page === "home" ? "index.html" : "about.html" : `../${page === "home" ? "index.html" : "about.html"}`; return ` ${esc(meta.metaTitle)} ${alternates}
${header(lang, page)}
${page === "home" ? homeMain(lang) : aboutMain(lang)}
${footer(lang)}
`; } function writePage(lang, page) { const dir = lang === "zh" ? outDir : path.join(outDir, lang); fs.mkdirSync(dir, { recursive: true }); const file = page === "home" ? "index.html" : "about.html"; fs.writeFileSync(path.join(dir, file), documentFor(lang, page)); } for (const lang of LANGS) { writePage(lang, "home"); writePage(lang, "about"); } console.log("Wrote static portal pages to html/");