Nathan Friedly
Nathan Friedly

Reputation: 8166

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?

Upvotes: 2

Views: 135

Answers (2)

Nathan Friedly
Nathan Friedly

Reputation: 8166

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)

Upvotes: 1

Peter Flannery
Peter Flannery

Reputation: 2101

There is a plugin which combines files together after the render process.

It's very simple to use, get it here -> docpad-plugin-combiner

An example of how it works:

File 1:

---
combine: true
outPath: portfolio.html
---
#Title 1

File 2:

---
combine: true
outPath: portfolio.html
---
#Title 2

To install, go to your docpad website root folder and run:

npm install --save docpad-plugin-combiner

Upvotes: 1

Related Questions