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