No resources in page bundle multilanguage

For some reason, this was working before, but doesn’t work anymore.

I have the following folder structure:

content/
    posts/
        server-names/
            index.es.md
            image.png

But I can’t use the image, because it tells me there are no resources. In the template I use, I put the following code:

<pre>{{ debug.Dump ($.Page ) }}</pre>
<pre>{{ debug.Dump ($.Page.Resources ) }}</pre>

Which shows:

Show json
{
  "PageWithoutContent": {
    "Date": "2023-09-03T11:19:15.811Z",
    "Lastmod": "2023-09-05T08:33:08.398Z",
    "PublishDate": "2023-09-03T11:19:15.811Z",
    "ExpiryDate": "0001-01-01T00:00:00Z",
    "Aliases": null,
    "BundleType": "leaf",
    "Description": "",
    "Draft": false,
    "IsHome": false,
    "Keywords": null,
    "Kind": "page",
    "Layout": "",
    "LinkTitle": "¿Cómo se llaman mis servidores?",
    "IsNode": false,
    "IsPage": true,
    "Path": "/posts/server-names",
    "Slug": "",
    "Lang": "es",
    "IsSection": false,
    "Section": "posts",
    "Sitemap": {
      "ChangeFreq": "",
      "Priority": -1,
      "Filename": "sitemap.xml",
      "Disable": false
    },
    "Type": "posts",
    "Weight": 0
  },
  "TableOfContentsProvider": {
    "Date": "2023-09-03T11:19:15.811Z",
    "Lastmod": "2023-09-05T08:33:08.398Z",
    "PublishDate": "2023-09-03T11:19:15.811Z",
    "ExpiryDate": "0001-01-01T00:00:00Z",
    "Aliases": null,
    "BundleType": "leaf",
    "Description": "",
    "Draft": false,
    "IsHome": false,
    "Keywords": null,
    "Kind": "page",
    "Layout": "",
    "LinkTitle": "¿Cómo se llaman mis servidores?",
    "IsNode": false,
    "IsPage": true,
    "Path": "/posts/server-names",
    "Slug": "",
    "Lang": "es",
    "IsSection": false,
    "Section": "posts",
    "Sitemap": {
      "ChangeFreq": "",
      "Priority": -1,
      "Filename": "sitemap.xml",
      "Disable": false
    },
    "Type": "posts",
    "Weight": 0
  },
  "ContentProvider": 0
}
null

The rest of the post is fine

Hugo version:

$ hugo version
hugo v0.125.6+extended linux/amd64 BuildDate=unknown

If I create an empty index.md file, the result would be this:

{
  "PageWithoutContent": {
    "Date": "2023-09-03T11:19:15.811Z",
    "Lastmod": "2023-09-05T08:33:08.398Z",
    "PublishDate": "2023-09-03T11:19:15.811Z",
    "ExpiryDate": "0001-01-01T00:00:00Z",
    "Aliases": null,
    "BundleType": "leaf",
    "Description": "",
    "Draft": false,
    "IsHome": false,
    "Keywords": null,
    "Kind": "page",
    "Layout": "",
    "LinkTitle": "¿Cómo se llaman mis servidores?",
    "IsNode": false,
    "IsPage": true,
    "Path": "/posts/server-names",
    "Slug": "",
    "Lang": "es",
    "IsSection": false,
    "Section": "posts",
    "Sitemap": {
      "ChangeFreq": "",
      "Priority": -1,
      "Filename": "sitemap.xml",
      "Disable": false
    },
    "Type": "posts",
    "Weight": 0
  },
  "TableOfContentsProvider": {
    "Date": "2023-09-03T11:19:15.811Z",
    "Lastmod": "2023-09-05T08:33:08.398Z",
    "PublishDate": "2023-09-03T11:19:15.811Z",
    "ExpiryDate": "0001-01-01T00:00:00Z",
    "Aliases": null,
    "BundleType": "leaf",
    "Description": "",
    "Draft": false,
    "IsHome": false,
    "Keywords": null,
    "Kind": "page",
    "Layout": "",
    "LinkTitle": "¿Cómo se llaman mis servidores?",
    "IsNode": false,
    "IsPage": true,
    "Path": "/posts/server-names",
    "Slug": "",
    "Lang": "es",
    "IsSection": false,
    "Section": "posts",
    "Sitemap": {
      "ChangeFreq": "",
      "Priority": -1,
      "Filename": "sitemap.xml",
      "Disable": false
    },
    "Type": "posts",
    "Weight": 0
  },
  "ContentProvider": 0
}
[
  {
    "Staler": {}
  },
  {
    "Staler": {}
  },
  {
    "Staler": {}
  },
  {
    "Staler": {}
  }
]

Note: There are 4 images in the folder

Hm… The problem doesn’t happen with Hugo 0.118.2 (the one I use on my server)

