jnordberg / wintersmith

A flexible static site generator
http://wintersmith.io/
MIT License
3.5k stars 335 forks source link

Can have a plugins generate files? #266

Closed kitsunde closed 9 years ago

kitsunde commented 10 years ago

I have 2 use cases for this.

The first is to build a sitemap.xml of page metadata, currently I've done that by dropping files into the content/ and template/ folder and doing some rather ugly recursive macro calls with nunjucks on the context.

The second is to build a search.json file for lunr.js by similarly crawling over the metadata.

It seems like both ContentPlugin and TemplatePlugin matches against existing files. Generator isn't supposed to modify the tree according to https://github.com/jnordberg/wintersmith/wiki/Writing-plugins#envregistergeneratorcontentgroup-generatorfn

It's not clear to me how to accomplish this.

jnordberg commented 10 years ago

It's a generator you want, the documentation is perhaps a little unclear, the note is because you shouldn't modify the tree passed into a generator but instead return a object with keys corresponding to the files you want to add and they will be merged.

env.registerGenerator 'sitemap', (contents, callback) ->
  rv = {'mysitemap.xml': somePluginInstance}
  callback null, rv