-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix collapsing toc when clicking on a nested page #149
Conversation
/** | ||
* 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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the GH UI does not render this due to its content.
Adding a comment here to see the diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT! 💯
Once we get new design we can focus on the css an javascript from scratch. We currently include way too much.
Closes #139
Changes
Screen.Recording.2025-01-07.at.21.47.29.mov
Notes
This is a hacky fix since the source code for this functionality is minified and just copied here.
Doing this properly should be handled after the next major release.