Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 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 Reply

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) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...