gohugoio / hugo

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

multilingual: Warn when resources are discarded #12079

Open jmooring opened 7 months ago

jmooring commented 7 months ago

Reference: https://discourse.gohugo.io/t/hugo-v0-123-0-images-are-not-showing-up-any-more/48359/9

This is a goofy setup to begin with, but maybe we should warn users if we're going to discard resources.

content/
├── de/
│   └── s1/
│       └── files/        <-- branch bundle
│           ├── _index.md
│           └── a.txt
└── en/
    └── s1/
        └── files/        <-- just a dumb directory of s1 page resources
            └── b.txt

Build with v0.122.0

public/
├── de/
│   ├── s1/
│   │   ├── files/
│   │   │   ├── a.txt
│   │   │   └── index.html
│   │   └── index.html
│   └── index.html
├── en/
│   ├── s1/
│   │   └── files/
│   │       └── b.txt  <-- discarded with v0.123.0 (see below)
│   └── index.html
└── index.html

Build with v0.123.0

public/
├── de/
│   ├── s1/
│   │   ├── files/
│   │   │   ├── a.txt
│   │   │   └── index.html
│   │   └── index.html
│   └── index.html
├── en/
│   └── index.html
└── index.html
test case ```go func TestFoo(t *testing.T) { t.Parallel() files := ` -- config.toml -- disableKinds = ['rss','sitemap','taxonomy','term'] defaultContentLanguage = 'en' defaultContentLanguageInSubdir = true [languages.en] contentDir = 'content/en' weight = 1 [languages.de] contentDir = 'content/de' weight = 2 -- layouts/_default/list.html -- {{ .Title }} -- content/de/s1/files/_index.md -- --- title: irrelevant --- -- content/de/s1/files/a.txt -- I am de/s1/files/a.txt -- -- content/en/s1/files/b.txt -- I am en/s1/files/b.txt ` b := hugolib.Test(t, files) b.AssertFileExists("public/de/s1/files/index.html", true) b.AssertFileExists("public/en/s1/files/index.html", false) b.AssertFileExists("public/de/s1/files/a.txt", true) // This is the failing test: b.AssertFileExists("public/en/s1/files/b.txt", true) } ```


bep commented 7 months ago

It's not obvious to me what happens in the example above.

jmooring commented 7 months ago

Do I need to clarify anything, or are you commenting about what's actually happening?

bep commented 7 months ago

No, I'm just saying that I need to check how we treat the case above before I can determine if it's right or wrong or if its possible/practical to warn about it.

j0hax commented 7 months ago

Hi, I'm also affected by this issue. In my case I am publishing mixed-language university notes, using either index.md oder index.de.md for my files depending on the language of the material.

# Abbreviated excerpts from my hugo.toml

languageCode = 'en-US'

[languages]
  [languages.de]
    languageCode = 'de-DE'
    languageDirection = 'ltr'
    languageName = 'Deutsch'
  [languages.en]
    languageCode = 'en-US'
    languageDirection = 'ltr'
    languageName = 'English'

Note the following example, the ai and compiler-theory branch bundles are localized as en-US (my default language), while the ds branch is German. Hugo v0.123.1 has completely removed the ability to see any images I have for German course notes.

content/notes/
├── ai
│   ├── csp.md
│   ├── _index.md
│   ├── mdp.md
│   ├── rl.md
│   └── search.md
├── compiler-theory
│   ├── _index.md
│   ├── lambdacalculus.md
│   ├── sml.md
│   └── types.md
├── ds
│   ├── algebra.de.md
│   ├── binomial.de.md
│   ├── counting.de.md
│   ├── graphs.de.md
│   ├── _index.de.md
│   ├── recursive.de.md
│   ├── solutions
│   │   ├── algebraische-strukturen.de.md
│   │   ├── graphentheorie
│   │   │   ├── adjgraph.png
│   │   │   ├── index.de.md
│   │   ├── _index.de.md
│   │   ├── kombinatorik.de.md
│   │   └── rekursionsgleichungen
│   │       ├── index.de.md
│   │       └── steine.png
│   ├── spicker
│   │   ├── index.de.md
│   │   ├── scan-back.jpg
│   │   └── scan.jpg
│   └── stirling.de.md
├── _index.de.md
├── _index.md
jmooring commented 7 months ago

This may or may not be the same issue. Can you please share your site repo with us so that we don't have to recreate/guess?

j0hax commented 7 months ago

Of course: https://github.com/j0hax/j0hax.github.io/

Multilingual pages are under /content/notes/

jmooring commented 7 months ago

@j0hax I have opened a separate issue for your problem. See https://github.com/gohugoio/hugo/issues/12107.