I tried with every version from 0.118 to 0.126.1, and images are shown up to 0.122.0, on the next version tested, 0.123.0, it doesn’t show the images.

I will explore the changelog

  • A new document store. Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role. With this we also introduce a new logical page Path which we will used going forward to support other content data sources.
    Hugo Releases v0.123.0

THIS seems to be the problem…

Oh, it seems that using duplicateResourceFiles works. But how can I update my shortcode to use the new method without duplication?

<figure{{ if or (.Get "class") (eq (.Get "align") "center") }} class="
           {{- if eq (.Get "align") "center" }}align-center {{ end }}
           {{- with .Get "class" }}{{ . }}{{- end }}"
{{- end -}}>
    {{- if .Get "link" -}}
        <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
    {{- end }}
    {{- $responsiveImages := (.Params.responsiveImages | default site.Params.responsiveImages) | default true }}
    {{- $img := ($.Page.Resources.ByType "image").GetMatch (printf "*%s*" (.Get "src")) }}
    {{- if $img -}}{{/* i.e it is present in page bundle */}}
        {{- $sizes := (slice "360" "480" "720" "1080" "1500") }}
        {{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") -}}
        {{- if hugo.IsExtended -}}
            {{- $processableFormats = $processableFormats | append "webp" -}}
        {{- end -}}
        {{- $prod := (hugo.IsProduction | or (eq site.Params.env "production")) }}
        {{- if (and (in $processableFormats $img.MediaType.SubType) ($responsiveImages) (eq $prod true)) }}
        <img loading="lazy" srcset="{{- range $size := $sizes -}}
                        {{- if (ge $img.Width $size) -}}
                        {{ printf "%s %s" (($img.Resize (printf "%sx" $size)).Permalink) (printf "%sw ," $size) -}}
                        {{ end }}
                    {{- end -}}{{$img.Permalink }} {{printf "%dw" ($img.Width)}}" 
            sizes="(min-width: 768px) 720px, 100vw" src="{{ $img.Permalink }}" alt="{{ .Get "alt" }}" 
            width="{{ $img.Width }}" height="{{ $img.Height }}">
        {{- else }}{{/* Unprocessable image or responsive images disabled */}}
        <img loading="lazy" src="{{ (path.Join $.Page.RelPermalink (.Get "src")) | absURL }}" alt="{{ .Get "alt" }}">
        {{- end }}
    {{- else }}{{/* For absolute urls and external links, no img processing here */}}
            <img loading="lazy" src="{{ (.Get "src") | absURL }}" alt="{{ .Get "alt" }}"
            {{- with .Get "width" }} width="{{ . }}"{{ end -}}
            {{- with .Get "height" }} height="{{ . }}"{{ end -}}
            /> <!-- Clossing img tag -->
    {{- end }}
    {{- if .Get "link" -}}
        </a>
    {{- end }}

    {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
        <figcaption>
            {{ with (.Get "title") -}}
                {{ . }}
            {{- end -}}
            {{- if or (.Get "caption") (.Get "attr") -}}<p>
                {{- .Get "caption" | markdownify -}}
                {{- with .Get "attrlink" }}
                    <a href="{{ . }}">
                {{- end -}}
                {{- .Get "attr" | markdownify -}}
                {{- if .Get "attrlink" }}</a>{{ end }}</p>
            {{- end }}
        </figcaption>
    {{- end }}
</figure>

I think is related to the following bug

1 Like

First, it is almost never a good idea to set duplicateResourceFiles to true. The resource de-duplication introduced in v0.123.0 is a huge win for multilingual single-host sites:

This approach reduces build times, storage requirements, bandwidth consumption, and deployment times, ultimately reducing cost.

See https://gohugo.io/content-management/page-resources/#multilingual.

Second, if a particular page does not exist in the default language, add the language key to the resource filename. In your case, where the default content language is English (en)…

content/
├── posts/
│   └── server-names/
│       ├── image.es.png
│       └── index.es.md
├── _index.en.md
└── _index.es.md

Try it:

git clone --single-branch -b hugo-forum-topic-50061 https://github.com/jmooring/hugo-testing hugo-forum-topic-50061
cd hugo-forum-topic-50061
hugo server

Third, in your shortcode, don’t do this:

<img loading="lazy" src="{{ (path.Join $.Page.RelPermalink (.Get "src")) | absURL }}" alt="{{ .Get "alt" }}">

Do this instead:

<img loading="lazy" src="{{ $img.RelPermalink }}" alt="{{ .Get "alt" }}">

Finally, the issue you referenced is not a bug. The issue is closed, and commenting on closed issues isn’t a great idea.

2 Likes

But then, if you have a draft, the behaviour would change whether you build the drafts or not.

If you build the draft, you won’t need to put the language code, but if you don’t build it, you should put it. Or, in another case, if you have a second-language-only post, and later down the road you create the main language post you would need to rename all the images.

I think the images should work without the language code in the filename.

Thanks for helping me with the shortcode, by the way!

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