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

Override section url #3354

Closed
LeeU1911 opened this issue Apr 16, 2017 · 25 comments
Closed

Override section url #3354

LeeU1911 opened this issue Apr 16, 2017 · 25 comments

Comments

@LeeU1911
Copy link

Hi all,

I'm building a multilingual site and would like to have 2 different urls for my section list page.

The content is as follows:

content
|___product
|___ _index.md
|___ product-1.md
|___ product-1.fr.md

Currently, by default, hugo generates /product and /product/product-1 which is expected.

For multilingual purpose, I want to achieve:
English:

/product
/product/product-1

French:

/produit
/produit/produit-1

I can achieve /produit/produit-1 by permalinks configuration in config.toml but I don't know how to generate /produit one which will still use my section template page under theme/layouts/section/product.html (same for both language).

Any idea would be very appreciated.

Thanks a lot.

P/S: I tried with putting url and slug in _index.md and that seems not working although the content of the file is picked up correctly in the template.

This is issue is referenced by this discussion.

@stale
Copy link

stale bot commented Dec 6, 2017

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 6, 2017
@ngsctt
Copy link

ngsctt commented Dec 22, 2017

Just thought I'd chime in and say that this is my single biggest issue using Hugo at the moment, and I think probably the only major roadblock to really powerful multilingual sites.

In my case, I have for example a notes section. In English, I want that section to have the title "Notes", the list page to appear at http://example.com/notes/, and the pages to be at eg. http://example.com/notes/on-making-a-website.html.

But, in Japanese, I need that section to have the title 意見 (iken), the list page to appear at http://example.com/ja/iken/ and the pages to be at eg. http://example.com/ja/iken/saito-wo-tukuru.html.

