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

Render the render hooks when calling .Page.RenderShortcodes #12356

Closed
jmooring opened this issue Apr 10, 2024 · 2 comments · Fixed by #12364
Closed

Render the render hooks when calling .Page.RenderShortcodes #12356

jmooring opened this issue Apr 10, 2024 · 2 comments · Fixed by #12364

Comments

@jmooring
Copy link
Member

jmooring commented Apr 10, 2024

I have no idea if this is possible.

Scenario

  1. I have an "include" shortcode as described in the documentation.
  2. I invoke the shortcode using the {{% .. %}} notation so that the headings in the included file appear in the TOC.
  3. The shortcode calls .Page.RenderShortcodes.
  4. The page I'm including is a leaf bundle that contains a markdown image that references a page resource. For example: ![alt](a.jpg).
  5. I enabled the embedded image render hook so that the src attribute of the img element will be relative to the site root.

Problem

The image render hook is evaluated relative to the including page, not relative to the included page, resulting in a broken image.

The workaround is to call .Content instead of .RenderShortcodes, but then the headings of the included page do not contribute to the including page's TOC.

Minimal example

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

Notes

If this were possible, I think the site author would need to set markup.goldmark.renderer.unsafe to true, which isn't great, but it's better than a broken image.

@bep
Copy link
Member

bep commented Apr 11, 2024

I think I have a better way to fix this. Will try to demo it in a PR.

bep added a commit to bep/hugo that referenced this issue Apr 12, 2024
bep added a commit to bep/hugo that referenced this issue Apr 12, 2024
bep added a commit to bep/hugo that referenced this issue Apr 13, 2024
bep added a commit to bep/hugo that referenced this issue Apr 13, 2024
bep added a commit to bep/hugo that referenced this issue Apr 13, 2024
bep added a commit to bep/hugo that referenced this issue Apr 14, 2024
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.

A typical `include` would similar to this:

```handlebars
{{ with site.GetPage (.Get 0) }}
  {{ .RenderShortcodes }}
{{ end }}
```

And when used in a Markdown file:

```markdown
{{% include "/posts/p1" %}}
```

Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.

Note that

* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.

Fixes gohugoio#12356
bep added a commit to bep/hugo that referenced this issue Apr 14, 2024
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.

A typical `include` would similar to this:

```handlebars
{{ with site.GetPage (.Get 0) }}
  {{ .RenderShortcodes }}
{{ end }}
```

And when used in a Markdown file:

```markdown
{{% include "/posts/p1" %}}
```

Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.

Note that

* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.

Fixes gohugoio#12356
bep added a commit to bep/hugo that referenced this issue Apr 14, 2024
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.

A typical `include` would similar to this:

```handlebars
{{ with site.GetPage (.Get 0) }}
  {{ .RenderShortcodes }}
{{ end }}
```

And when used in a Markdown file:

```markdown
{{% include "/posts/p1" %}}
```

Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.

Note that

* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.

Fixes gohugoio#12356
bep added a commit to bep/hugo that referenced this issue Apr 14, 2024
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.

A typical `include` would similar to this:

```handlebars
{{ with site.GetPage (.Get 0) }}
  {{ .RenderShortcodes }}
{{ end }}
```

And when used in a Markdown file:

```markdown
{{% include "/posts/p1" %}}
```

Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.

Note that

* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.

Fixes gohugoio#12356
bep added a commit to bep/hugo that referenced this issue Apr 14, 2024
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.

A typical `include` would similar to this:

```handlebars
{{ with site.GetPage (.Get 0) }}
  {{ .RenderShortcodes }}
{{ end }}
```

And when used in a Markdown file:

```markdown
{{% include "/posts/p1" %}}
```

Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.

Note that

* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.

Fixes gohugoio#12356
bep added a commit to bep/hugo that referenced this issue Apr 14, 2024
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.

A typical `include` would similar to this:

```handlebars
{{ with site.GetPage (.Get 0) }}
  {{ .RenderShortcodes }}
{{ end }}
```

And when used in a Markdown file:

```markdown
{{% include "/posts/p1" %}}
```

Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.

Note that

* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.

Fixes gohugoio#12356
bep added a commit that referenced this issue Apr 15, 2024
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.

A typical `include` would similar to this:

```handlebars
{{ with site.GetPage (.Get 0) }}
  {{ .RenderShortcodes }}
{{ end }}
```

And when used in a Markdown file:

```markdown
{{% include "/posts/p1" %}}
```

Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.

Note that

* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.

Fixes #12356
Copy link

github-actions bot commented May 7, 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 May 7, 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