diff --git a/_templates/md-viewer.html b/_templates/md-viewer.html
index dae6c31..3d6835d 100644
--- a/_templates/md-viewer.html
+++ b/_templates/md-viewer.html
@@ -122,11 +122,25 @@ if (title) {
if (filePath) {
document.getElementById('doc-path').textContent = filePath;
/* 用绝对路径(/ 开头),避免 在不同浏览器中解析不一致 */
- fetch('/' + filePath)
- .then(res => {
- if (!res.ok) throw new Error('文件未找到 (' + res.status + ')');
+ var fetchUrl = '/' + filePath;
+
+ function tryFetch(url, fallbackUrl) {
+ return fetch(url).then(function(res) {
+ if (!res.ok) throw new Error('HTTP ' + res.status);
return res.text();
- })
+ }).catch(function(err) {
+ /* 主路径失败 → 尝试去掉开头的 / 重新请求 */
+ if (fallbackUrl && url !== fallbackUrl) {
+ return fetch(fallbackUrl).then(function(res) {
+ if (!res.ok) throw new Error('HTTP ' + res.status + ' (fallback)');
+ return res.text();
+ });
+ }
+ throw err;
+ });
+ }
+
+ tryFetch(fetchUrl, filePath)
.then(md => {
/* 检测是否为自带 HTML 结构的文件(如共性需求说明.md) */
const isRawHtml = /^\s*<(?:style|div|!doctype|html)/i.test(md);
@@ -227,9 +241,9 @@ if (filePath) {
}
}
})
- .catch(err => {
- document.getElementById('content').innerHTML = '
加载失败:' + err.message + '
请确认文件路径:' + filePath + '
';
- });
+ .catch(err => {
+ document.getElementById('content').innerHTML = '❌ 加载失败:' + err.message + '
📁 文件路径:' + filePath + '
🔗 请求地址:' + fetchUrl + '
💡 请确认服务器已启动(双击 启动服务器.bat),且文件路径正确
';
+ });
} else {
document.getElementById('content').innerHTML = '未指定文件路径
';
}
diff --git a/index.html b/index.html
index f012bb8..3bbd452 100644
--- a/index.html
+++ b/index.html
@@ -169,19 +169,22 @@ body { background: var(--background); font-family: -apple-system, BlinkMacSystem
-
-
-
-
🚀
-
需要启动本地服务器
-
PRD文档预览等功能需要本地HTTP服务器
-
-
等待服务器就绪...
-
-
+
+
+
+
🚀
+
需要启动本地服务器
+
PRD文档预览、Markdown查看器等功能需要本地HTTP服务器。
请双击项目根目录下的 启动服务器.bat
+
+
+
等待服务器就绪(检测中...)
+
+