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/';