At the moment, I can get the subpages to have the correct output path (http://example.com/ja/iken/saito-wo-tukuru.html), by using

Languages:
  ja:
      permalinks:
        notes: /iken/:slug

in my config.yaml, but the list page permalink will still come out at http://example.com/ja/notes/.

Even using rewrite rules on Netlify, and throwing some hack-y code into templates and shortlinks using a Param listing these problem sections (ie. index .Site.Params.slugPatches (.Get 0)), I still can't get the permalinks in .Translations to match up.

It means I can't have a URL that makes sense in the target language, and there's no possible workaround that I can find.

On the other hand, if the section's output folder was named after the slug value in the section's frontmatter, just like for single pages, the system would work perfectly (and make a lot of immediate sense). Sections could be correctly translated, and the pages in the sections would have a correctly translated path.

Then, in /content/notes/_index.ja.md I could just put

---
title: 意見
slug: iken
---

instead of all those workarounds/.Site.Params/redirect rules.

@stale stale bot removed the Stale label Dec 22, 2017
@biodranik
Copy link
Contributor

I have the same issue now, trying to switch to hugo for an existing site. The concept of _index.[lang].md files for sections is great, and it's one of the biggest issues.

@lucendio
Copy link

Hi,

I would like to outline the need of this functionality a bit more. Starting with the following three threads in the forum, which are all (more or less) related to this matter. Some of them even explain how to work around this, which, in some case, might actually be applicable.

Multi language support and the need for translating parts of an url is, IMHO, one of the most reasonable use cases for overwriting section names with it's language-specific counterpart.
Yes, it is possible to accomplish that with the permalink configurations in hugo's config. file - as described in the forums. Though, it only works for the first level in the folder structure. Deeper sub-sections can't be overwritten with this approach.

Ideally, the slug parameter in the front matter for /content/section-name/subsectionA/_index.en.md would overwrite subsectionA in the output. I could also think of some build step, where section names get checked with the i18n function against existing translations (e.g. in hugolib/permalinks.go). An existing translation would then replace the original section name.
If anybody has other ideas, feel free to share them.

Hopefully, with this I was able to emphasize a bit more on the realness of this feature request.
@bep, I would love to see you starting to take this issue a bit more serious, even though the feature might not be important for you personally.

@regisphilibert
Copy link
Member

regisphilibert commented Jan 23, 2018

The guy is releasing patches twice a week give him a break. I'm just reacting to this last paragraph.

Now .34 resolves the section slug issue. You can now add one to your section _index.md.

Yet it still doesn't solve your problem ?

My posts are stored in content/post and yet, my section slug is /blog thanks to .34
https://regisphilibert.com/blog/

@lucendio
Copy link

Without a doubt, all contributors do an amazing work and I am very thankful for all their effort. I was just citing his own words, which, at least to me, seems to show a bit of an inappropriate attitude in that context.

Regarding .34, I couldn't find any hint of this issue being solved in the release. I already installed the latest release and noticed no difference in the behaviour already described.

@ValidRobot
Copy link

ValidRobot commented Feb 1, 2018

Currently, I am also thinking about creating a commercial multi-language website with Hugo and I really like the multi-language support Hugo offers, it makes it really easy and you can see the time and hard work which were invested by contributors, but I have one deal breaker and that is that I didn't find any way to override the section URL. Without the support of overridable sections is the multi-language support good but not usable in anything but private blogs.

So I would really appreciate the enhancement else the only other way to create a commercial multi-language website would to create for each language there own Hugo project which makes it viable but that's it.

The guy is releasing patches twice a week give him a break. I'm just reacting to this last paragraph.

Now .34 resolves the section slug issue. You can now add one to your section _index.md.

Yet it still doesn't solve your problem ?

My posts are stored in content/post and yet, my section slug is /blog thanks to .34
https://regisphilibert.com/blog/

@regisphilibert

Can you maybe link or post a example code, would appreciate it. Because it has no effect in my multi-language setup.

@jonjbar
Copy link

jonjbar commented Mar 20, 2018

Hi,
This is currently the only issue we've identified preventing us from moving from Drupal to Hugo. Hopefully, there will be a way to achieve that in a future update.

@budparr
Copy link

budparr commented Mar 20, 2018

@jonjbar Does the solution @regisphilibert posted here solve your issue? #3354 (comment)

@lucendio
Copy link

@budparr I already mentioned above, and happily confirm again that #3354 (comment) does not work for me (v0.36.1). Maybe @regisphilibert has some permalinks applied in the global config file, but again, that approach wont work for nested sections and is merly a workaround.

@regisphilibert
Copy link
Member

@lucendio I understand your problem and yes my comment can help you. I was able to achieve multilingual subsection url overriding using 0.37.
You do have to mention the parent section new url in the subsection url parameter.

If you point me to a repo of some sort I'd try and take a look.

Cheers.

@lucendio
Copy link

@regisphilibert Interesting. Would you mind posting a simple example or point me to the section in the docs showing how to achieve this?
Any hint or enlightenment is much apprechiated. (the repo of concern can be found here)

thx, L

@regisphilibert
Copy link
Member

regisphilibert commented Mar 20, 2018

Ok give it a look here: https://github.com/regisphilibert/rp_hugo/tree/greeting-test/

You're not going to be able to fork it as is because the theme is a private submodule but you can still download it and use any theme of your chosing.

Then, look at config.toml where permalinks are set.
And then inside content/post, you'll find the greeting sub section. Give it a look.

I didn't have time to check templates for it, but if you compile Hugo, you'll see the directory are generated the way you want.

@jonjbar
Copy link

jonjbar commented Mar 20, 2018

@regisphilibert Thank you for the sample. Still learning Hugo here but I believe that this is working due to the fact that you have only one section with the following in your config.toml file:

[languages.fr.permalinks] post = "blogue/:year/:month/:slug/"

Without that, and if you have multiple sections (e.g. have "blog" section and "products" section...) you can't use the _index.md trick to override the URL of sub-pages.
In other words, you can't have multiple translatable sections:

/blog/ -> /blogue
/product -> /produit
...

Or perhaps I am missing something ?

@regisphilibert
Copy link
Member

Are you saying that (from config.toml)

[languages.fr.permalinks]
  post = "blogue/:year/:month/:title/"
  product = "produit/:title"

is not working ?

@lucendio
Copy link

@regisphilibert thank you for the example. But sadly this still does not work for sub-sections or scales for multiple sections (as @jonjbar pointed out). The user experience I'd like to see, or I think this thread here is looking for, is described here. In short, it's something around the lines of, the ability to overwrite slug (meaning the part of the url for its specific path level) in its corresponding _index.[$Lang].md front matter.

@stale
Copy link

stale bot commented Jul 18, 2018

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Jul 18, 2018
@stale stale bot closed this as completed Aug 17, 2018
@InsOpDe
Copy link

InsOpDe commented Jan 12, 2019

any news on this?

@igr
Copy link

igr commented Jan 24, 2019

This. Feature. Would. Be. Really. Awesome.

@marcanuy
Copy link

I came up with a solution supporting nested sections assigning custom slugs
for each language, no matter their depth in dir structure. It requires:

  • "Translation by content directory"
  • "Frontmatter's translationKey"
  1. Set languages in config and define a directory for each one of them:
[languages]
  [languages.en]
    contentDir = "content/en"
    languageName = "English"
    weight = 10
  [languages.es]
    title = "Sitio ..."
    contentDir = "content/es"
    languageName = "Español"
    weight = 20
  1. Set translationKey for _index.md and pages and their slug as
    directory name or filename; I use the slug of the
    section/page being translated as the translation key, for example for
    /content/en/foo/_index.md:

    • EN: /content/en/foo/

      ----
      translationKey = "foo"
      ----
      
    • ES: /content/es/foo-slug-in-spanish/

      ----
      translationKey = "foo"
      ----
      

Same process for pages.

Then each level of the hierarchy will have its corresponding page in
the other language, and subdirectories will also be translated.

Applied this approach in this theme, for example for:

@biodranik
Copy link
Contributor

@bep Are there plans about an easier solution than just published workaround by @marcanuy ? This feature is really important for many multilingual sites.

@biodranik
Copy link
Contributor

@bep it was closed from another issue, but I don't see any reference to it from #5681
Was it fixed?

@andekande
Copy link

It's not been implemented. The PR enables to localize Pages via FrontMatter property 'url'.
What's asked for here is to enable that for sections the same way.
And have it picked up when accessing permalinks as well.

@fthorns
Copy link

fthorns commented Nov 3, 2021

Sad to see this issue is closed, this feature would awesome to have! I hope I haven't missed anything, if I did, please let me know :)

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests