diff options
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; |
