Jekyll:在 SCSS 部分中使用来自 _config.yml 的值

Jekyll: Using values from _config.yml in SCSS partial

在我的 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 %}

我想 @importcolors.scss 文件放入 main.scss,但是当我这样做时,出现以下错误:

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 文件的值?

只有你的 main.scss 会被 Jekyll 解析。

一旦用 Liquid 解析,它就会被传递给 sass/scss 处理器。因此,任何@imported 文件都不会被 Liquid 解析。