Skip to content

Commit 7f0e6c0

Browse files
author
coderzcr
committed
fix(docsify配置): 改进GitHub Pages环境检测并增强路径处理
- 增强GitHub Pages环境检测逻辑,添加路径检查 - 添加调试日志输出环境信息 - 扩展别名映射配置,确保各级别目录路径正确解析 - 优化basePath处理逻辑,提高部署兼容性
1 parent ef40f2b commit 7f0e6c0

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

index.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,44 @@
3939
<div id="app"></div>
4040
<script>
4141
// 动态设置basePath,适配本地开发和GitHub Pages部署
42-
const isGitHubPages = window.location.hostname.endsWith('github.io');
42+
// 改进GitHub Pages环境检测逻辑
43+
const isGitHubPages = window.location.hostname.includes('github.io') &&
44+
window.location.pathname.includes('/JavaWeb-Project-Source-Share/');
45+
46+
// 记录环境信息用于调试
47+
console.log('[Docsify配置] 当前环境:', window.location.hostname);
48+
console.log('[Docsify配置] 路径:', window.location.pathname);
49+
console.log('[Docsify配置] 识别为GitHub Pages:', isGitHubPages);
50+
51+
// 确定基础路径
52+
const basePath = isGitHubPages ? '/JavaWeb-Project-Source-Share/' : './';
53+
console.log('[Docsify配置] 使用basePath:', basePath);
54+
4355
window.$docsify = {
4456
name: 'JavaWeb项目源码库',
4557
repo: 'coderzcr/JavaWeb-Project-Source-Share',
4658
loadSidebar: true,
4759
subMaxLevel: 0,
4860
auto2top: true,
4961
coverpage: true,
50-
basePath: isGitHubPages ? '/JavaWeb-Project-Source-Share/' : './',
62+
basePath: basePath,
5163
homepage: 'README.md',
5264
relativePath: true, // 启用相对路径处理
5365
alias: {
54-
// 为不同环境的路径提供别名映射
66+
// 增强别名映射,确保所有可能的文件路径都能正确解析
67+
'/JavaWeb-Project-Source-Share/': '/',
68+
'/JavaWeb-Project-Source-Share/_sidebar.md': '/_sidebar.md',
69+
'/JavaWeb-Project-Source-Share/_coverpage.md': '/_coverpage.md',
70+
'/JavaWeb-Project-Source-Share/README.md': '/README.md',
71+
'/JavaWeb-Project-Source-Share/_404.md': '/_404.md',
5572
'/.*/_sidebar.md': '/_sidebar.md',
56-
'/.*/_coverpage.md': '/_coverpage.md'
73+
'/.*/_coverpage.md': '/_coverpage.md',
74+
// 为各级别目录添加别名
75+
'/newcomer/.*': '/newcomer/$1',
76+
'/easy/.*': '/easy/$1',
77+
'/medium/.*': '/medium/$1',
78+
'/difficult/.*': '/difficult/$1',
79+
'/expert/.*': '/expert/$1'
5780
},
5881
search: {
5982
maxAge: 86400000,

0 commit comments

Comments
 (0)