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

Github View/Edit links broken if defaultContentLanguageInSubdir = false #1420

Closed
Tracked by #1841
fekete-robert opened this issue Feb 15, 2023 · 11 comments · Fixed by #1744
Closed
Tracked by #1841

Github View/Edit links broken if defaultContentLanguageInSubdir = false #1420

fekete-robert opened this issue Feb 15, 2023 · 11 comments · Fixed by #1744
Milestone

Comments

@fekete-robert
Copy link
Collaborator

Hi, I am working on a site that uses Docsy 0.6.0 and might have hit a bug related to the following settings:

contentDir = "content"
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = false

The site is only available in English, so we don't use the content/en/ subdir. The site builds fine, but the github links "View/edit this page" are broken, because they do contain the "/en/" part.

I wanted to create a PR to omit the language from https://github.com/google/docsy/blob/main/layouts/partials/page-meta-links.html if "defaultContentLanguageInSubdir = false", but since this parameter is not under the [params] tag of the config file, it's not accessible from the partial (unless I'm missing something).

Does anyone have a solution or workaround to the problem? It's not a big issue, if there is no neat solution I'll just hide the links. An ugly workaround would be to duplicate the "defaultContentLanguageInSubdir = false" under [params] as well, but that's a really ugly hack.

The site is https://kube-logging.github.io/docs/ , its source is available at https://github.com/kube-logging/kube-logging.github.io/blob/master/config/_default/config.toml

Thanks!
Robert

@chalin
Copy link
Collaborator

chalin commented Feb 15, 2023

I have a similar setup for another project, and there are no issues with the GH page links. I'll investigate further and get back to you soon (probably later today).

@chalin
Copy link
Collaborator

chalin commented Feb 15, 2023

I haven't double checked yet, but off the top of my head what I recall is that you'll need to replace the contentDir by a mount point because we're not supposed to mix mount points (which are required when using Hugo modules) with the old *Dir config parameters.

From https://gohugo.io/hugo-modules/configuration/#module-config-mounts (emphasis mine):

When the mounts config was introduced in Hugo 0.56.0, we were careful to preserve the existing contentDir, staticDir, and similar configuration to make sure all existing sites just continued to work. But you should not have both: if you add a mounts section you should remove the old contentDir, staticDir, etc. settings.

Let me know if this helps.

@fekete-robert
Copy link
Collaborator Author

We don't use module mounts for this project, so it's not mixed. I've played around them a bit but didn't seem to solve the issue. I'll override the partial locally in our project to fix the links for now.

@LisaFC
Copy link
Collaborator

LisaFC commented Feb 21, 2023

It would be great if @chalin's workaround works because this is an old, old problem - as you discovered, you can't actually find defaultContentLanguageInSubdir via params in the partial, so there have been a variety of hacky solutions from various Docsy users, including overriding the entire partial.

@fekete-robert
Copy link
Collaborator Author

@LisaFC I couldn't get it work, but I have found another one that might be good enough to create an "official" workaround.

You can access the defaultContentLanguage = "en" and defaultContentLanguageInSubdir = false config parameters from the partials if you set them to cascade in the config file, like this:

[cascade]
defaultContentLanguage = "en"
defaultContentLanguageInSubdir = false

If this is set in the config file, then something like this works in the partial (I don't manage multilanguage sites so I don't know what the proper conditions would be):

{{ if and (eq ($.Param "defaultContentLanguage") (.Site.Language.Lang)) ($.Param "defaultContentLanguageInSubdir") -}}
    <!-- If defaultContentLanguageInSubdir is true and defaultContentLanguage is the current language -->
    {{ $gh_repo_path = printf "%s/content/%s/%s" $gh_branch ($.Site.Language.Lang) $pathFormatted -}}
    {{ else if and (eq ($.Param "defaultContentLanguage") (.Site.Language.Lang)) (not ($.Param "defaultContentLanguageInSubdir")) -}}
    <!-- If defaultContentLanguageInSubdir is false and defaultContentLanguage is the current language -->
    {{ $gh_repo_path = printf "%s/content/%s" $gh_branch $pathFormatted -}}

What do you think?

@chalin
Copy link
Collaborator

chalin commented Feb 22, 2023

Nice site you have there!

We don't use module mounts for this project, so it's not mixed

If you're using Docsy, since Docsy uses mounts, then your project is using mounts too 🤷‍♂️:

docsy/config.yaml

Lines 24 to 46 in 5597d43

mounts:
- source: assets
target: assets
- source: node_modules/bootstrap
target: assets/vendor/bootstrap
- source: node_modules/@fortawesome/fontawesome-free
target: assets/vendor/Font-Awesome
- source: i18n
target: i18n
- source: layouts
target: layouts
- source: static
target: static
- source: node_modules/@fortawesome/fontawesome-free/webfonts
target: static/webfonts
# Mounts for projects using Docsy as an NPM package. The source path prefix
# "../.." moves out of themes/docsy so that Docsy can find its dependencies.
- source: ../../node_modules/bootstrap
target: assets/vendor/bootstrap
- source: ../../node_modules/@fortawesome/fontawesome-free
target: assets/vendor/Font-Awesome
- source: ../../node_modules/@fortawesome/fontawesome-free/webfonts
target: static/webfonts

I've played around them a bit but didn't seem to solve the issue.

Ok. I'll take a look as soon as I can (quite busy atm). I'm starting to feel that this is a bug in the page-link rendering.

In the meantime, you should be able to use the path_base_for_github_subdir feature (with from and to fields) to get around the bug (to remove the /en from link paths).

@chalin
Copy link
Collaborator

chalin commented Feb 22, 2023

FYI, I just checked my other projects, and they all have their docs under content/en even though they don't have any other languages at the moment. So, that might also be a simple solution for you 🤷.

@bdalpe
Copy link

bdalpe commented Apr 11, 2023

I was able to use the workaround provided by @chalin. Sample toml config:

[params.path_base_for_github_subdir]
# change content/<lang>/... to content/...
from = "content/(.*?)/(.*?)"
to = "content/$2"

@chalin
Copy link
Collaborator

chalin commented Feb 7, 2024

@fekete-robert - can you confirm whether the following would have fixed the issue?

@fekete-robert
Copy link
Collaborator Author

Yes, it seems to work. Thanks!

@chalin
Copy link
Collaborator

chalin commented Feb 8, 2024

#1744 is the main fix in 0.9.0.
Thanks for confirming that it is working now for you.

Closed by #1744

@chalin chalin closed this as completed Feb 8, 2024
@chalin chalin modified the milestones: 24Q2, 24Q1 Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants