wilddragon-site/scripts/check-pages.mjs

20 lines
1.6 KiB
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}`);
}
const gp = "guides/smpte-2110-facility-migration";
const gh = fs.readFileSync(`${gp}/index.html`, "utf8");
const gld = JSON.parse(gh.match(/<script type="application\/ld\+json">(.*?)<\/script>/s)[1])["@graph"].map((n) => n["@type"]);
for (const t of ["TechArticle", "FAQPage", "BreadcrumbList"]) if (!gld.includes(t)) throw new Error("guide missing JSON-LD " + t);
if (!sm.includes(`https://wilddragon.net/${gp}/`) || !sm.includes("https://wilddragon.net/guides/")) throw new Error("guide missing from sitemap");
if (!fs.existsSync("guides/index.html")) throw new Error("missing guides index");
for (const p of ["services/broadcast-systems-integration", "broadcast-integration-dmv"]) if (!fs.readFileSync(`${p}/index.html`, "utf8").includes(`/${gp}/`)) throw new Error(p + " missing guide link");
console.log("check-pages ok");