import fs from "fs"; const base = "https://grammar.lingdocs.com"; console.log("generating sitemap.xml"); const indexText = fs.readFileSync("./src/content/index.ts", "utf-8"); const contentTreeRaw = indexText.split("/* content-tree */")[1]; const safeContentTreeText = contentTreeRaw .split("\n") .filter(l => !l.includes(`"import":`)) .join("\n"); const contentTree = JSON.parse(safeContentTreeText); const urls = contentTree.reduce((acc, section) => { if ("slug" in section) { return [ ...acc, `${base}/${section.slug}`, ]; } else { return [ ...acc, ...section.chapters.map(x => `${base}/${section.subdirectory}/${x.slug}`), ]; } }, [base]); const siteMap = ` ${urls.map(u => ` ${u} `).join("")} ` fs.writeFileSync("./public/sitemap.xml", siteMap);