Skip to content

Commit d4abb3c

Browse files
committed
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
1 parent eb0f29e commit d4abb3c

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

exampleSite/content/basics/configuration/_index.en.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Note that some of these parameters are explained in details in other sections of
1212

1313
```toml
1414
[params]
15-
# Prefix URL to edit current page. Will display an "Edit this page" button on top right hand corner of every page.
15+
# Prefix URL to edit current page. Will display an "Edit this page" button on top right hand corner of every page.
1616
# Useful to give opportunity to people to create merge request for your doc.
1717
# See the config.toml file from this documentation site to have an example.
1818
editURL = ""
@@ -24,12 +24,12 @@ Note that some of these parameters are explained in details in other sections of
2424
showVisitedLinks = false
2525
# Disable search function. It will hide search bar
2626
disableSearch = false
27-
# Javascript and CSS cache are automatically busted when new version of site is generated.
27+
# Javascript and CSS cache are automatically busted when new version of site is generated.
2828
# Set this to true to disable this behavior (some proxies don't handle well this optimization)
2929
disableAssetsBusting = false
3030
# Set this to true to disable copy-to-clipboard button for inline code.
3131
disableInlineCopyToClipBoard = false
32-
# A title for shortcuts in menu is set by default. Set this to true to disable it.
32+
# A title for shortcuts in menu is set by default. Set this to true to disable it.
3333
disableShortcutsTitle = false
3434
# When using mulitlingual website, disable the switch language button.
3535
disableLanguageSwitchingButton = false
@@ -41,6 +41,8 @@ Note that some of these parameters are explained in details in other sections of
4141
ordersectionsby = "weight"
4242
# Change default color scheme with a variant one. Can be "red", "blue", "green".
4343
themeVariant = ""
44+
# Provide a list of custom css files to load relative from the `static/` folder in the site root.
45+
custom_css = ["css/foo.css", "css/bar.css"]
4446
```
4547

4648
## Activate search
@@ -54,5 +56,5 @@ home = [ "HTML", "RSS", "JSON"]
5456

5557
Learn theme uses the last improvement available in hugo version 20+ to generate a json index file ready to be consumed by lunr.js javascript search engine.
5658

57-
> Hugo generate lunrjs index.json at the root of public folder.
59+
> Hugo generate lunrjs index.json at the root of public folder.
5860
> When you build the site with `hugo server`, hugo generates it internally and of course it doesn’t show up in the filesystem

exampleSite/content/basics/configuration/_index.fr.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ Notez que certains de ces paramètres sont expliqués en détails dans d'autres
2424
showVisitedLinks = false
2525
# Désactive la fonction de recherche. Une valeur à true cache la barre de recherche.
2626
disableSearch = false
27-
# Par défaut, le cache Javascript et CSS est automatiquement vidé lorsqu'une nouvelle version du site est générée.
27+
# Par défaut, le cache Javascript et CSS est automatiquement vidé lorsqu'une nouvelle version du site est générée.
2828
# Utilisez ce paramètre lorsque vous voulez désactiver ce comportement (c'est parfois incompatible avec certains proxys)
2929
disableAssetsBusting = false
3030
# Utilisez ce paramètre pour désactiver le bouton copy-to-clipboard pour le code formatté sur une ligne.
3131
disableInlineCopyToClipBoard = false
32-
# Un titre est défini par défaut lorsque vous utilisez un raccourci dans le menu. Utilisez ce paramètre pour le cacher.
32+
# Un titre est défini par défaut lorsque vous utilisez un raccourci dans le menu. Utilisez ce paramètre pour le cacher.
3333
disableShortcutsTitle = false
3434
# Quand vous utilisez un site multi-langue, utilisez ce paramètre pour désactiver le bouton de changement de langue.
3535
disableLanguageSwitchingButton = false
3636
# Ordonne les sections dans menu par poids ("weight") ou titre ("title"). Défaut à "weight"
3737
ordersectionsby = "weight"
3838
# Utilisez ce paramètre pour modifier le schéma de couleur du site. Les valeurs par défaut sont "red", "blue", "green".
3939
themeVariant = ""
40+
# Fournissez une liste de fichiers css personnalisés à charger par rapport depuis le dossier `static/` à la racine du site.
41+
custom_css = ["css/foo.css", "css/bar.css"]
4042
```
4143

4244
## Activer la recherche {#activer-recherche}
@@ -50,5 +52,5 @@ home = [ "HTML", "RSS", "JSON"]
5052

5153
Le thème *Learn* utilise les dernières améliorations d'Hugo pour générer un fichier d'index JSON, prêt à être consommé par le moteur de recherche lunr.js.
5254

53-
> Hugo génère lunrjs index.json à la racine du dossier `public`.
55+
> Hugo génère lunrjs index.json à la racine du dossier `public`.
5456
> Quand vous générez le site avec `hugo server`, Hugo génère le fichier en mémoire, il n'est donc pas disponible sur le disque.

layouts/partials/header.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
<link href="{{"css/theme.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
2020
<link href="{{"css/hugo-theme.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
2121
{{with .Site.Params.themeVariant}}
22-
<link href="{{(printf "css/theme-%s.css" .) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
22+
<link href="{{(printf "css/theme-%s.css" .) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
2323
{{end}}
24+
{{ range .Site.Params.custom_css -}}
25+
<link href="{{(printf "%s" .) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
26+
{{- end }}
2427

2528
<script src="{{"js/jquery-3.3.1.min.js"| relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
2629

@@ -71,7 +74,7 @@
7174
{{if $showBreadcrumb}}
7275
{{ template "breadcrumb" dict "page" . "value" .Title }}
7376
{{ else }}
74-
{{ .Title }}
77+
{{ .Title }}
7578
{{ end }}
7679
</span>
7780
</div>
@@ -101,9 +104,8 @@ <h1>
101104
{{$parent := .page.Parent }}
102105
{{ if $parent }}
103106
{{ $value := (printf "<a href='%s'>%s</a> > %s" $parent.RelPermalink $parent.Title .value) }}
104-
{{ template "breadcrumb" dict "page" $parent "value" $value }}
107+
{{ template "breadcrumb" dict "page" $parent "value" $value }}
105108
{{else}}
106109
{{.value|safeHTML}}
107110
{{end}}
108111
{{end}}
109-

0 commit comments

Comments
 (0)