私のテンプレート:
{{#each collections }}
<span class="Category__Title">{{ @key }}</span>
{{#each this }}
<a href="{{ this.path }}">{{ this.title }}</a>
{{/each}}
{{/each}}
レンダリング ( this.path は undefined ):
<span class="Category__Title">French</span>
<a href="">Braised vegetables</a>
<span class="Category__Title">Thai</span>
<a href="">Rice noodles</a>
私は金属細工師を使用しています:
metalsmith
.use(collections())
.use(markdown())
.use(templates({
engine: 'handlebars',
directory: 'templates'
}))
.use(permalinks({
pattern: ':title'
}))
.destination('./public')
コンパイル時に、ログをコレクションにコンソールします
var m = metalsmith.metadata();
console.log(m.collections);
そして、各コレクションにはファイルの配列があり、各ファイルにはキー「パス」が含まれていることがわかります。コンソールログ ->
{ title: 'Braised vegetables',
date: '10/12/1923',
tags: [ 'braise', 'old world' ],
collection: [ 'french' ],
template: 'recipe.hbt',
contents: <Buffer 3...>,
mode: '0644',
stats: { },
path: 'women-s-liberation-1906' }
変?ノードを介してプログラムでfile.pathにアクセスできます。さらに、Handlebars は file.title およびその他すべてのキーにアクセスできます。助けてくれてありがとう。