From 4c8ca31651fe80b2de38bc5ce3f1b0828508e668 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 21 May 2026 15:27:10 +0000 Subject: [PATCH] fix: hidden categories now auto-switch to default instead of showing error Two bugs fixed in navigateTo: 1. When a category has visibilityifnocontent: hidden (default) and the current page has no variant for it, the renderer now silently switches to the default category before fetching. Previously the category stayed active (kept visible in the selector via the activeCategory guard), the fetch failed, and an error page was shown. 2. The offline message stored in localStorage was shown for any failed fetch, not just genuine offline situations. Now gated on !navigator.onLine so missing pages always show pagenotfoundmessage instead. --- app/index.html | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/index.html b/app/index.html index af6b645..9ac8e70 100644 --- a/app/index.html +++ b/app/index.html @@ -2653,6 +2653,24 @@ function fmtDatetime(dtStr) { const contentEl = document.getElementById('pageContent'); highlightNav(file); + // If the active category is "hidden" (no notfoundmessage, not visibilityifnocontent:visible) + // and this page has no variant for it, silently switch to the default category instead of + // showing an error. + if (categoriesUse && activeCategory !== defaultCategoryCode && file !== defaultPage()) { + const cat = categoriesByCode[activeCategory]; + const isHidden = cat && !cat.notfoundmessage && cat.visibilityifnocontent !== 'visible'; + if (isHidden) { + const pageEntry = navData.find(p => p.file === file); + const hasVariant = !pageEntry || pageEntry.uncategorized + || !(pageEntry.variants && pageEntry.variants.length) + || pageEntry.variants.includes(activeCategory); + if (!hasVariant) { + setActiveCategory(defaultCategoryCode); + return; + } + } + } + // Build a clean URL: keep origin + path, set ?cat only when non-default, set hash to conceptual file const u = new URL(window.location); if (categoriesUse && activeCategory && activeCategory !== defaultCategoryCode) { @@ -2667,7 +2685,7 @@ function fmtDatetime(dtStr) { const result = await fetchPageFile(file); if (!result.ok) { - const offlineMsg = localStorage.getItem('mdcms-offline'); + const offlineMsg = !navigator.onLine && localStorage.getItem('mdcms-offline'); const bodyMsg = offlineMsg ? `

${offlineMsg}

` : `

${pageNotFoundMessage()}

`;