问题
I am using the docpad-plugin-grunt with several grunt tasks. I wonder what is the best way to run tasks over all docpad generated html documents without individual files to be specified in the gruntfile.js. Is there a routine where docpads handing over to grunt all filenames? Can dopad handle the iteration or is a seperated script needed?
回答1:
I don't think grunt is the way to go for this, what you really want to do is hook in to the rendering process that docpad does for each document. Typically, grunt is used to run a task at the end of the generation to do something that docpad doesn't do out of the box.
To intercept docpad's rendering process you probably want to handle the docpad render event which you define in the events section of the docpad.coffee file.
Assuming you want to minify your html you might do something like this (more or less lifted from the docpad documentation):
render: (opts) ->
# Prepare
{inExtension,outExtension,templateData,file,content} = opts
docpad = @docpad
# Render if applicable
if outExtension in ['html']
opts.content = minifyFunction(content)
来源:https://stackoverflow.com/questions/23934061/docpad-grunt-iteration-over-all-html-files