docpad grunt iteration over all html files

 ̄綄美尐妖づ 提交于 2019-12-25 07:10:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!