CaiJimmy / hugo-theme-stack

Card-style Hugo theme designed for bloggers
https://stack.jimmycai.com
GNU General Public License v3.0
4.89k stars 1.6k forks source link

[Bug]: When baseURL has a subdirectory, links in main menu are broken in multilingual mode #770

Closed tamaracha closed 1 year ago

tamaracha commented 1 year ago

What happened?

Situation: Site is in multilingual mode and baseURL has a subdirectory.

Menu links coming from page frontmatter already have the correct language prefix, and absLangURL or relLangURL breaks them. See this issue for further details. Menu templates can differentiate between menu items from frontmatter and from config, and use the page's RelPermalink for the href attribute for frontmatter menus. Only the manual config menu items need the relLangURL pipe.

The URL can be extracted like this:

<a
  href="{{- with .Page -}}
    {{- .RelPermalink -}}
  {{- else -}}
    {{- .URL | relLangURL -}}
  {{- end -}}"
>

Hugo version

0.109.0

Theme version

3.16.0

What browsers are you seeing the problem on?

No response

More information about the browser

No response

Relevant log output

No response

Link to the page with bug

https://demo.stack.jimmycai.com

Link to the source repository

No response

CaiJimmy commented 1 year ago

Sorry for the late reply.

Menu links coming from page frontmatter already have the correct language prefix, and absLangURL or relLangURL breaks them.

The latest version of this theme does not apply absLangURL nor relLangURL to menu links. This was fixed with https://github.com/CaiJimmy/hugo-theme-stack/commit/196116f20d655e4e3f9b4cb2c78edbefc898b7f5 and released with 3.17.0 (I forgot to release this version sorry).

While investigating this issue, I found that in multilingual mode, if I add a manual link in the following way:

    zh-cn:
        menu:
            main:
                - identifier: test
                  name: Test manual link
                  url: /about/
                  weight: 1

The resulting link is SITE_URL/about/ and not SITE_URL/zh-cn/about/, which might be contra-intuitive. The patch you mentioned above solves this problem but prevents users from adding a link which points to another language (I don't know if that's something people would do, whatever).

I'll keep it as it is right now. Since it's more flexible.