Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

1.8 KB
Raw Blame
// Postbuild: move the generated sitemap to the site ROOT (docs/sitemap.xml).
//
// Eleventy can only write inside its output dir (docs/blog), but robots.txt
// points crawlers at https://munderdiffl.in/sitemap.xml — the repo root. So we
// move docs/blog/sitemap.xml up to docs/sitemap.xml after the build. The sitemap
// uses absolute URLs, so its location on disk doesn't affect its contents.
//
// Runs with cwd = blog/ (npm sets it to the package dir).
import { readFile, rename, rm, writeFile } from "node:fs/promises";

const from = "../docs/blog/sitemap.xml";
const to = "../docs/sitemap.xml";

try {
  await rename(from, to);
  console.log(`[postbuild] sitemap → docs/sitemap.xml (root)`);
} catch (err) {
  console.error(`[postbuild] failed to move sitemap: ${err.message}`);
  process.exit(1);
}

// Splice the generated blog section (src/llms-blog.njk) into the root llms.txt
// between the BLOG markers, so AI crawlers see every post without anyone
// editing llms.txt by hand. The temporary file is removed after.
const section = "../docs/blog/llms-blog-section.txt";
const llms = "../docs/llms.txt";
const START = "<!-- BLOG:START generated by blog/scripts/postbuild.mjs -->";
const END = "<!-- BLOG:END -->";
try {
  const body = (await readFile(section, "utf8")).trim();
  const text = await readFile(llms, "utf8");
  const a = text.indexOf(START);
  const b = text.indexOf(END);
  if (a === -1 || b === -1 || b < a) throw new Error("BLOG markers missing in docs/llms.txt");
  const next = text.slice(0, a + START.length) + "\n" + body + "\n" + text.slice(b);
  if (next !== text) await writeFile(llms, next);
  await rm(section);
  console.log(`[postbuild] blog section → docs/llms.txt`);
} catch (err) {
  console.error(`[postbuild] failed to update llms.txt: ${err.message}`);
  process.exit(1);
}