Discussion:
[hakyll] expanding template variables in CSS file
j***@devietti.net
2016-06-30 07:28:20 UTC
Permalink
Hi there,

I like to use template variables in my CSS files for things like colors
that are referenced repeatedly. This was working great for me in a previous
version of Hakyll (I forget which, unfortunately), but upon upgrading to
4.8.3.2 this no longer works for me. Here's the rule I was using before:

match "css/*" $ do
route idRoute
compile $ do
getResourceBody
= applyAsTemplate defaultContext
I can compile my site without warnings, but when I run "./site rebuild" I
get this error:

Missing field $Blue$ in context for item css/my.css

For reference, my.css looks like this:

---
Blue: #01256e
---

a {
color: $Blue$;
text-decoration: underline;
background: transparent;
}


When I add the needed fields manually to a new context, everything works
again. Some built-in fields (like $url$ and $path$) are being expanded as
usual. I think the issue is that the embedded metadata fields are not
getting picked up by defaultContext, but I'm not sure how to fix it.

thanks!
joe
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jasper Van der Jeugt
2016-06-30 08:46:22 UTC
Permalink
Hey joe,

Thanks for posting the code, I was able to reproduce the problem
easily. The issue was actually caused by the fact that Hakyll moved
to a proper YAML parser for the metadata. This parses thinks
`#01256e` is a comment, so it fails to parse the metadata since there
is no value for `Blue`. It can be fixed by quoting the colour in your
CSS file like this:


---
Blue: "#01256e"
---

a { ... }

Hope this helps,
Peace,
Jasper
Post by j***@devietti.net
Hi there,
I like to use template variables in my CSS files for things like colors that
are referenced repeatedly. This was working great for me in a previous
version of Hakyll (I forget which, unfortunately), but upon upgrading to
match "css/*" $ do
route idRoute
compile $ do
getResourceBody
= applyAsTemplate defaultContext
I can compile my site without warnings, but when I run "./site rebuild" I
Missing field $Blue$ in context for item css/my.css
---
Blue: #01256e
---
a {
color: $Blue$;
text-decoration: underline;
background: transparent;
}
When I add the needed fields manually to a new context, everything works
again. Some built-in fields (like $url$ and $path$) are being expanded as
usual. I think the issue is that the embedded metadata fields are not
getting picked up by defaultContext, but I'm not sure how to fix it.
thanks!
joe
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
j***@devietti.net
2016-06-30 14:06:34 UTC
Permalink
Thanks! It works great now.

joe
Post by j***@devietti.net
Hi there,
I like to use template variables in my CSS files for things like colors
that are referenced repeatedly. This was working great for me in a previous
version of Hakyll (I forget which, unfortunately), but upon upgrading to
match "css/*" $ do
route idRoute
compile $ do
getResourceBody
= applyAsTemplate defaultContext
I can compile my site without warnings, but when I run "./site rebuild" I
Missing field $Blue$ in context for item css/my.css
---
Blue: #01256e
---
a {
color: $Blue$;
text-decoration: underline;
background: transparent;
}
When I add the needed fields manually to a new context, everything works
again. Some built-in fields (like $url$ and $path$) are being expanded as
usual. I think the issue is that the embedded metadata fields are not
getting picked up by defaultContext, but I'm not sure how to fix it.
thanks!
joe
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...