How to get collections from sub-folder in docpad?

2019-08-02 03:44发布

my folds structure are something like this:

  • documents
    • techs
      • docs

I want to get a collection from docs, my code is :

techs: ->
        @getCollection("html").findAllLive({relativeOutDirPath: /techs/docs/},[{date: -1}]).on "add", (model) ->
            model.setMetaDefaults({layout: "post"})

It just won't works... Could somebody tell me what's going on?

标签: docpad
5条回答
女痞
2楼-- · 2019-08-02 03:56

You may want to use the convenient helper provided by Docpad : getFilesAtPath.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-08-02 03:59

I've had problems depending on what system I'm running node.js and docpad on (ie Windows) with file path conventions. So I resort to the following to make sure I'm not having any of those sort of problems:

 @getCollection("html").findAllLive({relativeOutDirPath:path.join('techs','docs')},[date:-1])

Note the 'path.join' bit

查看更多
贼婆χ
4楼-- · 2019-08-02 04:08

The /techs/docs/ in {relativeOutDirPath: /techs/docs/} is parsed as a regular expression, rather than a string. Wrap it in quotes so you have {relativeOutDirPath: "/techs/docs/"} instead. You may or may not need the initial slash, I can't remember.

查看更多
看我几分像从前
5楼-- · 2019-08-02 04:08

Maybe you should read the file "docpad.coffee"

There is a section "collection", you can set collection named "html", and select all files in (database).

查看更多
啃猪蹄的小仙女
6楼-- · 2019-08-02 04:13

Just as example, all html documents from path starts with "post"

@getCollection("html").findAllLive({relativeOutDirPath: {$beginsWith: 'post'}})
查看更多
登录 后发表回答