I had an issue with a background image url in a static css file. It doesn’t get prepended by baseURL
Not surprisingly the static css file is not processed by hugo so no way to turn a relative reference into absolute.
So… I do have a custom style partial where I can fix this but it seems when the baseURL is set from the command line there is a following / added to the url. That’s not a deal breaker cause the image still loads with //.
When I use baseURL from the config file it doesn’t.
Since it’s not consistent I can’t write my printf correctly (with or without a leading / on images) and without will cause url syntax error when using the config setting.
{{ with $.Site.Params.imagespath }}
{{ $.Scratch.Set "path" ( . ) }}
{{ else }}
{{ $.Scratch.Set "path" ( printf "%s/images/" ( $.Site.BaseURL | default "" ) ) }}
{{ end }}
#hero {
background-image: url("{{ $.Scratch.Get "path" }}{{ .img | default "hero.jpg" }}");
}
rendered from command line
hugo -b https://dkebler.github.io/landingpage-guide -d docs
#hero {
background-image: url("https://dkebler.github.io/landingpage-guide//images/hero.jpg");
}
rendered from
baseURL=https://dkebler.github.io/landingpage-guide
#hero {
background-image: url("https://dkebler.github.io/landingpage-guide/images/hero.jpg");
}