diff options
author | Regis Philibert <login@regisphilibert.com> | 2021-06-15 16:58:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-15 16:58:27 +0300 |
commit | 6eb54ab5fd8b4932b0123d1fdf94d8026aa67ef6 (patch) | |
tree | a399f8332e77e68744bfd64245ad184fdc806079 /layouts | |
parent | 988c731a5762a6e0a1aad4fd2023caa2dc1e082d (diff) |
Refactor styling to drop PostCSS (#424)
Update custom_css logic (ensure retrocompat)
Fixes #423
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/func/style/GetMainCSS.html | 50 | ||||
-rw-r--r-- | layouts/partials/func/style/GetResource.html | 19 | ||||
-rw-r--r-- | layouts/partials/site-style.html | 30 |
3 files changed, 75 insertions, 24 deletions
diff --git a/layouts/partials/func/style/GetMainCSS.html b/layouts/partials/func/style/GetMainCSS.html new file mode 100644 index 0000000..ef33b1d --- /dev/null +++ b/layouts/partials/func/style/GetMainCSS.html @@ -0,0 +1,50 @@ +{{/* + style/GetMainCSS + Process the main css stylesheet and return as resource + + @author @regisphilibert + + @context Any (.) + + @returns Resource + + @uses + - func/style/GetResource +*/}} +{{ $main_style := dict }} + +{{/* We prepare a slice of resources to be concatenated as one */}} +{{ $assets_to_concat := slice }} +{{/* We add locale css files to the slice in the proper order */}} +{{ range slice "_tachyons.css" "_code.css" "_hugo-internal-templates.css" "_social-icons.css" "_styles" }} + {{ with partialCached "func/style/GetResource" . . }} + {{ $assets_to_concat = $assets_to_concat | append . }} + {{ end }} +{{ end }} + +{{/* We look for any custom css files registered by the user under `site.params.custom_css and if found in the theme's +css asset directory we add to aforementioned slice */}} +{{ with site.Params.custom_css }} + {{ range . }} + {{ with partialCached "func/style/GetResource" . . }} + {{ $assets_to_concat = $assets_to_concat | append . }} + {{ end }} + {{ end }} +{{ end }} + +{{ with $assets_to_concat }} + {{/* We proceed to concatenate the $assets_to_concat */}} + {{ $style := . | resources.Concat "ananke/css/main.css" }} + + {{/* We then use toCSS to add sourceMap and minify */}} + {{ $options := dict "enableSourceMap" true "precision" 6 }} + {{ $style = $style | resources.ToCSS $options | minify }} + {{/* We fingerprint in production for cache busting purposes */}} + {{ if eq (getenv "HUGO_ENV") "production" }} + {{ $style = . | fingerprint }} + {{ end }} + {{/* We're ready to set returning variable with resulting resource */}} + {{ $main_style = $style }} +{{ end }} + +{{ return $main_style }}
\ No newline at end of file diff --git a/layouts/partials/func/style/GetResource.html b/layouts/partials/func/style/GetResource.html new file mode 100644 index 0000000..99ab1bc --- /dev/null +++ b/layouts/partials/func/style/GetResource.html @@ -0,0 +1,19 @@ +{{/* + style/GetResource + Get a style asset stored at `/assets/ananke/css` + + @author @regisphilibert + + @context String (.) + + @access private + + @returns Resource + +*/}} +{{ $resource := dict }} +{{ with resources.Get (print "/ananke/css/" .) }} + {{ $resource = . }} +{{ end }} + +{{ return $resource }}
\ No newline at end of file diff --git a/layouts/partials/site-style.html b/layouts/partials/site-style.html index d2c25e4..0da5c4b 100644 --- a/layouts/partials/site-style.html +++ b/layouts/partials/site-style.html @@ -1,27 +1,9 @@ -{{/* We only process CSS if below setting is true */}} -{{ if site.Params.ananke_process_css }} - {{ with resources.Get "/ananke/css/main.css" }} - {{/* We use ToCSS on non sass to make sure node_modules paths are included and imported - Then we can run PostCSS on the resulting asset. - `use` setting allow us to skip the postcss.config file. - */}} - {{ $options := (dict "targetPath" "/ananke/css/main.css" "enableSourceMap" true "precision" 6 "includePaths" (slice "node_modules")) }} - {{ $style := . | resources.ToCSS $options | resources.PostCSS (dict "use" "postcss-cssnext") | minify }} - {{/* We fingerprint in production to ensure cache busting */}} - {{ if eq (getenv "HUGO_ENV") "production" }} - {{ $style = . | fingerprint }} - {{ end }} - {{ with $style }} - <link rel="stylesheet" href="{{ .RelPermalink }}" > - {{ end }} - {{ end }} -{{ else }} - {{/* If processing is turned off, we use the assets/dist/main.?.css commited to the repo. */}} - {{ with resources.GetMatch "/ananke/dist/main.*.css" }} - <link rel="stylesheet" href="{{ .RelPermalink }}" > - {{ end }} +{{ with partialCached "func/style/GetMainCSS" "style/GetMainCSS" }} +<link rel="stylesheet" href="{{ .RelPermalink }}" > {{ end }} -{{ range .Site.Params.custom_css }} - <link rel="stylesheet" href="{{ relURL (.) }}"> +{{ range site.Params.custom_css }} + {{ with partialCached "func/style/GetResource" . . }}{{ else }} + <link rel="stylesheet" href="{{ relURL (.) }}"> + {{ end }} {{ end }}
\ No newline at end of file |