2013-10-19 15 views
0

關於創建文件,docpad API page中的信息太少。如何用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" 
    } 
}, function(error, outContent, doc) { 
    res.json({ 
     id: doc.get("id") 
    }); 
}); 

它給我的文檔實例,但有被創建任何物理文件。

回答

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 
的方法