docpad subdirectory rendered into general director

2019-08-13 00:58发布

How to move files from src/documents/posts/post1.html to out/post1.html without the subfolder posts appearing in the out directory?

I have a sub directory posts in my documents

src/
    documents/
        index.html
        contact.html
        posts/
            post1.html
            post2.html

And I want the posts to be in out/post1.html not out/posts/post1.html.

标签: docpad
1条回答
啃猪蹄的小仙女
2楼-- · 2019-08-13 01:19

Turns out you can set the relativePath property to whatever you want

@getCollection("html").findAllLive(..).on 'add', (document) ->
    newRelativePath = document.get('relativePath').replace('posts/','')
    document.set('relativePath', newRelativePath)

ImportantNote:

if you use a findAllLive whith a selector that includes the relativePath and then change the relativePath, the document will be removed from the collection. Alternatively you can set another flag and use it for finding.

@getCollection("html").findAllLive({$or:{relativeOutDirPath:'posts', isPost: true}}).on 'add', (document) ->
    document.set('relativePath', newRelativePath)
            .setMeta({isPost: true})
查看更多
登录 后发表回答