Render-heading hook showing incorrect .Page

The .Page variable in my custom render-heading.html hook is sometimes being set to the home page, including its .Title, .Params, etc., so I can’t get access to the current page. I can’t figure out the rule though.

The render hook is in layouts/_default/_markup in my theme.

For pages under /blog it renders correctly (I tried appending {{.Page.Title}} to each heading to check).

I also have a /meta content folder for e.g. my /about page, where I map permalinks to "/:slugorfilename/". For each page in here, the render hook is setting .Page to the home page.

The blog pages also map permalinks to "/:slugorfilename/" so it isn’t that.

I’ve tried running hugo server with --disableFastRender and various other settings, and the bug persists. What am I missing?

Thanks,
Daniel

i doubt hugo will change the value of .Page within the render hook.

without any code I would say you change the context within the hook. so the . is not what you expect.

That was the first thing I checked. Here is the entire render hook:

<h{{ .Level }} id="{{ .Anchor }}" {{- with .Attributes.class }} class="{{ . }}" {{- end }}>
{{- .Text }}
{{- if and (le .Level 3) .Page.Params.showPermalinks -}}
  <a class="heading-anchor accent-icon" href="#{{ .Anchor }}">{{ partial "svg" (dict "name" "link") }}</a>
{{- end -}}
</h{{ .Level }}>

The thing is, in some pages, the .Page value is correct (anything under /blog is working). Elsewhere it is set to the root home page. It isn’t a big website (https://dannorth.net), and the blog is most of the content.

I tried moving some of the buggy pages around, e.g. to the top level, into other folders, etc. Even renaming the file. There is nothing obvious in the front matter for the buggy pages either.

so it’s in the layouts around I suppose.

maybe share it complete

Do you use the markdownify function anywhere?

Yes, in various places. Does this affect the behaviour of render hooks?

Yes.

A contrived example that will produce unexpected results:

{{ .RawContent | markdownify }}

For the record, I always use the RenderString method instead. Without access to your site I can’t tell you if markdownify is the problem.