Jekyll define fonts in config.yml

2019-08-02 00:06发布

问题:

I'm trying to define font variables in my jekyll template's _config.yml so that I can use liquid in my css and change all type styles directy from config. Somehow it's not rendering, is this even possible?

This is what I have in my _config:

fonts:

 primary: Roboto Slab

 secondary: Helvetica

And css:

body {
  font-family: '{{ site.fonts.primary }}',{{ site.fonts.secondary }},Arial,sans-serif;
}

回答1:

You have to provide YAML front matter in order for Jekyll to process Liquid tags in the css file:

---
---
body {
  font-family: '{{ site.fonts.primary }}',{{ site.fonts.secondary }},Arial,sans-serif;
}

The --- lines are the start and end of YAML front matter. You do not need to define anything in it.



回答2:

Why not simply declare these variables in your sass file ?