你能在布局中使用Jekyll页面变量吗?

Ale*_*nde 12 css jekyll

我正在使用Jekyll作为我的博客,我希望能够在特定帖子中使用独特的CSS样式.现在,我正在YAML前端中指定一个CSS文件,如下所示:

style: artdirection.css
Run Code Online (Sandbox Code Playgroud)

并在布局中使用它像这样:

{% if page.style %}
    <link rel="stylesheet" href="{{ page.style }}">
{% endif %}`
Run Code Online (Sandbox Code Playgroud)

这有效,但我更喜欢在页面的frontmatter中的样式标记中包含实际的CSS样式,而不是链接到样式表.

我试过用两种方法处理这个问题,包括这里描述的方法,但是我捕获的变量只能在帖子本身内部使用,而不能在布局中使用.

那么,有可能吗?

kik*_*ito 17

我很确定这会起作用:

---
title: xxx
style: |
  /* You can put any CSS here */
  /* Just indent it with two spaces */
  /* And don't forget the | after "style: " */
  h2 {
    color: red;
  }
---

Your markdown/textile goes here. h2s will be red
Run Code Online (Sandbox Code Playgroud)

然后在你的布局中:

<style type="text/css">
{{ page.style }}
</style>
Run Code Online (Sandbox Code Playgroud)

这应该是它.


Cir*_*四事件 9

杰基尔3改变了

现在,布局front-matter(_layouts/default.html)中声明的变量可通过以下方式显示:

{{ layout.style }}
Run Code Online (Sandbox Code Playgroud)

而不是旧的:

{{ page.style }}
Run Code Online (Sandbox Code Playgroud)

https://github.com/jekyll/jekyll/issues/4123

  • 这是一个非常难以实现的突破性变化,感谢您的加入 (4认同)