sintaxi / harp

Static Web Server/Generator/Bundler
http://harpjs.com
5k stars 342 forks source link

Generating a Table Of Contents #540

Closed AquaGeneral closed 4 years ago

AquaGeneral commented 8 years ago

I'm trying to create a automatically generated table of contents in my documentation page. Basically I need to go through the documentation text, find the elements I'm interested in by name and add those to the table of contents accordingly. It should also link directly to the elements.

I've placed the contents of the documentation into _documentationBase.jade. There is then a documentation.jade page that will add the table of contents and the documentation itself. What I am stuck on is I want to get a DOM represntation of the partial _documentationBase.jade.

The partial gives me a big string, and to find the parts I want out of that I want it to be a Document so I can call things like getElementsByName and more. To create a DOM object out of the string, it's possible to use the following:

Constructing a JS Document or DOMParser as unbuffered code in Jade results in the following error:

TypeError - Document is not a function

So what is the best way to go about this? I could easily make the table of contents on the client side, but that really is not a good use of Harp. I'm guessing there's possibly some much more simple way to go about this?

AquaGeneral commented 7 years ago

@sintaxi Sorry to both but I really still would like some guidance on this.

sintaxi commented 7 years ago

You may find this blog post useful. It teaches some techniques that I think you will find helpful.

https://medium.com/@magician03/how-to-host-portfolio-and-blog-using-github-pages-harpjs-bb301dd901ac