wilddragon-site/scripts/check-pages.mjs

13 lines
880 B
JavaScript
Raw Normal View History

// Smoke check: every LOCATION_PAGES/SERVICE_PAGES slug has a built page with valid JSON-LD, is in the sitemap, and links its subpages.
import fs from "node:fs";
const win = { __R: (p) => "/" + p };
new Function("window", fs.readFileSync("services-data.js", "utf8"))(win);
const sm = fs.readFileSync("sitemap.xml", "utf8");
for (const l of [...win.LOCATION_PAGES.map((l) => l.slug), ...win.SERVICE_PAGES.map((s) => "services/" + s.slug)]) {
const html = fs.readFileSync(`${l}/index.html`, "utf8");
JSON.parse(html.match(/<script type="application\/ld\+json">(.*?)<\/script>/s)[1]);
if (!sm.includes(`https://wilddragon.net/${l}/`)) throw new Error("missing from sitemap: " + l);
for (const sub of win.LOCATION_PAGES.find((x) => x.slug === l)?.subpages || []) if (!html.includes(`/${sub}/`)) throw new Error(`${l} missing link to ${sub}`);
}
console.log("check-pages ok");