Finally had time to experiment with the Hugo SSG pipeline feature for real, and it really let me process sass easily without too much npm. If I did not care about autoprefixer, I could eliminate npm altogether.
I wanted to change the site color palette depending on month, and was able to do it easily with this feature.
I made /myproject/assets/main.scss
, imported scss
files at the top (from the transpiled tachyons-sass library), and then used Hugo template code in it to do the conditional bits.
In <head>
(assumes postcss-cli
and autoprefixer
are installed via npm
), I then get and manipulate the main.scss
per the various other tutorials in here and in the docs, and link the result:
{{ $styles := resources.Get "main.scss" | resources.ExecuteAsTemplate "style.scss" . | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}">
In the /assets/main.scss
:
@import "tachyons-sass/tachyons.scss";
$textHilite: {{ .Site.Params.style.textHilite | default "goldenrod" }} !default;
{{ $mnth := now.Format "January"}}
{{ if eq $mnth "January" }}
$one: #658248 !default;
$two: #a0cf89 !default;
{{ else if eq $mnth "February" }}
...
{{ end }}
...
.one { color: $one; }
.two { color: $two; }
.bg-one { background-color: $one; }
.bg-two { background-color: $two; }
...
::selection {
background-color: $textHilite;
opacity: 0;
}
...
Then you just use the classes in your templates like <footer class="tc center bg-two white-90 pv5 pv6-l ph4">
. When you compile, Hugo will check for the current month, find the right colors and generate the css you need to display them.
Notice also that you can pull from your config.toml
site params, and passing a color var that Tachyons already has set in its defaults worked too:
[params]
ISO8601 = "2006-01-02T15:04:05JST"
googleAnalytics = "UA-12345678-9"
[params.style]
textHilite = "$gold"
...
Slick!