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 | |
| parent | 5391e4112e513b8052bc700bc0f062aebdfb8098 (diff) | |
| download | yuescript-01a84cb83973b1dbbcc0cbbc6835ea3f3ec755e3.tar.gz yuescript-01a84cb83973b1dbbcc0cbbc6835ea3f3ec755e3.tar.bz2 yuescript-01a84cb83973b1dbbcc0cbbc6835ea3f3ec755e3.zip | |
Try a fix. [skip CI]
Diffstat (limited to '')
| -rw-r--r-- | .github/workflows/static.yml | 4 | ||||
| -rw-r--r-- | doc/docs/.vitepress/config.mts | 30 | ||||
| -rw-r--r-- | doc/docs/.vitepress/theme/index.ts | 25 | ||||
| -rw-r--r-- | doc/scripts/fix-css-link-rel.mjs | 6 |
4 files changed, 50 insertions, 15 deletions
diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 4e79a61..c67c7da 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml | |||
| @@ -6,20 +6,16 @@ on: | |||
| 6 | # Allows you to run this workflow manually from the Actions tab | 6 | # Allows you to run this workflow manually from the Actions tab |
| 7 | workflow_dispatch: | 7 | workflow_dispatch: |
| 8 | 8 | ||
| 9 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
| 10 | permissions: | 9 | permissions: |
| 11 | contents: read | 10 | contents: read |
| 12 | pages: write | 11 | pages: write |
| 13 | id-token: write | 12 | id-token: write |
| 14 | 13 | ||
| 15 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
| 16 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
| 17 | concurrency: | 14 | concurrency: |
| 18 | group: "pages" | 15 | group: "pages" |
| 19 | cancel-in-progress: false | 16 | cancel-in-progress: false |
| 20 | 17 | ||
| 21 | jobs: | 18 | jobs: |
| 22 | # Single deploy job since we're just deploying | ||
| 23 | deploy: | 19 | deploy: |
| 24 | environment: | 20 | environment: |
| 25 | name: github-pages | 21 | name: github-pages |
diff --git a/doc/docs/.vitepress/config.mts b/doc/docs/.vitepress/config.mts index b458501..635d087 100644 --- a/doc/docs/.vitepress/config.mts +++ b/doc/docs/.vitepress/config.mts | |||
| @@ -21,6 +21,15 @@ const yuescriptLanguage = { | |||
| 21 | aliases: ["yue"], | 21 | aliases: ["yue"], |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | const docsBase = process.env.DOCS_BASE ?? "/"; | ||
| 25 | |||
| 26 | function withBase(path: string) { | ||
| 27 | if (!path.startsWith("/") || docsBase === "/") { | ||
| 28 | return path; | ||
| 29 | } | ||
| 30 | return `${docsBase.replace(/\/$/, "")}${path}`; | ||
| 31 | } | ||
| 32 | |||
| 24 | const sidebarText = { | 33 | const sidebarText = { |
| 25 | de: { | 34 | de: { |
| 26 | introduction: "Einführung", | 35 | introduction: "Einführung", |
| @@ -415,7 +424,7 @@ function createSidebar(basePath: string, locale: SidebarLocale) { | |||
| 415 | export default defineConfig({ | 424 | export default defineConfig({ |
| 416 | title: "YueScript", | 425 | title: "YueScript", |
| 417 | description: "A language that compiles to Lua", | 426 | description: "A language that compiles to Lua", |
| 418 | base: "/", | 427 | base: docsBase, |
| 419 | head: [ | 428 | head: [ |
| 420 | ["meta", { name: "theme-color", content: "#b4ac8f" }], | 429 | ["meta", { name: "theme-color", content: "#b4ac8f" }], |
| 421 | ["meta", { name: "apple-mobile-web-app-capable", content: "yes" }], | 430 | ["meta", { name: "apple-mobile-web-app-capable", content: "yes" }], |
| @@ -432,10 +441,13 @@ export default defineConfig({ | |||
| 432 | }, | 441 | }, |
| 433 | ], | 442 | ], |
| 434 | ["meta", { property: "og:type", content: "website" }], | 443 | ["meta", { property: "og:type", content: "website" }], |
| 435 | ["meta", { property: "og:image", content: "/image/yuescript.png" }], | 444 | ["meta", { property: "og:image", content: withBase("/image/yuescript.png") }], |
| 436 | [ | 445 | [ |
| 437 | "meta", | 446 | "meta", |
| 438 | { property: "og:image:secure_url", content: "/image/yuescript.png" }, | 447 | { |
| 448 | property: "og:image:secure_url", | ||
| 449 | content: withBase("/image/yuescript.png"), | ||
| 450 | }, | ||
| 439 | ], | 451 | ], |
| 440 | ["meta", { property: "og:image:type", content: "image/png" }], | 452 | ["meta", { property: "og:image:type", content: "image/png" }], |
| 441 | ["meta", { property: "og:image:width", content: "1200" }], | 453 | ["meta", { property: "og:image:width", content: "1200" }], |
| @@ -444,7 +456,7 @@ export default defineConfig({ | |||
| 444 | "link", | 456 | "link", |
| 445 | { | 457 | { |
| 446 | rel: "icon", | 458 | rel: "icon", |
| 447 | href: "/image/favicon/favicon-16x16.png", | 459 | href: withBase("/image/favicon/favicon-16x16.png"), |
| 448 | sizes: "16x16", | 460 | sizes: "16x16", |
| 449 | type: "image/png", | 461 | type: "image/png", |
| 450 | }, | 462 | }, |
| @@ -453,7 +465,7 @@ export default defineConfig({ | |||
| 453 | "link", | 465 | "link", |
| 454 | { | 466 | { |
| 455 | rel: "icon", | 467 | rel: "icon", |
| 456 | href: "/image/favicon/favicon-32x32.png", | 468 | href: withBase("/image/favicon/favicon-32x32.png"), |
| 457 | sizes: "32x32", | 469 | sizes: "32x32", |
| 458 | type: "image/png", | 470 | type: "image/png", |
| 459 | }, | 471 | }, |
| @@ -462,7 +474,7 @@ export default defineConfig({ | |||
| 462 | "link", | 474 | "link", |
| 463 | { | 475 | { |
| 464 | rel: "apple-touch-icon", | 476 | rel: "apple-touch-icon", |
| 465 | href: "/image/favicon/apple-touch-icon.png", | 477 | href: withBase("/image/favicon/apple-touch-icon.png"), |
| 466 | sizes: "180x180", | 478 | sizes: "180x180", |
| 467 | type: "image/png", | 479 | type: "image/png", |
| 468 | }, | 480 | }, |
| @@ -471,7 +483,7 @@ export default defineConfig({ | |||
| 471 | "link", | 483 | "link", |
| 472 | { | 484 | { |
| 473 | rel: "android-chrome", | 485 | rel: "android-chrome", |
| 474 | href: "/image/favicon/android-chrome-192x192.png", | 486 | href: withBase("/image/favicon/android-chrome-192x192.png"), |
| 475 | sizes: "192x192", | 487 | sizes: "192x192", |
| 476 | type: "image/png", | 488 | type: "image/png", |
| 477 | }, | 489 | }, |
| @@ -480,7 +492,7 @@ export default defineConfig({ | |||
| 480 | "link", | 492 | "link", |
| 481 | { | 493 | { |
| 482 | rel: "android-chrome", | 494 | rel: "android-chrome", |
| 483 | href: "/image/favicon/android-chrome-512x512.png", | 495 | href: withBase("/image/favicon/android-chrome-512x512.png"), |
| 484 | sizes: "512x512", | 496 | sizes: "512x512", |
| 485 | type: "image/png", | 497 | type: "image/png", |
| 486 | }, | 498 | }, |
| @@ -505,7 +517,7 @@ export default defineConfig({ | |||
| 505 | window.dispatchEvent(new Event('yue:ready')); | 517 | window.dispatchEvent(new Event('yue:ready')); |
| 506 | } | 518 | } |
| 507 | var s = document.createElement('script'); | 519 | var s = document.createElement('script'); |
| 508 | s.src = '/js/yuescript.js'; | 520 | s.src = '${withBase("/js/yuescript.js")}'; |
| 509 | s.async = true; | 521 | s.async = true; |
| 510 | document.head.appendChild(s); | 522 | document.head.appendChild(s); |
| 511 | })();`, | 523 | })();`, |
diff --git a/doc/docs/.vitepress/theme/index.ts b/doc/docs/.vitepress/theme/index.ts index 70145d5..7e9882e 100644 --- a/doc/docs/.vitepress/theme/index.ts +++ b/doc/docs/.vitepress/theme/index.ts | |||
| @@ -12,6 +12,19 @@ import YueCompiler from "./components/YueCompiler.vue"; | |||
| 12 | // @ts-ignore | 12 | // @ts-ignore |
| 13 | import YueDisplay from "./components/YueDisplay.vue"; | 13 | import YueDisplay from "./components/YueDisplay.vue"; |
| 14 | 14 | ||
| 15 | function applyShikiInlineColorFallback() { | ||
| 16 | if (typeof document === "undefined") return; | ||
| 17 | const isDark = document.documentElement.classList.contains("dark"); | ||
| 18 | const varName = isDark ? "--shiki-dark" : "--shiki-light"; | ||
| 19 | const spans = document.querySelectorAll<HTMLElement>(".vp-code span"); | ||
| 20 | spans.forEach((span) => { | ||
| 21 | const color = span.style.getPropertyValue(varName).trim(); | ||
| 22 | if (color) { | ||
| 23 | span.style.color = color; | ||
| 24 | } | ||
| 25 | }); | ||
| 26 | } | ||
| 27 | |||
| 15 | const theme: Theme = { | 28 | const theme: Theme = { |
| 16 | extends: DefaultTheme, | 29 | extends: DefaultTheme, |
| 17 | Layout: () => | 30 | Layout: () => |
| @@ -22,6 +35,18 @@ const theme: Theme = { | |||
| 22 | app.component("CompilerModal", CompilerModal); | 35 | app.component("CompilerModal", CompilerModal); |
| 23 | app.component("YueCompiler", YueCompiler); | 36 | app.component("YueCompiler", YueCompiler); |
| 24 | app.component("YueDisplay", YueDisplay); | 37 | app.component("YueDisplay", YueDisplay); |
| 38 | |||
| 39 | if (typeof window !== "undefined") { | ||
| 40 | const run = () => requestAnimationFrame(applyShikiInlineColorFallback); | ||
| 41 | window.addEventListener("DOMContentLoaded", run, { once: true }); | ||
| 42 | window.addEventListener("load", run, { once: true }); | ||
| 43 | |||
| 44 | const observer = new MutationObserver(run); | ||
| 45 | observer.observe(document.documentElement, { | ||
| 46 | attributes: true, | ||
| 47 | attributeFilter: ["class"], | ||
| 48 | }); | ||
| 49 | } | ||
| 25 | }, | 50 | }, |
| 26 | }; | 51 | }; |
| 27 | 52 | ||
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; |
