Hugo: Resource transformation URLs vs. canonifyURLs

Created on 25 Jul 2018  路  7Comments  路  Source: gohugoio/hugo

Originally posted on Discourse; another user suggested this might be a bug.

I have canonifyurls: true in my site config, but it doesn鈥檛 seem to be affecting the output of {{ $style.Permalink }}; not sure if that's pertinent.

My CSS partial

{{ $options := (dict "targetPath" "/css/main.css" "outputStyle" "compressed" "enableSourceMap" true) }}
{{ $style := resources.Get "sass/styles.scss" | toCSS $options | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}">

Environments

My two environments have different BaseURLs:

Output

The link to the generated CSS is broken in both environments; they're missing a subdirectory.

<link rel="stylesheet" href="https://intranet.fws.gov/region4/css/main.min.80b1bb2f29d8811c1f83e5164d0bd2314717d173a14186aa208c5abe546461ca.css">

<link rel="stylesheet" href="https://www.fws.gov/css/main.min.80b1bb2f29d8811c1f83e5164d0bd2314717d173a14186aa208c5abe546461ca.css">

Am I doing something wrong with my targetPath? I tried dropping the leading / without any luck.

Bug Stale

Most helpful comment

I have another issue talking about removing canonifyurls -- but I suspect I cannot do that until I get some kind of "URL rewriter" support in MD. But that setting must be the most expensive flag in the history of computing.

All 7 comments

I have canonifyurls: true in my site config, but it doesn鈥檛 seem to be affecting the output of {{ $style.Permalink }}; not sure if that's pertinent.

They're not connected, but what happens if you turn canonifyurls off?

This pipe thing with subfolders in BaseURL certainly works, most of my test sites have that setup.

Removing canonifyurls seems to have done the trick, actually.

ouput:

<link rel="stylesheet" href="https://www.fws.gov/southeast/css/main.min.80b1bb2f29d8811c1f83e5164d0bd2314717d173a14186aa208c5abe546461ca.css">

With canonifyurls turned on, this is my current work-around:

{{ $baseurl := printf "%s" .Site.BaseURL}}
{{ if in $baseurl "fws.gov/southeast" }}
  {{ $.Scratch.Set "path" "/southeast/css/main.css" }}
{{ else }}
  {{ $.Scratch.Set "path" "/region4/demo/css/main.css" }}
{{ end }}
{{ $options := (dict "targetPath" ($.Scratch.Get "path") "outputStyle" "compressed" "enableSourceMap" true) }}
{{ $style := resources.Get "sass/styles.scss" | toCSS $options | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}">

I have another issue talking about removing canonifyurls -- but I suspect I cannot do that until I get some kind of "URL rewriter" support in MD. But that setting must be the most expensive flag in the history of computing.

hugoThemes is also using canonifyURLs = true currently, so the same bug occurs for themes on https://themes.gohugo.io/.

@onedrawingperday The buildThemeSite.sh calls _script/generateThemeSite.sh which sets HUGO_CANONIFYURLS=true. absURL does not fix this resource permalink issue....

It appears that this might be a duplicate of #5226. Suppose #5226 is fixed, then this issue might be closed as well.

However, this issues is talking about transformed resource, while #5226 seems to be talking about general resources. So I am not exactly sure if these two issues are duplicates of each other.

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

Was this page helpful?
0 / 5 - 0 ratings