How to make footnote links absolute?

Hello,

The footnote links work fine when used from within the blog post.

But those links are useless in the summary page (see below), because they are relative links, like #fn:1.

Can those links be make absolute, pointing to the parent post?

The footnotes otherwise work fine within the post.

Try to set canonifyURLs = true in your config.

I do have that.

OK, I see it. That does not work, and I don’t see how to easily get it to work either. So would suggest you write summeries without notes.

Oh well :frowning:

Black Friday limitation?

No, more Einstein’s law of physics.

The thing is, we do the BF rendering once and then reuse it wherever it is needed.

We have the canonify setting that changes the rendered HTML files, but we still don’t know how to apply the proper logic in this case.

Thanks. Do I need to open this as an issue on hugo Github then?

Please look for an existing issue first. This isn’t a new problem.

I’m not sure why I didn’t do this earlier… the solution was simple… just strip off the footnote links from the summary.html layout.

The expression is {{ $your_summary | replaceRE `<sup.*footnote-ref.*><a href.*#fn:.*/a></sup>` "" | safeHTML }}.


Full code

In my summary.html, I have:

<div class="post p-summary" >
    {{ partial "summary_minus_toc.html" . }}
</div>

and the definition of the summary_minus_toc.html partial contains that replaceRE expression at the very end (needs Hugo v0.48+):

{{ $out := "" }}
{{- with .Description -}}
    {{- $out = . | markdownify | printf "<p>%s</p>" | safeHTML -}}
{{- else -}}
    {{- $summary_has_org_toc := substr .Content 0 30 | findRE "[\".]ox-hugo-toc" -}}
    {{- if $summary_has_org_toc -}}
        {{- $content_splits := split .RawContent "<!--endtoc-->" -}} <!-- Need to use .RawContent as we will be parsing for 'more' comment later. -->
        <!-- If Org TOC is present, the special comment endtoc would also be present.
             In that case, output only the part *after* that comment as Summary. -->
        {{- $summary_raw := index $content_splits 1 -}}
        {{- $summary_splits := split $summary_raw "<!--more-->" -}}
        {{- if eq (len $summary_splits) 2 -}}
            {{- $out = index $summary_splits 0 | markdownify -}}
        {{- else -}}
            {{- $out = $summary_raw | markdownify | truncate 300 -}}
        {{- end -}}
    {{- else -}}
        <!-- Print the whole Summary if endtoc special comment is not found. -->
        {{- $out = .Summary | printf "<p>%s</p>" | safeHTML -}}
    {{- end -}}
{{- end -}}
<!-- Strip off footnote links as those relative won't be valid on list pages.
     Example footnote link:
     <sup class="footnote-ref" id="fnref:fn-1"><a href="#fn:fn-1">1</a></sup>
-->
{{- $out = $out | replaceRE `<sup.*footnote-ref.*><a href.*#fn:.*/a></sup>` "" | safeHTML -}}
{{ $out }}

[ The same thing could have been done earlier without var overrides, by using .Scratch ]

Result

No footnote links in summaries!

The same summary block that I pasted in my first post in this thread is now broken-footnote-link-free (of course, over time, the content has slightly changed, and my site theme has improved considerably :smile:):

3 Likes