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

enforce language url subsitution on path boundary #254

Merged
merged 1 commit into from
Feb 22, 2021

Conversation

oasys
Copy link
Contributor

@oasys oasys commented Feb 19, 2021

Without this, the section name gets mangled when the language was a
substring of the section. For example, under 'en', a section named
"fragment" changes to "fragmt".

Copy link

@Shaddee060314 Shaddee060314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layouts/partials/templates/schema_json.html

@adityatelange
Copy link
Owner

adityatelange commented Feb 20, 2021

@oasys Nice Catch !

What if we use [LIMIT] from https://gohugo.io/functions/replace/ ? Does it have same effect

like

-{{- $lang_url := replace $url ( printf "%s/" .Lang) "/" }}
+{{- $lang_url := replace $url ( printf "%s/" .Lang) "/" 1 }}

@oasys
Copy link
Contributor Author

oasys commented Feb 20, 2021

I will test later, but I suspect that will only fix when running a multi language config. A single language config will probably still have problems (as in my example, there will be no en/ to strip. )

@adityatelange
Copy link
Owner

I will test later, but I suspect that will only fix when running a multi language config. A single language config will probably still have problems (as in my example, there will be no en/ to strip. )

True

@oasys oasys force-pushed the fix_section_mangling branch from a52d740 to a52ae2f Compare February 20, 2021 15:23
@oasys
Copy link
Contributor Author

oasys commented Feb 20, 2021

How about this? I assume multilingual config always has the lang prefix at the beginning of the URI. Using replaceRE anchors the lang match to the beginning (^) and the (/). I think this should work for most cases -- the only one I can think of that won't work is having a "section" name that is the same as a configured language.

{{- $lang_url := replaceRE ( printf "^%s/" .Lang) "" $url 1 }}

@oasys
Copy link
Contributor Author

oasys commented Feb 20, 2021

This will do the same, but might be more readable:

 {{- $lang_url := strings.TrimPrefix ( printf "%s/" .Lang) $url }}

If you prefer this change instead of the replaceRE one, let me know and I'll update the PR.

@adityatelange
Copy link
Owner

This will do the same, but might be more readable:

 {{- $lang_url := strings.TrimPrefix ( printf "%s/" .Lang) $url }}

If you prefer this change instead of the replaceRE one, let me know and I'll update the PR.

I agree, sure we can do this way

  Without this, the section name gets mangled when the language was a
  substring of the section.  For example, under 'en', a section named
  "fragment" changes to "fragmt".
@oasys oasys force-pushed the fix_section_mangling branch from a52ae2f to 8a1270e Compare February 21, 2021 13:02
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@oasys
Copy link
Contributor Author

oasys commented Feb 21, 2021

I agree, sure we can do this way

Done. Thanks!

@adityatelange adityatelange merged commit 5e05ed6 into adityatelange:master Feb 22, 2021
kylethedeveloper pushed a commit to kylethedeveloper/hugo-PaperMod that referenced this pull request Feb 21, 2023
…ityatelange#254)

* Without this, the section name gets mangled when the language was a
  sub-string of the section.  For example, under 'en', a section named
  "fragment" changes to "fragmt".
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 this pull request may close these issues.

3 participants