hugo-theme-learn icon indicating copy to clipboard operation
hugo-theme-learn copied to clipboard

Attachments URL wrong if site is deployed under subpath

Open Nightshadelink opened this issue 2 years ago • 0 comments

Problem:

Whenever the web pages are not deployed in the root but under a subpath it shows that in the attachement.html a leading slash is used too much in the URL. So the full BasePath is not used relatively, but absolute "$fileDir", "$filesName" and ".Name".

Example:

  • BaseURL = "https://foo.bar/3000/"
  • Example-Attachement = ".../foo.en.files/bar.png"
  • Expected URL = "https://foo.bar/3000/foo.en.files/bar.png"
  • Actual URL = "https://foo.bar/foo.en.files/bar.png"

Presumed cause:

In .../layouts/shortcodes/attachments.html

<a href="{{ (printf "%s%s/%s" $fileDir $filesName .Name) | relLangURL }}">{{.Name}}</a>

$fileDir probably (didn't test) carries a leading slash hence relLangURL does not utilize the BasePath fully.

Proposed modification:

Remove leading slash. This works for now, but presumably you have a better solution for fixing.

<a href="{{ slicestr (printf "%s%s/%s" $fileDir $filesName .Name) 1 | relLangURL }}">{{.Name}}</a>

System-Info:

vanilla deployed on github-pages

Nightshadelink avatar Jan 10 '23 19:01 Nightshadelink