Taking a look at following code from this post:
{{ $inServerMode := .Site.IsServer }}
{{ $sass := resources.Get "scss/main.scss" | resources.ExecuteAsTemplate "style.main.scss" . }}
{{ $sassIncludes := (slice "assets/dependencies/" "assets/scss/" "assets/scss/vendors/") }}
{{ $cssTarget := "css/styles.css" }}
{{ $cssOpts := cond ($inServerMode) (dict "targetPath" $cssTarget "enableSourceMap" true "includePaths" $sassIncludes) (dict "targetPath" $cssTarget "includePaths" $sassIncludes "outputStyle" "compressed") }}
Of course ‘scss/main.scss’ is executed as template and can take front-matter variables from page bundle, via dot, but where does ‘style.main.scss’ live? What’s in it, and how does it relate to ‘scss/main.scss’?
The name of ‘style.main.scss’ is arbitrary? The output file for main.scss after processing as template?
Anyway, pardon that question - Hugo does have anyway a curve.
The goal here is to rewrite css-grid-template declarations at the page level by dropping a page.scss into the leaf bundle with associated front-matter variables declared in the post, hence the topic title.
This is the set-up:
{{ $sassMain := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "sassMain.scss" . }}
{{$sassPage := resources.Get "sass/page.scss"}}
{{ with (.Resources.GetMatch "page.scss") }}
{{$sassPage = ""}}
{{ $sassPage = .Content | resources.ExecuteAsTemplate "sassPage.scss" . }}
{{ end }}
{{ $sassIncludes := (slice "assets/sass-includes/" "node_modules") }}
{{- $sassOpts := dict "targetPath" "css/main.css" "includePaths" $sassIncludes -}}
{{- if (in (slice (getenv "HUGO_ENV") hugo.Environment) "production") -}}
{{- $sassOpts = merge $sassOpts (dict "outputStyle" "compressed") -}}
{{- end -}}
{{- $styles := resources.Get "styles.css" -}}
{{- $syntax := resources.Get "syntax.css" -}}
{{ $sassBundle := slice $sassMain $sassPage | resources.Concat "sass/sassBundle.scss" | resources.ExecuteAsTemplate "sass/sassBundleParsed.scss" . | toCSS $sassOpts }}
{{ $mainBundle := slice $styles $syntax $sassBundle | resources.Concat "css/bundle.css" }}
{{- if (eq (getenv "HUGO_ENV") "production") -}}
{{- $mainBundle = $mainBundle | postCSS | minify | fingerprint "Sha512" -}}
{{- end -}}
<link rel="stylesheet" href="{{- $mainBundle.RelPermalink -}}" integrity="{{- $mainBundle.Data.Integrity -}}"/>
There’s a file with a meaningless sass declaration assigned to $sassPage, to avoid an empty slice error when there are no page.scss files in bundles.
Hugo runs with no page.scss files, but gives error when a test page.scss is included in a bundle.
This looks like page level resources don’t like sass format, as the error is more or less no strings allowed in ExecuteAsTemplate.
Here is the front-matter test variable assignment so far:
[[style.footer]]
grid-column = "1/span 2"
and here the insertion of the hugo variable into page.scss
$$ft-75-gc = {{ .Param.style.footer.grid-column}};
Neither ‘=’ nor “:” will work in page.scss.
Is this procedure actually possible (inserting front-matter variables into sass files at the page level), or can hugo variables only get into sass files through the assets directory (the way Regis does it here )?
If it is possible, in what order does .Concat concatenate files? Can sass variable inserted at page level override sass variable inserted at global level through concatenation?
Looking for a quick way to restructure page grids from front-matter