How to get collections from sub-folder in docpad?

廉价感情. 提交于 2020-01-05 09:12:57

问题


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?


回答1:


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.




回答2:


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




回答3:


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).




回答4:


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




回答5:


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

@getCollection("html").findAllLive({relativeOutDirPath: {$beginsWith: 'post'}})


来源:https://stackoverflow.com/questions/18375086/how-to-get-collections-from-sub-folder-in-docpad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!