问题描述
我正在使用docpad-plugin-grunt和几个grunt任务。我想知道在gruntfile.js中没有指定单个文件的情况下,如何在所有docpad生成的html文档上运行任务的最佳方式。 docpads是否有一个例行程序来处理所有文件名? dopad可以处理迭代,还是需要分离的脚本?
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?
推荐答案
我不认为咕噜是这样的方式,你真正想要做的是钩住呈现docpad为每个文档所做的过程。通常情况下,grunt被用于在该生成结束时运行一项任务,以便执行docpad不会立即执行的操作。
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.
要拦截docpad的渲染过程可能需要处理在docpad.coffee文件的events部分中定义的。
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.
假设你想缩小你的html,你可能会这样做(或多或少地从docpad文档中解除):
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)
这篇关于docpad grunt遍历所有html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!