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.
I don’t think what you want is currently possible (but please prove me wrong).
But I agree that it would be useful. I have a two-language blog, and I have “solved” this problem by creating short and language agnostic sections ("/prod/" in your example).
For Hugo 0.21 we plan to add nested sections, and I will have this in the back of my head. Please also create a GitHub issue to track it.
Add alias for section URL by putting this into _index.md file
aliases = ["/produit"]
This way, it’s guaranteed that /produit and /produit/produit-1 both works. For English language, I don’t do anything so by default /product and /product/product-1 should work.
In my opinion, this is not a recommended way though, just some workaround to make sure even I give https://example.com/fr/produit link to customer, it still works (by redirecting back to /product which is okay for now).
Still, clean and native solution from Hugo would be hugely appreciated.
Did anyone find a way to override the section URL? I’m working on a single-language website, and would like to override the top sections (the slugs of the subsections are fine).
Since I link to the section three times on each page for navigation purposes (header, breadcrumbs, footer), that would create 3 redirected links on each content page. I’m not interested in taking that gamble.
And if I hard code the proper URL in the Hugo templates, building the website fails because htmltest reports a website check error.
I was suggesting using aliases, not something like Netlify _redirects. But I understand that the aliases approach creates a different kind of redirect, using meta refresh.
So… I’m not sure how else you would solve this… you cannot have symlinks in webpages…
Thanks for thinking along. Other than the slug front matter variable for the /ox-hugo/_index.md file working I also don’t know an easy way. I can write a Gulp task to rewrite the HTML files Hugo renders, but that’s tricky since it might break easily.
Perhaps other people have already fixed overriding the section URL.
Wow good catch, that does the trick! Thank you! I tried slug earlier today (which didn’t work) but overlooked url.
For others in this thread, you’ll need to use the url page variable, and not slug. That looks like this. For example to have the /ox-hugo/ section main page render at /ox-hugo-org-exporter/ instead of its default URL, use a front matter like this:
+++
title = "Ox-hugo"
url = "/ox-hugo-org-exporter/"
date = "2018-05-16"
+++
I believe slug did not work because slugs replace the filename part of the path, and for a sections the “_index.md” filename is ultimately stripped away. See Path Breakdown in Hugo.