0

docpad API 页面中关于创建文件的信息太少。

这是我尝试过的:

docpad.action("render", {
    text: content,
    filename: "random.html.md",
    path: "./src/documents/posts",
    attributes: {
        id: "some-random-id,
        title: "some-random-title",
        layout: "default"
    }
}, function(error, outContent, doc) {
    res.json({
        id: doc.get("id")
    });
});

它给了我文档实例,但没有创建物理文件。

4

1 回答 1

1

这是我用来创建虚拟文档并将它们写入文件的方法

outDirPath = docpad.config.outPath 

docAttr = {
    fullPath: null
    body: 'some content html to be rendered'
    outPath: outDirPath + '/index.html' # this where it will write the file
    extension: 'md'      
    extensions: ['html', 'md']
    relativePath: 'index.html'
    filename: 'index.html'
    write: true 
    render: true
    layout: 'somelayout'
}

# create the document
virtualDocument = docpad.createDocument(docAttr)
docpad.renderDocument virtualDocument, { templateData: this, someCustomData: extraData}, (err, content, file) ->
    # renderDocument complete callback
    file.write ()->
        # file.write complete callback
        return

    return
于 2013-10-20T00:34:57.107 回答