mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Add data property to chapter struct

Open bgotink opened this issue 2 years ago • 2 comments

This data property makes it possible to share data between pre-processors, or between pre-processors and the renderer, including the "html" renderer which exposes the chapter data as "data" in the .hbs files.

I've explicitly not provided a built-in way to configure data. Any built-in approach for parsing data would have to be discussed. While I consider hugo/jekyll style front-matter pretty standard for this kind of thing, others might disagree. Even if everyone agreed, the question would then become "what flavours of front-matter do we support?"

I've also explicitly not created any data properties that are used out of the box by mdBook itself.

I'm assuming this PR would need to go in 0.5.0, as it changes the JSON model and any pre-processors compiled with older versions of mdBook would strip the property.

For reference, my use case: I have (many) large JSON files containing data, and I want to use a pre-processor to insert the correct data in every chapter, to then use it in our theme's .hbs file to generate a metadata table, links, that kind of stuff.

Related:

  • Request for chapter metadata: #2142
  • Request for TOML front-matter: #277
  • Other PR adding a data property to chapters: #1465. That PR adds a pre-processor to extrat TOML front-matter, and it defines a few data properties that are built into mdBook. This PR is more limited in scope.
  • Crate mdbook_frontmatter which processes a fixed, limited, set of data properties in YAML front-matter

bgotink avatar Jul 31 '23 22:07 bgotink