I’ve made use of {{ .Summary }} to render out either the auto generated X character summary or my manually split summary however it looks like footnote tags are still included even though the footnotes themselves are not, leaving unclickable [^1] in the summary.
This post mentions the same problem and that solving it may not be simple.
That said, what would be involved in stripping out the footnote tags e.g. [^1] when displaying .Summary?
The other alternative I’m considering is adding a post-summary = “< p >stuff</ p >” to the frontmatter but I’d prefer to only use that in cases where I want a pretty different summary of a post due to the need for markup and duplication of content.
Is this something .Summary should handle, or should I suck it up and use replaceRE on Summary to remove the footnote tags?
Yes, these options are there (although the <--!more--> tag wouldn’t help much in a case of a footnote in the first sentence), but this is a clear enough case that should, IMO, be considered a bug.
I mean, I don’t believe there’s a usecase where that rogue “1” at the end of a word in summary is actually desired. Stripping footnotes is what should be done by Hugo automatically when generating .Summary both by autosplitting and when <--!more--> is used. A frontmatter-defined summary might be an exception, but are there really any users that place a footnote there?
Oh, the tags are stripped alright, which actually makes the case worse.
You see, a footnote[1] is rendered as a link containing some text. In the case of Discourse it is replaced with some JS magic, but in Hugo, it would be just 1, wrapped in <a> and <sup>.
The Hugo automatic summary process (as well as with the <--!more--> tag) strips those tags. The resulting summary looks like:
You see, a footnote1 is rendered as a link containing…
And since that “1” there is no longer wrapped in any tags, there’s no good way to replaceRE it. Definitely a bug IMO.
A footnote[^1] here. A superscript<sup>®</sup> after it.
Is rendered by Goldmark as:
<p>A footnote<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> here. A superscript<sup>®</sup> after it.</p>
So the regex to strip it out is not simple.
There’s been discussion in the past related to using bluemonday to sanitize HTML, and it has a regex option. We might want to look at that before spending more time on what we have now, which is a little bit broken.
Yep, I wouldn’t want to try doing this with regex. Of course, in HTML terms the task is pretty simple: completely wipe out any node that has id prefixed with “fnref:” and anything inside it.
Of course, this needs to be done before the tags are stripped in the process of .Summary generation, which is AFAIK not something a user can currently do.
Thank you for the correction. It “worked” on my site (single footnote instances within summaries) but I clearly didn’t test it on the example string above.
If anybody plans to use that regex, I don’t believe it’ll work if you’re using named footnotes[^like-this], but this should work.[^1]