=>
Both absURL and relURL consider the configured value of baseURL in your site’s config file.
Here’s a test scenario (using content/index.md
and layouts/_default/single.html
)
<pre>
.Site.BaseURL : {{ .Site.BaseURL }}
<br/>
{{- $myRefRel := `vendor/cool.css` }}
$myRefRel : {{ $myRefRel }}
relURL $myRefRel : {{ relURL $myRefRel }}
absURL $myRefRel : {{ absURL $myRefRel }}
<br/>
{{- $myRefAbs := `/vendor/cool.css` }}
$myRefAbs : {{ $myRefAbs }}
relURL $myRefAbs : {{ relURL $myRefAbs }}
absURL $myRefAbs : {{ absURL $myRefAbs }}
hugo -d ${DEST}/ -b "http://example.com/theme/w3css/"
gives me:
.Site.BaseURL : http://example.com/theme/w3css/
$myRefRel : vendor/cool.css
relURL $myRefRel : /theme/w3css/vendor/cool.css
absURL $myRefRel : http://example.com/theme/w3css/vendor/cool.css
$myRefAbs : /vendor/cool.css
relURL $myRefAbs : /theme/w3css/vendor/cool.css
absURL $myRefAbs : http://example.com/vendor/cool.css
absURL "/vendor/cool.css"
produces http://example.com/vendor/cool.css
I would expect:
http://example.com/theme/w3css/vendor/cool.css
since the BaseURL defines /theme/w3css/ as “subdir”.
Things change if the deprecated --canonifyURLs
is used (which is used to build the exampleSites for https://themes.gohugo.io/)
hugo -d ${DEST}/canonify --canonifyURLs -b "http://example.com/theme/w3css/"
we get:
.Site.BaseURL : http://example.com/theme/w3css/
$myRefRel : vendor/cool.css
relURL $myRefRel : /vendor/cool.css
absURL $myRefRel : http://example.com/theme/w3css/vendor/cool.css
$myRefAbs : /vendor/cool.css
relURL $myRefAbs : /vendor/cool.css
absURL $myRefAbs : http://example.com/vendor/cool.css
If we take the configured BaseURL for granted (so the site will live in a subdir (/theme/w3css
) on the host) the only valid test is
absURL $myRefRel
all others do not include the defined subdir from the BaseURL.
Maybe I’ve a total misunderstanding here?