Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Mar 14, 2024 · 3 comments · Fixed by #12246

Comments

@CXwudi
Copy link

CXwudi commented Mar 14, 2024

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
Copy link
Author

CXwudi commented Mar 14, 2024

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
Copy link
Member

jmooring commented Mar 14, 2024

@CXwudi Thanks for creating this issue. This will be resolved with #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
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
  {{- if .Get "link" -}}
    <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
  {{- 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 -}}

  <img src="{{ $src }}"
    {{- if or (.Get "alt") (.Get "caption") }}
    alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
    {{- end -}}
    {{- with .Get "width" }} width="{{ . }}"{{ end -}}
    {{- with .Get "height" }} height="{{ . }}"{{ end -}}
    {{- with .Get "loading" }} loading="{{ . }}"{{ end -}}
  /><!-- Closing img tag -->
  {{- if .Get "link" }}</a>{{ end -}}
  {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
    <figcaption>
      {{ with (.Get "title") -}}
          <h4>{{ . }}</h4>
      {{- 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>

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

@jmooring jmooring self-assigned this Mar 14, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Mar 14, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Mar 14, 2024
@jmooring jmooring changed the title [Bug]: figure shortcode is not working for images stored in the same folder as in the markdown blog post for non default languages figure shortcode is not working for images stored in the same folder as in the markdown blog post for non default languages Mar 14, 2024
Copy link

github-actions bot commented Apr 5, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants