如何在 github 页面上使用 jekyll 设置集合?

How to set a collection with jekyll on github page?

我遵循Collections | Jekyll • Simple, blog-aware, static sites to add collections to my blog wow-yes.github.io的官方指南。

我已将 staff_members 添加到 _config.yml 中。所有来源都存储在 GitHub - wow-yes/blog: my personal blog.

collections:
    my_collection:
        output: true
    staff_members:
        output: true
        people: true

我还将 jane.md 添加到文件夹 _staff_members .

我在本地电脑上测试时,一切正常。 http://127.0.0.1:4000/staff_members/jane.html 效果很好。

但是当我打开 https://wow-yes.github.io/staff_members/jane.html on github page, I get a 404 page Site not found · GitHub Pages

看起来 Github 没有编译 jane.md

谢谢。

这个问题我自己解决了

这个linkhttps://wow-yes.github.io/staff_members/jane.html is wrong. The right one is https://wow-yes.github.io/blog/staff_members/jane.html。 Github 已经编译 jane.md 但我没有得到正确的 link.

github-pages 地址缺少 /blog/。好吧,所以我将 {{site.baseurl}} 添加到 _layout/collections.html 中,为我的 collection 生成正确的 url。它在我的本地服务器和 github-pages.

上运行良好

官方指南Collections | Jekyll • Simple, blog-aware, static sites就在本地服务器上。但是,当您将此代码应用到 github 个页面时,请在 {{ staff_member.url }} 之前添加 {{site.baseurl}}。例如:

{% for staff_member in site.staff_members %}
  <h2>
    <a href="{{ site.baseurl }}{{ staff_member.url }}">
      {{ staff_member.name }} - {{ staff_member.position }}
    </a>
  </h2>
  <p>{{ staff_member.content | markdownify }}</p>
{% endfor %}