Metalsmith-collection 找不到降价文件

Metalsmith-collection not finding markdown files

我有一个使用 handlebars 和 metalsmith 的静态网站。我可以从我的 metalsmith 配置文件中创建一个名为 carrierscollection,但是插件 pattern 会忽略降价文件,因此 carriers 始终为空

我的 JS 文件有如下 metalsmith 配置

      ...//other metalsmith plugins
      .use(
        collections({
          carriers: { pattern: '**/*.md' }
        })
      )
      .use(markdown())
      .use(
        layouts({
          engine: 'handlebars',
          directory: './src/layouts',
          partials: './src/partials'
        })
      )
      ...//other metalsmith plugins

我的 carriers.hbs 包含以下内容

    <section id="carriers" class="integrations">
      <div class="cards">
        {{log collections}}
        {{#each collections.carriers }}
          <h5>{{this.title}}</h5>
        {{/each}}
      </div>
    </section>

{{log collections}} Handlebars 内置帮助程序记录此 { carriers: [ metadata: undefined ] } 并且生成的 html 文件如下所示

<main>
  <section id="carriers" class="integrations">
    <div class="cards">

    </div>
  </section>
</main>

那么我在这里错过了什么?

Update
So I got more experience with Metalsmith and now got to know why the markdown files were not available. This is because of the Metalsmith.source('my-directory') did not contain the markdown files and they were in another folder.


遗憾的是,我没有解决这个问题的方法,因为我的项目太大了,以我在 Metalsmith 方面的经验不足无法追踪。但是,我认为导致问题和需要注意的要点是

  1. 国际化插件结构很重要,要牢记它如何与其他插件一起工作
  2. 构建过程中插件的顺序(例如 markdown() 必须在 layouts() 之前)否则您可能会遇到错误或意外结果
  3. collections插件的模式