metalsmith/collections

"pattern:" does not work in CLI

BitFis opened this issue · 14 comments

Somehow i can only add files to my collection by setting the metadata collection in the file.
I can not select any files with the pattern attribute like following:

"metalsmith-collections": {
    "articles": {
        "pattern": "*.md"
    }
}

or

"metalsmith-collections": {
    "articles": "*.md"
}

This will only give me an empty collection in the template

sigo commented

I think it don't depends on pattern, but it just don't work for CLI.

Any chance that that will be fixed?

@BigZ94 why don't you link to your repo and I'll see if I can have a look for you.

Bump. Any idea when this issue will be fixed?

I'm following the tutorial at: http://www.robinthrift.com/posts/metalsmith-part-2-shaping-the-metal/

However, the collection (if defined in the index.js as a pattern) doesn't work.

I don't know if this is relevant, but it's caught me out a few times. What I have noticed is that in various metalsmith plugins. they don't go deeper than the folder stated. I'm not sure if it's the same with collections. So I only have 1 collection per folder.

I only had one collection and the CLI didn't work for me either.

Something to watch out for, that I just see. The order of where the metalsmith-collections in the metalsmith.json file matter. If you move it after metalsmith-markdown the files which are being sent to metalsmith-collections will have a .htmlextension, and will not match *.md

$ DEBUG=metalsmith-collections metalsmith, will show which files are actually being matched.

1__tbones-mbp__node_

* disclosure: I use grunt-metalsmith, not the pure metalsmith.json and CLI approach

nlundquist, did you get this fixed? All the 'not working' posts in this thread have little info and follow-up. This feature does and has always worked for me in metalsmith, but I've had a few frustrating hours with some of the other plugins that needed a specific setup to work.

The plugin nature of Metalsmith clearly opens up opportunities, but it also seems to present issues due to the linear nature when parsing the plugins (so one thing must be before another, but after something else, and therefore certain combinations might not work).

If it helps, In my build.js, the first plugin is collections, setup like this:

Metalsmith(__dirname)
.use(collections({
pages: {
pattern: 'pages/
.md'
},
posts: {
pattern: 'posts/.md',
sortBy: 'date',
reverse: true
}
})

The folders pags and posts are in an src folder.

@simplyeffectiveweb 👍

I have run into the same issue. The pattern matching simply would not work via the CLI. I tried using every available example to see if it was just something I was doing wrong but nothing worked. Once I changed to use the metadata, it worked right away.

I am currently using the CLI with this plugin, and it works just fine. As mentioned previously, metalsmith-collections is the very first plugin I invoke:

  "plugins": {
    "metalsmith-collections": {
      "static": {
        "pattern": {"*.{html,xml,txt,png,ico}", },
        "refer": false
      },
      "error": {
        "pattern": "{403,404}.md",
        "refer": false
      },
      "articles": {
        "pattern": "content/articles/*.md ",
        "reverse": true
      },
      "recent-articles": {
        "pattern": "content/articles/*.md",
        "reverse": true,
        "limit": 5
      }
    },
    ...

The bug looks like already fixed. The pattern works both via CLI and metadata. The only pitfall is that pattern's path is relative to source folder. So if .source('./src'), then pattern: '*.md', not pattern: './src/*.md'

This pitfall could be better documented as I suppose it's kind of obvious once you already know it. However my pattern ./*.md doesn't work. I have to lose the current folder prefix ./ then it works.