Section URL doesn't change on content page but works on list page

Hello, I’m trying to make a section and its pages to have different URLs based on the language that I’m currently on.

For example I wish to have a /portfolio-es/some_post.md for the Spanish version and /portfolio-en/some_post.md for the English version.
I found out that I can use the url keyword in the front matter to override the URL and the layout keyword to point to use a single layout (so I don’t have to repeat the portfolio-lang for each language) in the list page (by adding in the front matter on /portfolio/_index.html). So now when I try to reach the Spanish version of the portfolio I get the url baseURL/es/portfolio-es which is what I want.

Seems to work but when I try to reach the post from the list it points me to an /portfolio/some_post, it skips the url keyword that I added in the front matter.

Any idea how to fix this, or is there a way to do it even better?
Below is my project structure:

tree -I 'modules|static'
.
├── README.md
├── config.yaml
├── content
│   ├── en
│   │   ├── contact.html
│   │   └── portfolio
│   │       ├── _index.html
│   │       └── ceva.md
│   ├── es
│   │   ├── contact.html
│   │   └── portfolio
│   │       ├── _index.html
│   │       └── ceva.md
│   └── ro
│       ├── contact.html
│       └── portfolio
│           ├── _index.html
│           └── ceva.md
├── i18n
│   ├── en.yaml
│   ├── es.yaml
│   └── ro.yaml
├── resources
│   └── _gen
│       ├── assets
│       └── images
└── themes
    └── hugo-personal-theme
        ├── LICENSE
        ├── README.md
        ├── archetypes
        │   └── default.md
        ├── assets
        │   ├── css
        │   │   ├── styles.css
        │   │   └── styles.css.map
        │   └── js
        │       └── dark-mode.js
        ├── layouts
        │   ├── 404.html
        │   ├── _default
        │   │   ├── baseof.html
        │   │   ├── contact.html
        │   │   ├── list.html
        │   │   └── single.html
        │   ├── index.html
        │   ├── partials
        │   │   ├── blog-post-list-item.html
        │   │   ├── components
        │   │   │   ├── blog
        │   │   │   │   └── blog_item.html
        │   │   │   ├── projects
        │   │   │   │   └── project_item.html
        │   │   │   └── resume
        │   │   │       └── resume.html
        │   │   ├── dark-mode-switch.html
        │   │   ├── footer.html
        │   │   ├── head.html
        │   │   ├── header.html
        │   │   ├── pages
        │   │   │   ├── blog
        │   │   │   │   ├── _list.html
        │   │   │   │   └── _single.html
        │   │   │   ├── contact
        │   │   │   │   └── _single.html
        │   │   │   ├── portfolio
        │   │   │   │   ├── _list.html
        │   │   │   │   └── _single.html
        │   │   │   └── resume
        │   │   │       └── _single.html
        │   │   ├── translations.html
        │   │   └── util-fab.html
        │   └── portfolio
        │       ├── list.html
        │       └── single.html
        └── theme.toml

31 directories, 45 files

If you have a relative link that begins with a forward slash then its URL will point to the host root despite the multilingual config and a content file’s url parameter.

For example:
/portfolio/some_post ===> https://example.com/portfolio/some_post/
portfolio/some_post ===> https://example.com/<lang code>/portfolio/some_post/

If the above does not solve your issue ,then please share the link to your repo for people to have a further look.

The thing is that I’m not using any custom URL, I just use the range function to loop over the pages of the current section:

{{ define "main" }}
portfolio-list
<br>
{{ range .Pages }}
<a href="{{.Permalink}}">to post :{{.Permalink}}</a>
{{ end }}
{{ end }}

and as a result I get :

portfolio-list
to post :http://localhost:61876/en/portfolio/ceva-en/

Since I added the url keyword to _index.html front matter I was expecting to get :

portfolio-list
to post :http://localhost:61876/en/portfolio-en/ceva-en/

but it seems to only apply the url to the list page and not the single content.

Any way to fix this?

Please.

I have created a test repo :
test

I have found a solution using the permalink keyword in the config file from a hugo issue I have discovered here

There is also another workaround in the comments from that same issue (https://github.com/gohugoio/hugo/issues/3354#issuecomment-475975122)
involving the translationKey keyword.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.