Additional Heading Questions #58
-
Hello, I have two additional heading questions. Firstly, what is the best way to modify the Content pipeline to nest the headings? var topLevelHeadings = Document.GetDocumentList(HtmlKeys.Headings).Where(x => x.GetInt(HtmlKeys.Level) == 1); It works but it's not ideal. Looking at the content pipeline, we have this section: new ExecuteIf(Config.FromDocument(doc => doc.MediaTypeEquals(MediaTypes.Html)))
{
// Excerpts and headings only work for HTML content
new GenerateExcerpt(),
new GatherHeadings(Config.FromDocument(WebKeys.GatherHeadingsLevel, 1))
} https://github.com/statiqdev/Statiq.Web/blob/56064f078eb08eb84aa504c1a6b4a36e2040d83c/src/Statiq.Web/Pipelines/Content.cs#L31-L36 public GatherHeadings WithNesting(bool nesting = true); I was looking at simply removing and replacing the Content pipeline with my own, however I wanted to explore the Second question is fairly straightforward hopefully. The above code to get the top level headings works great on Markdown documents, but on Blazor pages, this returns an empty collection. The end result is that my table of contents only renders on pages which were written in markdown. Is there something I'm doing wrong here Or is this behavior normal and expected? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Fantastic question. The ideal long-term solution would be to surface the nesting option as a setting and build it in. I'll look at doing that in the next release. In the meantime, you could certainly modify the pipeline. That has the advantage of (hopefully) being more compatible as the pipelines continue to evolve (I.e. if you release it wholesale you won't benefit from any future improvements or functionality). On the other hand, this one is tricky since the .ModifyPipeline(
nameof(Pipelines.Content),
x => x.ProcessModules
.GetFirst<CacheDocuments>()
.Children
.ReplaceLast<ExecuteIf>(
new ExecuteIf(Config.FromDocument(doc => doc.MediaTypeEquals(MediaTypes.Html)))
{
// Excerpts and headings only work for HTML content
new GenerateExcerpt(),
new GatherHeadings(Config.FromDocument(WebKeys.GatherHeadingsLevel, 1)).WithNesting()
})) Unfortunately you'd still have to replace the entire
Yeah, it's expected unfortunately. That's what the |
Beta Was this translation helpful? Give feedback.
Fantastic question. The ideal long-term solution would be to surface the nesting option as a setting and build it in. I'll look at doing that in the next release.
In the meantime, you could certainly modify the pipeline. That has the advantage of (hopefully) being more compatible as the pipelines continue to evolve (I.e. if you release it wholesale you won't benefit from any future improvements or functionality). On the other hand, this one is tricky since the
GatherHeadings
module is nested a few modules deep. To modify it would end up looking like: