-
-
Notifications
You must be signed in to change notification settings - Fork 382
fix(navbar): navbar on small screen now follow menu.main from hugo.yaml #883
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for hugo-hextra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for hugo-hextra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Pull request overview
This PR fixes the mobile navbar to properly respect the menu.main configuration in hugo.yaml. Previously, the sidebar when used as a mobile navbar would display all pages and sections. Now it filters items to only show those defined in the main menu configuration.
Changes:
- Added conditional filtering logic in the sidebar partial that detects when the sidebar is used as a navbar (via
IsHomecheck) - Items are now filtered against
menu.mainpaths when rendering the mobile view - Refactored from
withstatement to direct variable assignment to support the new filtering logic
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| {{- $items = $itemsCandidates -}} | ||
| {{- end -}} | ||
|
|
||
| {{- $items = where $items "Params.sidebar.exclude" "!=" true -}} |
Copilot
AI
Jan 19, 2026
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.
The indentation here is inconsistent with the rest of the code block. This line has 4 spaces of indentation, but should have 2 spaces to match the indentation level of lines 81-82 and other statements at the same nesting level.
| {{- $items = where $items "Params.sidebar.exclude" "!=" true -}} | |
| {{- $items = where $items "Params.sidebar.exclude" "!=" true -}} |
| {{- if .context.IsHome -}} | ||
| {{- $allowedPaths := slice -}} | ||
| {{- range site.Menus.main -}} | ||
| {{- with .Page -}} | ||
| {{- $allowedPaths = $allowedPaths | append .Path -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
|
|
||
| {{- range $itemsCandidates -}} | ||
| {{- if in $allowedPaths .Path -}} | ||
| {{- $items = $items | append . -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
|
|
||
| {{- else -}} | ||
| {{- $items = $itemsCandidates -}} | ||
| {{- end -}} |
Copilot
AI
Jan 19, 2026
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.
This complex filtering logic would benefit from an inline comment explaining its purpose. Consider adding a comment like "Filter items to only show pages that are in the main menu when rendering the mobile navbar" to help future maintainers understand why this conditional filtering is needed.
Added detection in the sidebar partial for cases where the sidebar is also used as a navbar, i.e., in mobile view.
This workaround use "IsHome" from context. It fix #240 (comment) and partialy #265 (comment)
This workaround isn’t elegant. It would be better to create a new partial,
side-navbar.html, that relies onsidebar.html. This would allow crawling through menu.main inhugo.yamland discovering the subfolders under each section based on each menu path. (Handling nested menus is still an open question.) This refactor will allow to easily fix #497 (comment), #831 (comment) and #449 (comment) by getting weight and name fromhugo.yaml