无法通过液体访问 Jekyll 默认的 yaml front-matter

Jekyll default yaml front-matter not accessible via liquid

在我的个人网站上,我根据 post 的类别设置主页上 post 列表的样式。所以如果我有前面的问题:

---
layout: post
title:  "My Post"
date:   2016-01-26
category: code
---

因为类别是 code,所以下面的 div 将呈现 css class card-code 并设置 post 的样式相应地摘录。

  {% for post in site.posts %}
    <div class="col-1-2">

      <!-- This Line! -->
      <div class="paper-card card-{{ post.category }}">

         <!-- other code -->
      </div>
    </div>
  {% endfor %}

为了让我的生活更简单,我在 _config.yml 文件中将 post 的默认类别设置为 general

default:
  -
    scope:
      path: ""
      type: "posts"
    values:
      category: "general"

然而,{{ post.category }} 对于这些 post(即 card-)没有任何结果。知道为什么这不起作用吗?

阅读 Front Matter Defaults 的文档,该部分应称为 defaults 而不是 default

在您的 _config.yaml

中试试这个
defaults:
  -
scope:
  path: ""
  type: "posts"
values:
  category: "general"