I have a static website using handlebars and metalsmith. I can create a collection
called carriers
from my metalsmith config file but the plugin pattern
ignores the markdown files so carriers
is always empty
My JS file has metalsmith config as follows
...//other metalsmith plugins
.use(
collections({
carriers: { pattern: '**/*.md' }
})
)
.use(markdown())
.use(
layouts({
engine: 'handlebars',
directory: './src/layouts',
partials: './src/partials'
})
)
...//other metalsmith plugins
And my carriers.hbs
contains the following
<section id="carriers" class="integrations">
<div class="cards">
{{log collections}}
{{#each collections.carriers }}
<h5>{{this.title}}</h5>
{{/each}}
</div>
</section>
The {{log collections}}
Handlebars built-in helper logs this { carriers: [ metadata: undefined ] }
and the generated html file looks like this
<main>
<section id="carriers" class="integrations">
<div class="cards">
</div>
</section>
</main>
So what am I missing here?
Update
So I got more experience with Metalsmith and now got to know why the markdown files were not available. This is because of theMetalsmith.source('my-directory')
did not contain the markdown files and they were in another folder.
Sadly, I don't have a solution for this because my project was too big to track down with my little experience in Metalsmith. However, the main points that I believe causing the problems and to watch out for are
markdown()
must be before layouts()
) otherwise you might get an error or unexpected outcomescollections
plugin