Any way to get deeper information about a page's content than just {{ .Content }}?

Hello.

Is there any way for a template to drill down deeper into a page’s content, beyond just using {{ .Content }}? Ideally, I’d like to be able to loop over the individual headings defined in the Markdown content, as well as the paragraphs under those headings. I don’t see any way to do this though.

My use case is for generating a Lunr search index.json file. All the examples I’ve seen pack the entire page’s various headings and paragraphs into one single text block. This doesn’t work well for me. I want the json file to have separate entries for each heading, with a text block containing all paragraphs directly under that heading.

Is there any way to do this, or do I need to write an external program to parse the content files?

No .Content is monolithic. There are workarounds. Search the closed Github issues of Hugo, there was a recent one about dividing .Content

But I’m using front matter parameters for the Lunr.js index. It’s extra work but it’s the best way to put the info I need and keep the size of the JSON reasonable.

There is .TableOfContents, which works well as part of a Lunr index.

1 Like

Thanks. I looked into these options and they don’t seem good enough to me. I guess I’ll write an external tool.