-
-
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
Table of Contents (ToC) not always rendered #2433
Comments
I have a similar problem when trying to render the summary of other pages. I use a taxonomy called {{ $pageset := .Get 0 -}}
{{ $pages := .Site.Taxonomies.pagesets.Get $pageset }}
{{ range $pages }}
<div class="pageset-block">
<h2>
<a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a>
</h2>
<p>{{ .Page.Summary }}</p>
</div>
{{ end }} I am not familiar with the Go programming language but I was able to follow the build process to the following lines:
My use case is a sort of "index page" for the pages in the @targodan where you able to find a solution/work around for your problem? |
@stefano-pogliani Sadly I wasn't, I just created the ToC by hand. 😒 . I have gathered a bit of experience with go. If I find the time I'll take a look at the code you found over the weekend. |
In Hugo 0.17 shortcodes are processed as late as possible -- but do not expect us to lift the laws of physics: We cannot create a summary for the page etc. before we have processed the shortcodes, a shortcode cannot list the content that surrounds it ... Use regular templates for these operations. I'm closing this now. This belongs on the discussion forum. |
@bep I don't know about the summary problem but ToCs are a feature of hugo that does not work. Ergo this issue should not be closed. In the name of being constructive: I looked at the code @stefano-pogliani found and were a bit confused by the order in which things are done. First shortcodes are handled and then the ToC is created. Unless I have not considered something important this contradicts your statement of "shortcodes are processed as late as possible". Please take a look at my commit targodan/hugo@7473e32 I tested it and now the ToC in shortcode works. Yes, this propably means that shortcodes in headings might act weiredly (the next thing I will test) but now the ToC works. On the other hand, if not in shortcodes then where can we use the |
I opened a post in the discussion forum: https://discuss.gohugo.io/t/toc-not-working-in-shortcodes/4347 |
I'll reopen this -- thinking about it this may be possible to do without too much work. But a PR that just moves some lines and "it works for me" will not be merged. Tests! |
Of course. I only went for a quick shot without tests because you closed the issue and I didn't want to waste my time, not knowing if this will be reopened. I will add some tests and then open a pull request. I hope to find the time over the weekend but can't promise anything, as I haven't looked at how you guys do your testing yet. |
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. |
I wanted to add a ToC to some of my posts and found that it is not being rendered under certain circumstances.
My setup
Using the blackburn theme, added a shortcode called
/layouts/shortcodes/toc.html
:Added a post called
/content/post/test.md
:Hugo version:
Hugo Static Site Generator v0.16 BuildDate: 2016-09-01T17:43:30+02:00
The rendered result
When I just execute hugo like this
The ToC is not rendered / is empty.
The same thing happens when I execute hugo as a server.
When executing as server and I modify and save the
/layouts/shortcodes/toc.html
it renders the ToC.When I now change and save the
/content/post/test.md
again, the ToC disappears again.Under any circumstances I did not get any errors.
By "does not render / is empty" I mean the result looks like this in the markup.
The text was updated successfully, but these errors were encountered: