gohugoio / hugo

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

`figure` shortcode is not working for images stored in the same folder as in the markdown blog post for non default languages #12244

Closed CXwudi closed 7 months ago

CXwudi commented 7 months ago

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

Hugo v0.123.8 extended version

Does this issue reproduce with the latest release?

I have a folder structure is as following:

.
└── content
    └── posts
        └── my-first-post
            ├── img.png
            ├── index.en.md
            └── index.zh-cn.md

And my blog has set the default language to English.

Using the figure shortcode, I can see that img.png is properly showing in index.en.md but not index.zh-cn.md

The shorcode I used in both markdown file is simply just {{< figure src="img.png" caption="xxx">}}.

Downgrading Hugo to v0.121.2 works.

CXwudi commented 7 months ago

A reproducible sample can be my repo at https://github.com/CXwudi/personal-blog-source, change the HUGO_VERSION in .devcontainer\.env to 0.123.8, and run ./test-local.sh in the root directory to bring up my blog. Checkout the Chinese version of the first post and you can see image

jmooring commented 7 months ago

@CXwudi Thanks for creating this issue. This will be resolved with https://github.com/gohugoio/hugo/issues/12245.

In the interim, assuming that you are using the embedded figure shortcode described here, create your own to override it:

layouts/shortcodes/figure.html ```text {{- if .Get "link" -}} {{- end -}} {{- $u := urls.Parse (.Get "src") -}} {{- $src := $u.String -}} {{- if not $u.IsAbs -}} {{- with or (.Page.Resources.Get $u.Path) (resources.Get $u.Path) -}} {{- $src = .RelPermalink -}} {{- end -}} {{- end -}} {{ with .Get {{- if .Get "link" }}{{ end -}} {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
{{ with (.Get "title") -}}

{{ . }}

{{- end -}} {{- if or (.Get "caption") (.Get "attr") -}}

{{- .Get "caption" | markdownify -}} {{- with .Get "attrlink" }} {{- end -}} {{- .Get "attr" | markdownify -}} {{- if .Get "attrlink" }}{{ end }}

{{- end }}
{{- end }} ```


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

github-actions[bot] commented 6 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.