aboutsummaryrefslogtreecommitdiff
path: root/doc/scripts/fix-css-link-rel.mjs
blob: 9cbc9eae2eaafa31eb9492f7aa91ed78cdf1a4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
import { join } from "node:path";

const distRoot = "docs/.vitepress/dist";
const cssRelPattern = /rel="preload stylesheet"/g;

function walk(dir, files = []) {
  for (const entry of readdirSync(dir)) {
    const fullPath = join(dir, entry);
    const stat = statSync(fullPath);
    if (stat.isDirectory()) {
      walk(fullPath, files);
    } else if (fullPath.endsWith(".html")) {
      files.push(fullPath);
    }
  }
  return files;
}

let updated = 0;
for (const filePath of walk(distRoot)) {
  const original = readFileSync(filePath, "utf8");
  const fixed = original.replace(cssRelPattern, 'rel="stylesheet"');
  if (fixed !== original) {
    writeFileSync(filePath, fixed, "utf8");
    updated += 1;
  }
}

console.log(`[fix-css-link-rel] Updated ${updated} HTML files.`);