Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attachments: fix incorrect links for defaultContentLanguageInSubdir=true #425

Closed
ajeans opened this issue Dec 22, 2022 · 2 comments
Closed
Assignees
Labels
bug Something isn't working change Introduces changes with existing installations
Milestone

Comments

@ajeans
Copy link

ajeans commented Dec 22, 2022

Hello,

I configured my site with an exotic option :-)

  "defaultContentLanguageInSubdir": true,

All my URLs are prepended with a /en/ language code.

This usually works fine, but the attachments shortcode creates links that do not contain the language code and simply reply with "Page Not Found'.
One such generated link is http://localhost:1313/sdks/backend/java/security.en.files/application.yml, whereas the attached file is available at http://localhost:1313/en/sdks/backend/java/security.en.files/application.yml.

I found out that I could fix this for my use case with the following change. Would it make sense to have this change in the theme?

--- themes/hugo-theme-relearn/layouts/partials/shortcodes/attachments.html	2022-12-22 19:34:22.252790204 +0100
+++ themes/quicksign/layouts/partials/shortcodes/attachments.html	2022-12-22 19:32:16.047510461 +0100
@@ -42,7 +42,7 @@
         {{- $unit = "Megabyte-symbol" }}
       {{- end }}
       {{- $unitsymbol := $unit | T }}
-    <li><a href="{{ (printf "%s%s/%s" $fileLink $filesName .Name) | relURL }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li>
+    <li><a href="{{ (printf "%s%s/%s" $fileLink $filesName .Name) | relLangURL }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li>
     {{- end }}
   {{- end }}
   </ul>

Best,
Arnaud

@McShelby McShelby changed the title attachments: links are incorrect when "defaultContentLanguageInSubdir": true attachments: fix incorrect links for defaultContentLanguageInSubdir=true Dec 23, 2022
@McShelby McShelby self-assigned this Dec 23, 2022
@McShelby McShelby added the bug Something isn't working label Dec 23, 2022
@McShelby McShelby added this to the 5.9.0 milestone Dec 23, 2022
@McShelby McShelby added the change Introduces changes with existing installations label Dec 23, 2022
@McShelby
Copy link
Owner

The non-standard conformant way the attachments shortcode was implemented (see #22 for plans to fix this) leads to some quirks.

Eg. Hugo stores the attachments only for leaf bundles in their corresponding language subdirectory (plus also storing them in the subdirectory of the default language). All other page types store the attachments only in the subdirectory of the default language.

So our generated links always have to point into the subdirectory of the default language.

@ajeans
Copy link
Author

ajeans commented Jan 5, 2023

Hello @McShelby

Thanks for the quick fix, I can confirm that after moving to version 5.92, I can get rid of my hack and it all works fine.

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working change Introduces changes with existing installations
Projects
None yet
Development

No branches or pull requests

2 participants