diff --git a/IDE官网/assets/js/stage-globe.js b/IDE官网/assets/js/stage-globe.js index 97873f7..4f12cbd 100644 --- a/IDE官网/assets/js/stage-globe.js +++ b/IDE官网/assets/js/stage-globe.js @@ -5,7 +5,7 @@ (function (global) { 'use strict'; - const WORLD_URL = '/assets/data/world-110m.json'; + const WORLD_URL = 'assets/data/world-110m.json'; const HUB = [114.06, 22.55]; const LABELS = { diff --git a/nginx-default.conf b/nginx-default.conf index 64cebd5..5b54f4c 100644 --- a/nginx-default.conf +++ b/nginx-default.conf @@ -55,6 +55,14 @@ server { add_header Cache-Control "no-cache, no-store, must-revalidate"; } + # 官网静态资源(/site/index.html 通过 base href 引用 /site/assets/...) + location ^~ /site/ { + try_files $uri =404; + expires 7d; + add_header Cache-Control "public"; + access_log off; + } + # ============ 客户 / 管理端登录入口 ============ location = /login { try_files /index.html =200; diff --git a/nginx-docker.conf b/nginx-docker.conf index b96462d..45c16d5 100644 --- a/nginx-docker.conf +++ b/nginx-docker.conf @@ -22,6 +22,13 @@ server { add_header Cache-Control "no-cache, no-store, must-revalidate"; } + location ^~ /site/ { + try_files $uri =404; + expires 7d; + add_header Cache-Control "public"; + access_log off; + } + location = /login { try_files /index.html =200; } diff --git a/scripts/postbuild-cleanup-dist.js b/scripts/postbuild-cleanup-dist.js index 635bd01..2d1d3d8 100644 --- a/scripts/postbuild-cleanup-dist.js +++ b/scripts/postbuild-cleanup-dist.js @@ -6,6 +6,30 @@ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const dist = path.join(root, 'dist'); const siteSrc = path.join(root, 'IDE官网'); const legacyLoginDir = path.join(dist, 'login'); +const siteDir = path.join(dist, 'site'); + +/** Avoid fs.cpSync merge into dist/assets (conflicts with Vite + can crash on Windows). */ +function copyDirSync(src, dest, options = {}) { + const { skipDirNames = new Set() } = options; + fs.mkdirSync(dest, { recursive: true }); + for (const entry of fs.readdirSync(src, { withFileTypes: true })) { + if (entry.isDirectory() && skipDirNames.has(entry.name)) continue; + const srcPath = path.join(src, entry.name); + const destPath = path.join(dest, entry.name); + if (entry.isDirectory()) { + copyDirSync(srcPath, destPath, options); + continue; + } + if (entry.isFile()) { + fs.copyFileSync(srcPath, destPath); + } + } +} + +function injectSiteBaseHref(html) { + if (html.includes('', '\n '); +} if (fs.existsSync(legacyLoginDir)) { fs.rmSync(legacyLoginDir, { recursive: true, force: true }); @@ -17,22 +41,26 @@ function copyOfficialSite() { return; } - const siteDir = path.join(dist, 'site'); - fs.mkdirSync(siteDir, { recursive: true }); - fs.copyFileSync(path.join(siteSrc, 'index.html'), path.join(siteDir, 'index.html')); + if (fs.existsSync(siteDir)) { + fs.rmSync(siteDir, { recursive: true, force: true }); + } + + copyDirSync(siteSrc, siteDir, { + skipDirNames: new Set(['.well-known']), + }); + + const siteIndex = path.join(siteDir, 'index.html'); + if (fs.existsSync(siteIndex)) { + const html = fs.readFileSync(siteIndex, 'utf8'); + fs.writeFileSync(siteIndex, injectSiteBaseHref(html), 'utf8'); + } const src9610 = path.join(siteSrc, '9610.html'); if (fs.existsSync(src9610)) { fs.copyFileSync(src9610, path.join(dist, '9610.html')); } - const srcAssets = path.join(siteSrc, 'assets'); - const destAssets = path.join(dist, 'assets'); - if (fs.existsSync(srcAssets)) { - fs.cpSync(srcAssets, destAssets, { recursive: true }); - } - - console.log('[postbuild] copied official site to dist/site + 9610.html + assets'); + console.log('[postbuild] copied official site to dist/site (assets under /site/assets)'); } copyOfficialSite();