mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-11-10 00:12:09 +00:00
86143428f3
- Streamline CSS to reduce duplication - Better backlink accessible names for endnotes with multiple backlinks This required updating a false positive filter in my vnu jq filter.
46 lines
2.2 KiB
HTML
46 lines
2.2 KiB
HTML
{{- $footnote_heading := printf "Footnotes" -}}
|
|
{{- if .Params.footnote_heading -}}
|
|
{{- $footnote_heading = .Params.footnote_heading -}}
|
|
{{- end -}}
|
|
|
|
<!--
|
|
Add heading to footnotes, remove unused class.
|
|
Requires Goldmark v1.4.12 or higher, since that version switched
|
|
endnotes from a <section> to a <div>.
|
|
-->
|
|
{{- $referencesWithoutHeading := `(<div class="footnotes" role="doc-endnotes">
|
|
<hr>)` -}}
|
|
{{- $referencesWithHeading := printf `<hr>
|
|
<section role="doc-endnotes" aria-labelledby="note-hd">
|
|
<h2 id="note-hd">%s</h2>` ($footnote_heading) -}}
|
|
|
|
{{- $endnotesClosingDiv := `</a></p>
|
|
</li>
|
|
</ol>
|
|
</div>` -}}
|
|
|
|
{{- $endnotesClosingSection := printf `</a></p>
|
|
</li>
|
|
</ol>
|
|
</section>` -}}
|
|
|
|
<!--Descriptive footnote link names, remove unused class-->
|
|
{{- $badNoteRef := `class="footnote-ref" role="doc-noteref">([0-9]*)</a>` -}}
|
|
{{- $goodNoteRef := `role="doc-noteref">note ${1}</a>` -}}
|
|
|
|
<!--Move the Table of Contents heading *inside* the <nav> element-->
|
|
{{- $tocHeadingOutside := `<h2>Table of Contents</h2><nav(?:.*)>` -}}
|
|
{{- $tocHeadingInside := `<nav id=TableOfContents role="doc-toc"><h2 id="toc-hd">Table of Contents</h2>` -}}
|
|
|
|
<!--Give footnote backlinks accessible names-->
|
|
{{- $footnoteBacklinksBad := `<a href="#fnref:([0-9]*)" class="footnote-backref"(.*role="doc-backlink"(?:.*)?)>` -}}
|
|
{{- $footnoteBacklinksGood := `<a href="#fnref:${1}" aria-label="back to reference ${1}"${2}>` -}}
|
|
|
|
<!--
|
|
If two backlinks exist, give them different names.
|
|
I currently don't have any triple backlinks; if I ever do, I'll implement this properly with a loop.
|
|
-->
|
|
{{- $repeatedFootnoteBacklinksBad := `"back to reference ([0-9]*)"(.*)<a href="#fnref([0-9]):([0-9]*)"(.*role="doc-backlink"(?:.*)?)>` -}}
|
|
{{- $repeatedFootnoteBacklinksGood := `"back to reference ${1}, instance 1"${2}<a href="#fnref${3}:${4}" aria-label="back to reference ${4}, instance 2"${5}>` -}}
|
|
|
|
{{- .Content | replaceRE $referencesWithoutHeading $referencesWithHeading | replaceRE $badNoteRef $goodNoteRef | replaceRE $endnotesClosingDiv $endnotesClosingSection | replaceRE $tocHeadingOutside $tocHeadingInside | replaceRE $footnoteBacklinksBad $footnoteBacklinksGood | replaceRE $repeatedFootnoteBacklinksBad $repeatedFootnoteBacklinksGood | safeHTML -}}
|