Node.js 如何使用docpad创建物理文件?
有关创建文件的信息太少 这就是我尝试过的:Node.js 如何使用docpad创建物理文件?,node.js,docpad,Node.js,Docpad,有关创建文件的信息太少 这就是我尝试过的: docpad.action("render", { text: content, filename: "random.html.md", path: "./src/documents/posts", attributes: { id: "some-random-id, title: "some-random-title", layout: "default" } }
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")
});
});
它给了我文档实例,但没有创建物理文件 这是我用来创建虚拟文档并将其写入文件的方法
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