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

Handle .Page.Fragments.Identifiers.Contains (on self) etc. from hooks #10750

Closed
bep opened this issue Feb 24, 2023 · 1 comment · Fixed by #10752
Closed

Handle .Page.Fragments.Identifiers.Contains (on self) etc. from hooks #10750

bep opened this issue Feb 24, 2023 · 1 comment · Fixed by #10752
Assignees
Milestone

Comments

@bep
Copy link
Member

bep commented Feb 24, 2023

I recently added .Fragments to the page object. What I'm describing in this issue is a known limitation, to me anyway, but I suspect that this new object will be used enough (to build ToC, to enable auditing of duplicate identifiers, bad links etc.) that there will be enough surprises to warrant fixing this.

As of writing this issue, this and variations of this (including using the .Related method when having a fragments type of index configured) will fail from a render hook template:

{{ .Page.Fragments.Identifiers.Contains "some-title" }}

The above will currently create a "bite your own tail" situation.

Luckily, Goldmark allows us to split parsing and rendering, so I will fix this.

A quick semi-related note about shortcodes at the end. To do something similar in shortcodes you need to use the {{< delimiter, e.g:

## Some Title

{{< foo.inline >}}
{{ .Page.Fragments.Identifiers.Contains "some-title" }}
{{< /foo.inline >}}

The reason for this is that the {{% inner content will be evaluated before we hand it to Goldmark to parse as Markdown.

/cc @jmooring

@bep bep added this to the v0.111.0 milestone Feb 24, 2023
@bep bep self-assigned this Feb 24, 2023
bep added a commit to bep/hugo that referenced this issue Feb 24, 2023
This also speeds up situations where you only need the fragments/toc and not the rendered content, e.g. Related
with fragments type indexing:

```bash

name            old time/op    new time/op    delta
RelatedSite-10    12.3ms ± 2%    10.7ms ± 1%  -12.95%  (p=0.029 n=4+4)

name            old alloc/op   new alloc/op   delta
RelatedSite-10    38.6MB ± 0%    38.2MB ± 0%   -1.08%  (p=0.029 n=4+4)

name            old allocs/op  new allocs/op  delta
RelatedSite-10      117k ± 0%      115k ± 0%   -1.36%  (p=0.029 n=4+4)
```

Fixes gohugoio#10750
bep added a commit that referenced this issue Feb 24, 2023
This also speeds up situations where you only need the fragments/toc and not the rendered content, e.g. Related
with fragments type indexing:

```bash

name            old time/op    new time/op    delta
RelatedSite-10    12.3ms ± 2%    10.7ms ± 1%  -12.95%  (p=0.029 n=4+4)

name            old alloc/op   new alloc/op   delta
RelatedSite-10    38.6MB ± 0%    38.2MB ± 0%   -1.08%  (p=0.029 n=4+4)

name            old allocs/op  new allocs/op  delta
RelatedSite-10      117k ± 0%      115k ± 0%   -1.36%  (p=0.029 n=4+4)
```

Fixes #10750
@github-actions
Copy link

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 Mar 19, 2023
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.

1 participant