-
-
Notifications
You must be signed in to change notification settings - Fork 378
Description
Hello. I'm looking for a more efficient and correct way to transliterate characters for generating anchor links within a page, in the responsive sidebar, and in the table of contents.
I've implemented a solution using a partials/transliterate.html file:
{{- $text := . -}}
{{- $id := $text | lower -}}
{{- $pairs := dict
...
-}}
{{- range $key, $val := $pairs -}}
{{- $id = replace $id $key $val -}}
{{- end -}}
{{- $id = anchorize $id -}}
{{- return $id -}}
This involved modifying render-heading.html:
{{- $customAnchor := partial "transliterate.html" .PlainText -}}
<h{{ .Level }}>
{{- .Text | safeHTML -}}
{{- if gt .Level 1 -}}
<span class="hx-absolute -hx-mt-20" id="{{ $customAnchor }}"></span>
<a href="#{{ $customAnchor }}" class="subheading-anchor" aria-label="Permalink for this section"></a>
{{- end -}}
</h{{ .Level }}>
{{- /* Drop trailing newlines */ -}}
toc.html, and sidebar.html to apply the transliteration to the links.
Modifications to render-heading are confined to in-page anchors and do not extend to the Table of Contents (TOC) or sidebar.
It feels like there should be a more elegant solution, and I'm hoping someone can point me in the right direction.
Using theme version 0.9.7, if that matters.
The github-ascii option for autoHeadingIDType in hugo.yml is not suitable for me, as it results in characters being lost.