Jekyll:在SCSS中使用_config.yml中的值



在我的Jekyll项目中,我的_config.yml文件中有以下内容:

colors:
  - name: red
    hex: '#FF0000'
  - name: yellow
    hex: '#FFFF00'
  - name: blue
    hex: '#0000FF'

assets/css/colors.scss中,我想创建如下颜色的类:

{% for color in site.colors %}
.{{ color.name }} {
  color: {{ color.hex }};
}
{% endfor %}

当我这样做时,我会得到以下错误:

Error in _assets/css/background-test.scss:6 Invalid CSS after "}": expected selector or at-rule, was "{% for color in..." 
  Liquid Exception: Invalid CSS after "}": expected selector or at-rule, was "{% for color in..." in _includes/head.html, included in _layouts/default.html
jekyll 3.0.1 | Error:  Invalid CSS after "}": expected selector or at-rule, was "{% for color in..."

有没有办法让Liquid处理SCSS中_config.yml文件中的值?

如果你想让Jekyll处理你的scss文件,你必须向它添加一个前置事项。

这项工作:

---
# empty front matter
---
@charset "utf-8";
{% for color in site.colors %}
.{{ color.name }} {
  color: {{ color.hex }};
}
{% endfor %}

最新更新