From 14ab203ca9492fb2a24969627e106d3477ca94f1 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 7 Jan 2025 21:42:13 +0100 Subject: [PATCH 1/2] Fix collapsing toc when clicking on a nested page --- src/Elastic.Markdown/_static/shibuya.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Elastic.Markdown/_static/shibuya.js b/src/Elastic.Markdown/_static/shibuya.js index 4a69c30ee..a1025f24f 100644 --- a/src/Elastic.Markdown/_static/shibuya.js +++ b/src/Elastic.Markdown/_static/shibuya.js @@ -14,3 +14,28 @@ iconify-icon/dist/iconify-icon.mjs: * @version 2.1.0 *) */ + +/** + * Expands all collapsed parent sections in the navigation tree that contain the current page link. + * This ensures the current page is visible in the navigation by opening all ancestor collapsible sections. + * The function works by: + * 1. Finding the navigation link matching the current page URL + * 2. Walking up the DOM tree from that link + * 3. Expanding any collapsed parent sections by toggling their CSS classes + */ +function expandCurrentPage() { + const currentPathname = window.location.pathname; + const currentLink = document.querySelector(`a[href="${currentPathname}"]`); + if (currentLink) { + let parent = currentLink.parentElement; + while (parent) { + if (parent.classList && parent.classList.contains('_collapse')) { + parent.classList.remove('_collapse'); + parent.classList.add('_expand'); + } + parent = parent.parentElement; + } + } +} + +expandCurrentPage(); \ No newline at end of file From 2f34a6e0a7575509a8f950015fb2a67ed45c4bb8 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 7 Jan 2025 21:56:22 +0100 Subject: [PATCH 2/2] Add newline at EOF --- src/Elastic.Markdown/_static/shibuya.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elastic.Markdown/_static/shibuya.js b/src/Elastic.Markdown/_static/shibuya.js index a1025f24f..b2dc6de01 100644 --- a/src/Elastic.Markdown/_static/shibuya.js +++ b/src/Elastic.Markdown/_static/shibuya.js @@ -38,4 +38,4 @@ function expandCurrentPage() { } } -expandCurrentPage(); \ No newline at end of file +expandCurrentPage();