-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix page-meta for single language sites #1486
Conversation
Thanks for this, and sorry for the belated review! I am going to look at this properly but from back in #138 we found checking IsMultiLingual didn't work for all sites - that may have changed since then, of course! Going to also try this new tip from the Hugo forum: https://discourse.gohugo.io/t/check-if-default-language-content-is-in-a-language-subdir/21425/6 |
So this seems to work even if there aren't any language subdirs (which the older version of IsMultiLang didn't seem to work for), hoorah! Do you want me to try the new template functions and see if we can make it even simpler? I think we can get rid of some of the conditionals... |
I quickly tested relLangURL in a So one could indeed refactor the code a bit. |
@LisaFC I took a shot at the refactoring, could you review, please? |
Just taking a look now! At first glance in a multilang site it seems to be working (give or take an extra slash) for everything except the default language, for some reason. Let me see if I can fix it. |
Right, got it working! Few review comments/edits incoming. |
{{ $gh_repo_path = printf "%s/content/%s/%s" $gh_branch ($.Site.Language.Lang) $pathFormatted -}} | ||
{{ else if $gh_subdir -}} | ||
{{ $gh_repo_path = printf "%s/%s/content/%s" $gh_branch $gh_subdir $pathFormatted -}} | ||
{{ $gh_repo_path := printf "%s/content/%s" $gh_branch ( relLangURL $pathFormatted ) -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So (for some reason the GH web UI won't let me comment on any lines outside your change) you need to do the following:
Change line 2 above from
{{ $pathFormatted := replace .File.Path "\\" "/" -}}
to
{{ $pathFormatted := strings.TrimPrefix hugo.WorkingDir $.File.Filename -}}
Then change these lines to:
{{ $gh_repo_path := printf "%s%s" $gh_branch $pathFormatted -}}
{{ if $gh_subdir -}}
{{ $gh_repo_path = printf "%s/%s%s" $gh_branch $gh_subdir $pathFormatted -}}
That works for both sites with language subdirectories and ones without!
Here's my working version for comparison: |
We specify a minimum of 0.110.0, but I think we may have to bump it to 0.112.0 for our next release if we use this as that's when that WorkingDir function was introduced. (Hugo is currently on 0.119.0) |
Did that work? |
Bump! I'd like to get this in as it will fix one of our very very oldest unresolved issues. |
@LisaFC Will try it later. |
@LisaFC Tested your variant at https://github.com/LisaFC/multilang/blob/main/layouts/partials/page-meta-links.html with a single-language/no language site: OK ❤️👍 |
Should we close this PR in favor of your change? |
OK! I'll add you to my PR and you can close yours then. |
Fixes #981
Fixes #138
Summary
The "edit", "view source" and similar links in the page-meta area (on the right) are broken for single-language Hugo sites (HTTP 404).
Those sites may store their source documents without language specific path segment depending on the
.Site.IsMultiLingual
property.This PR changes the page-meta partial template to take that property into account.