Allow custom css files to be loaded by configuration

Previously adding custom css files would require the end user to copy
the header or footer partial into their overrides. They would then
need to maintain that partial into the future.

This config allows a user to provide a list of custom css files to load
into the theme, meaning they do not need to clone the partial.

```
[params]
  custom_css = ["css/foo.css", "css/bar.css"]
```

Inspiration taken from https://discourse.gohugo.io/t/how-to-override-css-classes-with-hugo/3033/4
This commit is contained in:
Matthew Taylor 2020-03-09 15:50:24 +00:00 committed by Matthew Taylor
parent eb0f29ee44
commit d4abb3c9a1
3 changed files with 17 additions and 11 deletions

View file

@ -41,6 +41,8 @@ Note that some of these parameters are explained in details in other sections of
ordersectionsby = "weight" ordersectionsby = "weight"
# Change default color scheme with a variant one. Can be "red", "blue", "green". # Change default color scheme with a variant one. Can be "red", "blue", "green".
themeVariant = "" themeVariant = ""
# Provide a list of custom css files to load relative from the `static/` folder in the site root.
custom_css = ["css/foo.css", "css/bar.css"]
``` ```
## Activate search ## Activate search

View file

@ -37,6 +37,8 @@ Notez que certains de ces paramètres sont expliqués en détails dans d'autres
ordersectionsby = "weight" ordersectionsby = "weight"
# Utilisez ce paramètre pour modifier le schéma de couleur du site. Les valeurs par défaut sont "red", "blue", "green". # Utilisez ce paramètre pour modifier le schéma de couleur du site. Les valeurs par défaut sont "red", "blue", "green".
themeVariant = "" themeVariant = ""
# Fournissez une liste de fichiers css personnalisés à charger par rapport depuis le dossier `static/` à la racine du site.
custom_css = ["css/foo.css", "css/bar.css"]
``` ```
## Activer la recherche {#activer-recherche} ## Activer la recherche {#activer-recherche}

View file

@ -21,6 +21,9 @@
{{with .Site.Params.themeVariant}} {{with .Site.Params.themeVariant}}
<link href="{{(printf "css/theme-%s.css" .) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"> <link href="{{(printf "css/theme-%s.css" .) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
{{end}} {{end}}
{{ range .Site.Params.custom_css -}}
<link href="{{(printf "%s" .) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
{{- end }}
<script src="{{"js/jquery-3.3.1.min.js"| relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script> <script src="{{"js/jquery-3.3.1.min.js"| relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
@ -106,4 +109,3 @@
{{.value|safeHTML}} {{.value|safeHTML}}
{{end}} {{end}}
{{end}} {{end}}