22 lines
2 KiB
JavaScript
22 lines
2 KiB
JavaScript
// 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");
|
|
// every /images/ ref in built pages must exist (catches missing photos/hero/ variants)
|
|
for (const f of fs.readdirSync(".", { recursive: true }).filter((f) => f.endsWith("index.html") && !f.includes("node_modules")))
|
|
for (const m of fs.readFileSync(f, "utf8").matchAll(/src="\/?(images\/[^"?]+)"/g)) if (!fs.existsSync(m[1])) throw new Error(`${f}: missing ${m[1]}`);
|
|
console.log("check-pages ok");
|