I’m trying to figure out the best way for me to include table of contents in pages. Right now I’ve set a page param of tableOfContents which, when set to true, will insert {{ .TableOfContents }} in the page template.
My problem comes with being able to change certain settings for individual pages. My site-wide configuration specifies:
markup:
tableOfContents:
endLevel: 2
Is there any way to change such settings for individual pages in their front-matter? For example, I might set a certain page’s endLevel to include H3 or H4, even though the site-wide configuration specifies H2.
Related Bug
On a related note: this problem is also affected by a bug I’m seeing here in Hugo v0.68.3. (I plan to file a bug report after this). Whenever I enable the Table Of Contents in a situation like this one (without any endLevel specified in the site configuration):
Extra-Curriculars
Testing
Heading Four Here with Heading Three Before It
Technology
Heading Four Here without Heading Three Before It
The Table of Contents comes out looking like this:
I believe the expected behaviour would be for no extra bullet point to appear after the one with an H3 (or for it to appear but include the H4 point).
Work-Around
If I manually set an endLevel, the problem disappears. It is only when one is not set that the problems occur. This bug is what led me to need an endLevel in the first place.
I’m trying to experiment with another site to reproduce, but haven’t been able to thus far. I’m wondering if the problem here is with the bullet points?
Repository
The repository I’m experiencing the issue in is located at https://git.sr.ht/~exprez135/taliaferro. Please note that it’s over 1.1G in size because of media files within.
The public website which is publishes to is found at thetaliaferrotimes.org. The specific page my screenshot came from is the Coronavirus page. At the moment I have a site-wide endLevel: 2 to prevent the problem from occurring.
Environmental Information
hugo env
Hugo Static Site Generator v0.68.3/extended darwin/amd64 BuildDate: unknown
GOOS=“darwin”
GOARCH=“amd64”
GOVERSION=“go1.14”
Irrespective of the bug, which I’ll investigate further, is there any way to change params like the table of contents endLevel or markdown extensions in the front-matter of individual pages?
I don’t know. I was going to add it to your posts and see. Have you tried adding it to front matter (just add the global config options to front matter and change them)? I don’t have a project with tables of contents at the moment.