From 546c1583a1213c9c019ca0cb13f8714a946a322b Mon Sep 17 00:00:00 2001
From: nschimme <5505185+nschimme@users.noreply.github.com>
Date: Sun, 20 Sep 2026 16:24:44 +0000
Subject: [PATCH 1/3] Fix PR preview base URLs for forks and add link/asset CI
tests
Fix PR preview base path determination for forks targeting mume.github.io so builds use VITE_BASE=/pr-N/ on docs.mume.org. Add an automated link and asset path verification test script (npm test) integrated into CI workflows and Dockerfile to prevent path regression or broken asset references.
---
.github/workflows/deploy.yml | 5 +
.github/workflows/pr-preview.yml | 9 +-
Dockerfile | 1 +
docs/news/index.md | 2 +-
package.json | 3 +-
scripts/ci-env.sh | 6 +-
scripts/test-link-and-asset-paths.js | 163 +++++++++++++++++++++++++++
7 files changed, 184 insertions(+), 5 deletions(-)
create mode 100644 scripts/test-link-and-asset-paths.js
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 1315dbd..11f718b 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -55,6 +55,11 @@ jobs:
env:
VITE_BASE: ${{ env.VITE_BASE || format('{0}/', steps.pages.outputs.base_path) }}
+ - name: Verify links and asset paths
+ run: npm test
+ env:
+ VITE_BASE: ${{ env.VITE_BASE || format('{0}/', steps.pages.outputs.base_path) }}
+
- name: Collect PRs to deploy
uses: actions/github-script@v9
with:
diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml
index 6f6d45d..598d851 100644
--- a/.github/workflows/pr-preview.yml
+++ b/.github/workflows/pr-preview.yml
@@ -26,7 +26,9 @@ jobs:
- name: Determine Base URL Prefix
id: base_url
run: |
- if [ "${{ github.event.repository.name }}" = "${{ github.repository_owner }}.github.io" ]; then
+ REPO_NAME=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]')
+ OWNER_NAME=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
+ if [ "$REPO_NAME" = "mume.github.io" ] || [ "$REPO_NAME" = "${OWNER_NAME}.github.io" ]; then
echo "prefix=/" >> $GITHUB_OUTPUT
else
echo "prefix=/${{ github.event.repository.name }}/" >> $GITHUB_OUTPUT
@@ -44,6 +46,11 @@ jobs:
env:
VITE_BASE: ${{ steps.base_url.outputs.prefix }}pr-${{ github.event.number }}/
+ - name: Verify links and asset paths
+ run: npm test
+ env:
+ VITE_BASE: ${{ steps.base_url.outputs.prefix }}pr-${{ github.event.number }}/
+
- name: Package build
run: |
cd dist
diff --git a/Dockerfile b/Dockerfile
index b64a232..68081fd 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,6 +13,7 @@ ARG VITE_BASE=/
ENV VITE_BASE=${VITE_BASE}
RUN npm run build
+RUN npm test
FROM nginx:alpine
diff --git a/docs/news/index.md b/docs/news/index.md
index 43b92be..ab5500f 100644
--- a/docs/news/index.md
+++ b/docs/news/index.md
@@ -16,7 +16,7 @@ description: Latest developments, changes, war updates, and traffic plots for Mu
Game News
Find out about the latest news from the game!
-Web News
+Web News
The news from this Web-page. Note these do not really get used, usually everything important gets put up as Game News.
Frequentation Plots
diff --git a/package.json b/package.json
index 5039516..dacae02 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,8 @@
"preview": "vitepress preview docs",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
- "docs:preview": "vitepress preview docs"
+ "docs:preview": "vitepress preview docs",
+ "test": "node scripts/test-link-and-asset-paths.js"
},
"dependencies": {
"vue": "^3.5.42"
diff --git a/scripts/ci-env.sh b/scripts/ci-env.sh
index 55e9544..13b3d03 100755
--- a/scripts/ci-env.sh
+++ b/scripts/ci-env.sh
@@ -28,8 +28,10 @@ else
fi
echo "VITE_HOSTNAME=$VITE_HOSTNAME" >> $GITHUB_ENV
-# Explicitly set VITE_BASE=/ for the official production environment
-if [ "$OWNER" = "mume" ] && [ "$REPO" = "mume.github.io" ]; then
+# Explicitly set VITE_BASE=/ for the official production environment if not already set
+OWNER_LOWER=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')
+REPO_LOWER=$(echo "$REPO" | tr '[:upper:]' '[:lower:]')
+if [ -z "$VITE_BASE" ] && [ "$OWNER_LOWER" = "mume" ] && [ "$REPO_LOWER" = "mume.github.io" ]; then
export VITE_BASE="/"
echo "VITE_BASE=$VITE_BASE" >> $GITHUB_ENV
fi
diff --git a/scripts/test-link-and-asset-paths.js b/scripts/test-link-and-asset-paths.js
new file mode 100644
index 0000000..6c466c0
--- /dev/null
+++ b/scripts/test-link-and-asset-paths.js
@@ -0,0 +1,163 @@
+import fs from 'fs'
+import path from 'path'
+import { fileURLToPath } from 'url'
+
+const __filename = fileURLToPath(import.meta.url)
+const __dirname = path.dirname(__filename)
+const distDir = path.resolve(__dirname, '../dist')
+
+if (!fs.existsSync(distDir)) {
+ console.error(`[TEST ERROR] dist directory does not exist at ${distDir}. Run 'npm run build' first.`)
+ process.exit(1)
+}
+
+function getAllHtmlFiles(dir, fileList = []) {
+ const files = fs.readdirSync(dir)
+ for (const file of files) {
+ const filePath = path.join(dir, file)
+ if (fs.statSync(filePath).isDirectory()) {
+ getAllHtmlFiles(filePath, fileList)
+ } else if (file.endsWith('.html')) {
+ fileList.push(filePath)
+ }
+ }
+ return fileList
+}
+
+const htmlFiles = getAllHtmlFiles(distDir)
+if (htmlFiles.length === 0) {
+ console.error('[TEST ERROR] No HTML files found in dist directory.')
+ process.exit(1)
+}
+
+let errors = []
+let totalLinksChecked = 0
+let totalAssetsChecked = 0
+
+let baseEnv = process.env.VITE_BASE || '/'
+if (!baseEnv.startsWith('/')) baseEnv = '/' + baseEnv
+if (!baseEnv.endsWith('/')) baseEnv = baseEnv + '/'
+const expectedBase = baseEnv
+
+console.log(`[TEST] Verifying ${htmlFiles.length} HTML files in dist/ against expected base: "${expectedBase}"...`)
+
+for (const htmlFile of htmlFiles) {
+ const content = fs.readFileSync(htmlFile, 'utf8')
+ const relPath = path.relative(distDir, htmlFile)
+
+ // 1. Check for invalid prefix '/mume.github.io/'
+ if (content.includes('/mume.github.io/')) {
+ errors.push(`${relPath}: Contains invalid hardcoded path prefix '/mume.github.io/'`)
+ }
+
+ // 2. Extract and check src/href attributes (
,