aboutsummaryrefslogtreecommitdiff
path: root/doc/scripts/fix-css-link-rel.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'doc/scripts/fix-css-link-rel.mjs')
-rw-r--r--doc/scripts/fix-css-link-rel.mjs30
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/scripts/fix-css-link-rel.mjs b/doc/scripts/fix-css-link-rel.mjs
new file mode 100644
index 0000000..9cbc9ea
--- /dev/null
+++ b/doc/scripts/fix-css-link-rel.mjs
@@ -0,0 +1,30 @@
1import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
2import { join } from "node:path";
3
4const distRoot = "docs/.vitepress/dist";
5const cssRelPattern = /rel="preload stylesheet"/g;
6
7function walk(dir, files = []) {
8 for (const entry of readdirSync(dir)) {
9 const fullPath = join(dir, entry);
10 const stat = statSync(fullPath);
11 if (stat.isDirectory()) {
12 walk(fullPath, files);
13 } else if (fullPath.endsWith(".html")) {
14 files.push(fullPath);
15 }
16 }
17 return files;
18}
19
20let updated = 0;
21for (const filePath of walk(distRoot)) {
22 const original = readFileSync(filePath, "utf8");
23 const fixed = original.replace(cssRelPattern, 'rel="stylesheet"');
24 if (fixed !== original) {
25 writeFileSync(filePath, fixed, "utf8");
26 updated += 1;
27 }
28}
29
30console.log(`[fix-css-link-rel] Updated ${updated} HTML files.`);