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

Fix page-meta for single language sites #1486

Closed

Conversation

lyind
Copy link

@lyind lyind commented Mar 16, 2023

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.

@LisaFC
Copy link
Collaborator

LisaFC commented Sep 14, 2023

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

@LisaFC
Copy link
Collaborator

LisaFC commented Sep 15, 2023

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...

@lyind
Copy link
Author

lyind commented Sep 19, 2023

I quickly tested relLangURL in a .Site.IsMultiLingual == false environment: it works.

So one could indeed refactor the code a bit.

@lyind
Copy link
Author

lyind commented Sep 19, 2023

@LisaFC I took a shot at the refactoring, could you review, please?

@LisaFC
Copy link
Collaborator

LisaFC commented Sep 19, 2023

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.

@LisaFC
Copy link
Collaborator

LisaFC commented Sep 21, 2023

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 ) -}}
Copy link
Collaborator

@LisaFC LisaFC Sep 21, 2023

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!

@LisaFC LisaFC requested a review from emckean September 21, 2023 17:33
@LisaFC
Copy link
Collaborator

LisaFC commented Sep 21, 2023

Here's my working version for comparison:
https://github.com/LisaFC/multilang/blob/main/layouts/partials/page-meta-links.html

@lyind
Copy link
Author

lyind commented Sep 25, 2023

Which Hugo versions are we supposed to support (Hugo minimum version)?

Updating now, due to:
grafik

@LisaFC
Copy link
Collaborator

LisaFC commented Sep 25, 2023

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)

@LisaFC
Copy link
Collaborator

LisaFC commented Oct 4, 2023

Did that work?

@LisaFC
Copy link
Collaborator

LisaFC commented Oct 20, 2023

Bump! I'd like to get this in as it will fix one of our very very oldest unresolved issues.

@lyind
Copy link
Author

lyind commented Oct 20, 2023

@LisaFC Will try it later.

@lyind
Copy link
Author

lyind commented Nov 3, 2023

@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 ❤️👍

@lyind
Copy link
Author

lyind commented Nov 3, 2023

Should we close this PR in favor of your change?

@LisaFC
Copy link
Collaborator

LisaFC commented Nov 3, 2023

OK! I'll add you to my PR and you can close yours then.

@lyind lyind closed this Nov 3, 2023
@chalin chalin added this to the 23Q4 milestone Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants