Hello,
I created a new site and theme with Hugo using the following commands:
$ hugo new site website
$ cd website
$ hugo new theme customtheme
In the customtheme/layouts/partials directory, there is a snippet that loads a CSS file. I assume this is the correct way to do it, as it comes by default with the new theme:
{{- with resources.Get "css/main.css" }}
{{- if eq hugo.Environment "development" }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{- else }}
{{- with . | minify | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{- end }}
{{- end }}
{{- end }}
In my case, I have multiple CSS files, and I modified the code as follows:
{{- with resources.Match "css/*.css" | resources.Concat "styles.css" }}
{{- if eq hugo.Environment "development" }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{- else }}
{{- with . | minify | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{- end }}
{{- end }}
{{- end }}
The only difference is in the first line. My version also seems to work, but I’m unsure if using with in conjunction with resource.Match is acceptable. Also, in order to avoid creating another with condition on line 2, I used a pipe on the first line. Is this approach okay?