2021-06-15 15:58:27 +02:00
{{/*
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 */}}
2021-12-23 22:02:15 +01:00
{{ range slice "_tachyons.css" "_code.css" "_hugo-internal-templates.css" "_social-icons.css" "_styles.css" }}
2021-06-15 15:58:27 +02:00
{{ with partialCached "func/style/GetResource" . . }}
{{ $assets_to_concat = $assets_to_concat | append . }}
{{ end }}
{{ end }}
2021-12-02 21:22:18 +01:00
{{ with partialCached "func/socials/Get" "socials/Get" }}
{{ $socials_rules := slice }}
{{ range $service := . }}
{{ with .color }}
{{ $rule := printf `
.ananke-socials a.%s:hover {
color: %s
}` $service.name $service.color }}
{{ $socials_rules = $socials_rules | append $rule }}
{{ end }}
{{ end }}
{{ with $socials_rules }}
{{ $socials_rules = delimit . "" }}
{{ $socials_css := $socials_rules | resources.FromString "ananke/css/generated_socials.css" }}
{{ $assets_to_concat = $assets_to_concat | append $socials_css }}
{{ end }}
{{ end }}
2021-06-15 15:58:27 +02:00
2024-09-17 18:05:21 +02:00
{{/* We look for any custom css files registered by the user under `site.params.custom_css and if found in the theme's
2022-04-21 17:48:54 +02:00
css asset directory we (unless condition below) add to aforementioned slice */}}
2021-06-15 15:58:27 +02:00
{{ with site.Params.custom_css }}
{{ range . }}
{{ with partialCached "func/style/GetResource" . . }}
2022-04-21 17:48:54 +02:00
{{ if eq .MediaType.SubType "x-scss" "x-sass" "scss" "sass" }}
{{ if hugo.IsExtended }}
{{/* as we cannot concatenate styles of different types, we sass/scss to be transformed to css beforehand */}}
2024-09-17 18:05:21 +02:00
{{ $assets_to_concat = $assets_to_concat | append (. | css.Sass) }}
2022-04-21 17:48:54 +02:00
{{ else }}
{{ partial "func/warn" (printf "Processing of stylesheet %s of type %s has been skipped. You need Hugo Extended to process such files." .Name .MediaType.SubType) }}
{{ end }}
{{ else }}
{{ $assets_to_concat = $assets_to_concat | append . }}
{{ end }}
2021-06-15 15:58:27 +02:00
{{ 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 }}
2024-09-17 18:05:21 +02:00
{{ $style = $style | css.Sass $options | minify }}
2021-06-15 15:58:27 +02:00
{{/* We fingerprint in production for cache busting purposes */}}
{{ if eq (getenv "HUGO_ENV") "production" }}
2021-06-17 15:21:34 +02:00
{{ $style = $style | fingerprint }}
2021-06-15 15:58:27 +02:00
{{ end }}
{{/* We're ready to set returning variable with resulting resource */}}
{{ $main_style = $style }}
{{ end }}
2024-09-17 18:05:21 +02:00
{{ return $main_style }}