[Solved] .BaseURL setting vs commandline adding an extra /

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


  #hero {
    background-image: url("https://dkebler.github.io/landingpage-guide/images/hero.jpg");

@dkebler Looks like a fix to this is coming with v20! :smile:


Oh, and in the interim, have you checked out relURL in this use case? Might be a good way to avoid the background-image issue you’re having if you need a super quick fix?

Although github and aws don’t have an issue with the double // firebase I just discovered does and won’t load the image. So yea this should be fixed. Just now seeing the bug fix above. I’ll see v.20 is now out. I’ll try it and report back

Yup with .20.1 loaded the issue/bug is no more. I’m tagging this solved. Thx!

1 Like