Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

gruntjs - docpad grunt iteration over all html files

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...