-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Add Level to the Heading struct #10776
Comments
Yea, we can add that. But I think what you ask for gets less obvious if you start from an arbitrary level, e.g.
Building a ToC with this new structure would always need a recursive template, so passing |
I suggest waiting until a use case with more value comes along.
Agreed. |
Could you show a complete example please?
Thanks in advance! |
@l1x This kind of question is better suited for https://discourse.gohugo.io/ so we can focus the discussion on @jmooring 's feature request. However, the error you're encountering is because there's no
But best to ask these question on discourse; something like "Collect headings from .Page" |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Use Case 1
Building a TOC by walking
.Page.Fragments.Headings
works great, and it's easy to control the start and end levels from site and/or page params.However, to do this, the partial needs to keep track of the current Level while walking the map, adding 1 each time it goes a level deeper. This is not difficult to do, but would be a bit easier if we could access
.Level
for each heading.Use Case 2
Control whether or not a TOC is displayed based on the number of headings of a certain level or levels.
If there are 3 or more headings of Level 2, 3, or 4 (combined), then display the TOC, otherwise don't.
I could walk the map once to get the counts, then walk it again to render, but it would be easier if I could get the counts up front. While some sort of count method would be ideal, adding
Level
would be sufficient.The example above works because
sort
removes the first level keys.The text was updated successfully, but these errors were encountered: