2

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?

Nathan Friedly
  • 7,837
  • 3
  • 42
  • 59
  • 1
    Did you ever find an answer to this? I'm having the same issue (wish to use a collection of files with write:false) – M-Pixel Nov 03 '14 at 05:27
  • Yes, sorry I forgot about this, I posted an answer below now: http://stackoverflow.com/a/26721750/933879 – Nathan Friedly Nov 03 '14 at 19:39

2 Answers2

1

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
Peter Flannery
  • 2,061
  • 1
  • 16
  • 5
  • Cool, I didn't know about that. I think I'm going to stick with my current setup for now because I'd like to use my main layout without having to split it into start and end files, but I'll keep this in mind. – Nathan Friedly Nov 20 '13 at 18:07
1

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)

Nathan Friedly
  • 7,837
  • 3
  • 42
  • 59