Skip to content

markdownify resolves page resources to home instead of current page when render hooks are present #9692

Open
@jmooring

Description

@jmooring

The result is either a missing resource or the wrong resource. This is limited to the markdownify function... .Page.RenderString works as expected.

The problem occurs with v0.93.0 and later.

structure

content/
├── test/
│   ├── a.jpg
│   └── index.md
├── b.jpg
└── _index.md

content/test/index.md

{{< img "![kitten](a.jpg)" >}}

layouts/shortcodes/img.html

{{ .Get 0 | markdownify }}

layouts/_default/_markup/render-image.html

{{ with $i := .Page.Resources.GetMatch .Destination }}
  <img src="{{ .RelPermalink }}">
{{ else }}
  {{ errorf "Unable to get %q as a page resource" .Destination }}
{{ end }}

When you run hugo, the result is:

ERROR 2022/03/18 08:46:47 Unable to get "a.jpg" as a page resource

If you do this...

mv content/b.jpg content/a.jpg

...the site builds but the wrong image is displayed.

Example:

git clone --single-branch -b hugo-github-issue-9692 https://github.com/jmooring/hugo-testing hugo-github-issue-9692
cd hugo-github-issue-9692
hugo 

Reference: https://discourse.gohugo.io/t/37735

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions