0

So, this is admittedly a niche question. It has to do with metalsmith-collections via gulpsmith.

I'm adding a blog to a static site and using metalsmith via gulpsmith to do so.

I'm having trouble using metalsmith-collections with this setup, though it seems like everything should be working fine.

I'll attempt to show my relevant code.

Here's my (I think) relevant required modules:

var gulp = require('gulp');
var metalsmith = require('metalsmith');
var gulpsmith = require('gulpsmith');
var markdown = require('metalsmith-markdown');
var collections = require('metalsmith-collections');

I have a gulp 'blog' task that otherwise works as expected.

gulp.task('blog', function() {
  return gulp
  .src(blogInput)

  .pipe(gulp_front_matter()).on("data", function(file) {
    assign(file, file.frontMatter);
    delete file.frontMatter;
  })

 .pipe(
   gulpsmith()
   .use(collections({
     posts: {
       pattern: '/src/blog/*.md',
       sortBy: 'date',
       reverse: true
      }
    }))
  )

  .pipe(gulp.dest(blogOutput))

});

I want to output a list of my latest blog posts.

So, my hbs template is as follows:

<article>
  <ul>
      {{#each collections.posts}}
          <li>
              <h3>{{this.title}}</h3>
              <article>{{this.contents}}</article>
          </li>
      {{/each}}
  </ul>

The problem code is apparently above:

{{#each collections.posts}}

Nothing gets output there.

Well, technically, the output is this:

<article>
  <ul>
  </ul>
</article>

No iterating through the array of posts that is supposed to be generated.

Not sure if this is all the relevant code, but I'm happy to add more for any help troubleshooting.

Any suggestions greatly appreciated.

UPDATE

var blogInput = './src/blog/*.md';
var blogOutput = './blog/';
Donkey Shame
  • 754
  • 3
  • 18
  • care to show what's the content of `blogInput`? it could be that the whole problem resides in the way you pass the `pattern` to `metalsmith-collection` (which should be relative to the root of the src files passed to metalsmith). – Mr Peach Aug 02 '17 at 08:37
  • @MrPeach: I've updated the question above with the information you requested. Thanks! – Donkey Shame Aug 02 '17 at 23:01
  • have you tried updating the `pattern` to be something more generic like `*.md` as it should work starting from the list grepped in the `blogInput` – Mr Peach Aug 05 '17 at 11:19
  • @MrPeach I've now tried that, but with no luck. I appreciate your help, but no dice so far. – Donkey Shame Aug 13 '17 at 12:52

0 Answers0