From d984d565526d8b1416d572582ce7a4586691e418 Mon Sep 17 00:00:00 2001 From: Fabien POLLY Date: Tue, 9 Dec 2025 11:47:16 +0100 Subject: [PATCH] feat: Implement dual-path content loading with a flat path fallback and enhance missing page error reporting with detailed troubleshooting. --- index.html | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index c45a20f..d8cca6b 100644 --- a/index.html +++ b/index.html @@ -917,9 +917,27 @@ if (STATE.contentCache[cacheKey]) { text = STATE.contentCache[cacheKey]; } else { - const res = await fetch(`./wiki/${folder}/${filename}`); - if (!res.ok) throw new Error(`HTTP ${res.status}`); - text = await res.text(); + // ATTEMPT 1: Structure Path + try { + const path1 = `./wiki/${folder}/${filename}`; + const res = await fetch(path1); + if (res.ok) { + text = await res.text(); + } else { + throw new Error("404"); + } + } catch (e) { + // ATTEMPT 2: Flat Path (Fallback) - "AUTO-FIX" + console.warn(`Attempt 1 failed for ${folder}/${filename}. Trying flat path...`); + const path2 = `./wiki/${filename}`; + const res2 = await fetch(path2); + if (res2.ok) { + text = await res2.text(); + } else { + // If both fail, throw detailed error + throw new Error(`Content not found. Tried:\n1. ./wiki/${folder}/${filename}\n2. ./wiki/${filename}`); + } + } STATE.contentCache[cacheKey] = text; } @@ -965,7 +983,18 @@ } catch (e) { console.error("Load failed", e); - viewer.innerHTML = `

Page Not Found

Could not load content: ${filename}

Check if the file exists in your wiki/ folder and if .nojekyll exists in repo root.

`; + const cleanError = e.message.replace(/\n/g, '
'); + viewer.innerHTML = ` +

Page Not Found

+
+ Error Details:
${cleanError} +
+

+ Troubleshooting:
+ 1. Ensure the file exists in your wiki/ folder.
+ 2. Check capitalization (Linux/GitHub is case-sensitive).
+ 3. Verify .nojekyll is at the root of your repo. +

`; } }