Gioni06 / stasis-generator

A simple and easy to use static site generator
https://getstasis.com/
MIT License
27 stars 4 forks source link

Exposing tree of page headers #8

Open f0x52 opened 5 years ago

f0x52 commented 5 years ago

Hey, for my site I'd like to be able to dynamically generate a list of the current page's sections. Something like Wikipedia's Content block at the start of a page. For this I need to access an array of all header markdown objects from handlebars, and they all need to get an id to use in the anchor tag.

Im not sure what the best place would be to hack this in, any ideas?

Gioni06 commented 5 years ago

Hm.. interesting. The compiler uses unified as a text parsing engine. You could checkout if there is a plugin that extracts this data. You could then attach it to the Edge as a “sections” array.

Gioni06 commented 5 years ago

Maybe a combination of those plugins would do the trick.

https://www.npmjs.com/package/rehype-autolink-headings https://www.npmjs.com/package/rehype-slug https://www.npmjs.com/package/remark-outer-tochttps://www.npmjs.com/package/remark-outer-toc