docpadquery-engine

How do I get a collection of files with `write: false` in DocPad


I have a setup like so:

portfolio.html.eco
portfolio/
  - project1.html.md
  - project2.html.md
  - etc.

I want this to all be combined into a single large portfolio.html file in the out/ directory. All of my project files have the write: false metadata which prevents them from being written.

I've tried doing a few variations on this in my portfolio.html.eco but they all seem to get an empty collection:

<% for project in @getCollection("documents").findAll({relativePath: 'portfolio'}).toJSON() %>

But I always get an empty list. I also tried this:

@getFilesAtPath('portfolio/') 

It does get me the correct content, but it hasn't been rendered yet. Update: it has been rendered, I was using the body value instead of contentRendered.

Can anyone explain what I'm doing wrong with the collection version? Does having write: false prevent documents from being included in the collection?


Solution

  • What I ended up doing was removing the write: false from the files and instead creating the collection first and then programmatically adding the write: false to the documents once they were in the collection:

    module.exports = {
        collections: {
            projects: function() {
                var projects = this.getFilesAtPath('projects', [{filename:1}]);
                projects.each(function(project) {
                    project.setMetaDefaults({'write': 'false'});
                });
                projects.on("add", function (model) {
                    model.setMetaDefaults({'write': 'false'})
                });
                return projects;
            },
            // ...
    

    (You can see the full source at https://github.com/nfriedly/nfriedly.com/blob/master/docpad.js#L81)