link-check.mjs 559 B

123456789101112
  1. import { readFileSync, existsSync } from "node:fs"
  2. import { dirname, resolve } from "node:path"
  3. const f = ".scratch/cockpit-real-data-wayfinding/issues/67-district.md"
  4. const text = readFileSync(f, "utf8")
  5. const links = [...text.matchAll(/\]\(([^)#][^)]*)\)/g)].map((m) => m[1]).filter((l) => !/^https?:/.test(l))
  6. const bad = []
  7. for (const l of links) {
  8. const target = resolve(dirname(f), l.split("#")[0])
  9. if (!existsSync(target)) bad.push(l)
  10. }
  11. console.log("links:", links.length, "broken:", bad.length)
  12. for (const b of bad) console.log(" BROKEN", b)