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()}
`;