foundation / panini

A super simple flat file generator.
Other
592 stars 104 forks source link

modifying render() to prevent recursion? #163

Open mmilano opened 6 years ago

mmilano commented 6 years ago

modification assistance request: Are there any suggestions about how to modify panini.render() to

  1. allow a page content template (page.html) to include itself i.e. {{> body}}
  2. but prevent infinite recursive rendering.

right now, that will result in a render loop.

advice?

or, alternatively, a way to access the rendered body - the var page in render() or better yet, the partial 'body' - from other helpers?

gakimball commented 6 years ago

What do you need this for?

mmilano commented 6 years ago

well....since you asked... there are actually a couple of directions stuffed into the question.

context:

Ultimately, i am attempting to build a helper that parses the page's body content and generates a table of contents for the page. Call the helper toc.js.

The process i am working with is:

  1. get the generated page content (which itself might include html, markup, partials, and helpers)
  2. extract headings (to a desired depth), and
  3. output the html for the table of contents (as page navigation via anchor links)

3 i can do, once i have an array or object of headings. That depends on…

2 i hope to do with the help of cheerio.js. doing this depends on…

1.

i experimented with adding the body content with in the nameOfThePage.html page. infinite render loop. node crashes. makes a certain sense, if it is not checked internally.

i tried making toc.js a block helper in the layout-page, with {{> body}} as the block content, like so:

{{#toc}}
{{> body}}
{{/toc}}

but that isn't really the right spirit of how it should work.

I considered adding the page to the pageData object, but that feels needlessly bloated.

Ive tried accessing panini itself, and getting the body content. I can get part-way, but it is the raw content - pre-rendering - and I cant figure out how to get it post-rendered.