diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-12 11:04:12 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-12 11:04:32 +0800 |
| commit | 5391e4112e513b8052bc700bc0f062aebdfb8098 (patch) | |
| tree | 66533f6a6f826efc3304b5f358fbc4eb06dc5a15 /doc/scripts | |
| parent | 02ad762c3d1171afc586a648460bca9f16154337 (diff) | |
| download | yuescript-5391e4112e513b8052bc700bc0f062aebdfb8098.tar.gz yuescript-5391e4112e513b8052bc700bc0f062aebdfb8098.tar.bz2 yuescript-5391e4112e513b8052bc700bc0f062aebdfb8098.zip | |
Try fix doc css issue. [skip CI]v0.33.0
Diffstat (limited to 'doc/scripts')
| -rw-r--r-- | doc/scripts/fix-css-link-rel.mjs | 30 |
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 @@ | |||
| 1 | import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs"; | ||
| 2 | import { join } from "node:path"; | ||
| 3 | |||
| 4 | const distRoot = "docs/.vitepress/dist"; | ||
| 5 | const cssRelPattern = /rel="preload stylesheet"/g; | ||
| 6 | |||
| 7 | function 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 | |||
| 20 | let updated = 0; | ||
| 21 | for (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 | |||
| 30 | console.log(`[fix-css-link-rel] Updated ${updated} HTML files.`); | ||
