|
39 | 39 | <div id="app"></div> |
40 | 40 | <script> |
41 | 41 | // 动态设置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 | + |
43 | 55 | window.$docsify = { |
44 | 56 | name: 'JavaWeb项目源码库', |
45 | 57 | repo: 'coderzcr/JavaWeb-Project-Source-Share', |
46 | 58 | loadSidebar: true, |
47 | 59 | subMaxLevel: 0, |
48 | 60 | auto2top: true, |
49 | 61 | coverpage: true, |
50 | | - basePath: isGitHubPages ? '/JavaWeb-Project-Source-Share/' : './', |
| 62 | + basePath: basePath, |
51 | 63 | homepage: 'README.md', |
52 | 64 | relativePath: true, // 启用相对路径处理 |
53 | 65 | 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', |
55 | 72 | '/.*/_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' |
57 | 80 | }, |
58 | 81 | search: { |
59 | 82 | maxAge: 86400000, |
|
0 commit comments