gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.19k stars 7.48k forks source link

Inconsistency between .Translations and .Resources in a multilingual multi-host website #12333

Open ov opened 6 months ago

ov commented 6 months ago

See #12320 for the beginning of the discussion.

For a multilingual multi-host site the page resources are kept shared even if the pages are not considered the translations of each other. This started in 0.123 and is still a problem in the latest version.

See the repository here: https://github.com/ov/hugo-bundle-issue

It has two translations placed into different folders. Each translation has two folders bundled and not-bundled. The difference is that the pages in not-bundled have translationKey defined to be different for both languages, so they don't think they are the translations. The bundled pages don't have that key explicitly set, so are considered the translations of each other.

The code in layout/_default is the same for list and single and shows the translations and the resources of the page.

Now if you build a site and check the /bundled/ pages for both translations, you'll notice that both pages see each other as translations and have their resources shared. That's the expected behaviour of a page bundle, that's fine.

Now check the /not-bundled/ pages of both translations. You'll find that they don't see each other as translations (due to the different translationKey), but still share the resources. You can also see that all the resources are present in public/<lang>/not-bundled/ folders.

Expected behaviour: if the pages don't see each other as translations, their resources should not be shared, copied and mentioned in .Resources

Actual behaviour: the resources are shared, copied and mentioned, which looks inconsistent.

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.124.1+extended darwin/arm64 BuildDate=unknown

Does this issue reproduce with the latest release?

yes

jmooring commented 6 months ago

Before I look at this, if you haven't already done so, please build from HEAD and retest... https://github.com/gohugoio/hugo/issues/12320 was fixed this morning by https://github.com/gohugoio/hugo/pull/12331.

ov commented 6 months ago

I've just tried it with:

hugo v0.125.0-DEV+extended darwin/arm64 BuildDate=unknown

and the problem is still there. It is somewhat different to #12320, though.

jmooring commented 6 months ago

This isn't a regression... v0.122.0 and v0.124.1 behave identically.

config

defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = true

[languages.en]
baseURL = "https://en.example.org"
contentDir = "content/en"

[languages.fr]
baseURL = "https://fr.example.org"
contentDir = "content/fr"

content

content/
├── en/
│   └── p1/
│       ├── a.txt
│       └── index.md  <-- translationKey: en-p1
└── fr/
    └── p1/
        ├── b.txt
        └── index.md  <-- translationKey: fr-p1

published (v0.122.0)

public/
├── en/
│   └── p1/
│       ├── a.txt
│       ├── b.txt
│       └── index.html
└── fr/
    └── p1/
        ├── a.txt
        ├── b.txt
        └── index.html

published (v0.124.1) (same as above)

public/
├── en/
│   └── p1/
│       ├── a.txt
│       ├── b.txt
│       └── index.html
└── fr/
    └── p1/
        ├── a.txt
        ├── b.txt
        └── index.html

expected

public/
├── en/
│   └── p1/
│       ├── a.txt
│       └── index.html
└── fr/
    └── p1/
        ├── b.txt
        └── index.html

test site

git clone --single-branch -b hugo-github-issue-12333 https://github.com/jmooring/hugo-testing hugo-github-issue-12333
cd hugo-github-issue-12333
rm -rf public && hugo && tree public

test case

test case ```go func TestFoo(t *testing.T) { t.Parallel() files := ` -- hugo.toml -- disableKinds = ['home','section','rss','sitemap','taxonomy','term'] defaultContentLanguage = 'en' defaultContentLanguageInSubdir = true [languages.en] baseURL = "https://en.example.org" contentDir = "content/en" [languages.fr] baseURL = "https://fr.example.org" contentDir = "content/fr" -- layouts/_default/single.html -- {{ .Title }} -- content/en/p1/index.md -- --- title: p1 translationKey: en-p1 --- -- content/fr/p1/index.md -- --- title: p1 translationKey: fr-p1 --- -- content/en/p1/a.txt -- a -- content/fr/p1/b.txt -- b ` b := hugolib.Test(t, files) b.AssertFileExists("public/en/p1/a.txt", true) b.AssertFileExists("public/en/p1/b.txt", false) // failing test b.AssertFileExists("public/fr/p1/b.txt", true) b.AssertFileExists("public/fr/p1/a.txt", false) // failing test } ```


ov commented 6 months ago

After double-checking that, I agree that this might not be a regression.

I used to have a few resources belonging to the home directory in v0.122 which were not shared or bundled even without translationKey provided. That just worked (I mentioned that in #12320). However, after checking the bundling rules it seems that the behaviour was incorrect in v0.122.

You fixed that in v0.123 and the resources started getting bundled and copied which was not what I needed, so I tried to "unlink" them by providing different translationKey elements. This didn't help, so I filed the report. I still think this is an inconsistency bug, but instead of regression this looks like a partially working fix or so.

Let me know if you want a repo with that setup for v0.122. It is a little unrelated to this specific issue, so I didn't provide that initially.