diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-12 11:38:41 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-12 11:38:41 +0800 |
| commit | 01a84cb83973b1dbbcc0cbbc6835ea3f3ec755e3 (patch) | |
| tree | fc86e3ffc0becd8f0b1176512cf36cbd212df5a5 /doc/scripts | |
| parent | 5391e4112e513b8052bc700bc0f062aebdfb8098 (diff) | |
| download | yuescript-01a84cb83973b1dbbcc0cbbc6835ea3f3ec755e3.tar.gz yuescript-01a84cb83973b1dbbcc0cbbc6835ea3f3ec755e3.tar.bz2 yuescript-01a84cb83973b1dbbcc0cbbc6835ea3f3ec755e3.zip | |
Try a fix. [skip CI]
Diffstat (limited to 'doc/scripts')
| -rw-r--r-- | doc/scripts/fix-css-link-rel.mjs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/doc/scripts/fix-css-link-rel.mjs b/doc/scripts/fix-css-link-rel.mjs index 9cbc9ea..4c48868 100644 --- a/doc/scripts/fix-css-link-rel.mjs +++ b/doc/scripts/fix-css-link-rel.mjs | |||
| @@ -2,7 +2,8 @@ import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs"; | |||
| 2 | import { join } from "node:path"; | 2 | import { join } from "node:path"; |
| 3 | 3 | ||
| 4 | const distRoot = "docs/.vitepress/dist"; | 4 | const distRoot = "docs/.vitepress/dist"; |
| 5 | const cssRelPattern = /rel="preload stylesheet"/g; | 5 | const preloadStylesheetRelPattern = /rel="preload stylesheet"/g; |
| 6 | const stylesheetAsPattern = /(<link[^>]*rel="stylesheet"[^>]*?)\s+as="style"/g; | ||
| 6 | 7 | ||
| 7 | function walk(dir, files = []) { | 8 | function walk(dir, files = []) { |
| 8 | for (const entry of readdirSync(dir)) { | 9 | for (const entry of readdirSync(dir)) { |
| @@ -20,7 +21,8 @@ function walk(dir, files = []) { | |||
| 20 | let updated = 0; | 21 | let updated = 0; |
| 21 | for (const filePath of walk(distRoot)) { | 22 | for (const filePath of walk(distRoot)) { |
| 22 | const original = readFileSync(filePath, "utf8"); | 23 | const original = readFileSync(filePath, "utf8"); |
| 23 | const fixed = original.replace(cssRelPattern, 'rel="stylesheet"'); | 24 | let fixed = original.replace(preloadStylesheetRelPattern, 'rel="stylesheet"'); |
| 25 | fixed = fixed.replace(stylesheetAsPattern, "$1"); | ||
| 24 | if (fixed !== original) { | 26 | if (fixed !== original) { |
| 25 | writeFileSync(filePath, fixed, "utf8"); | 27 | writeFileSync(filePath, fixed, "utf8"); |
| 26 | updated += 1; | 28 | updated += 1; |
