diff options
author | Nicholas Johnson <mail@nicholasjohnson.ch> | 2024-11-22 00:00:00 +0000 |
---|---|---|
committer | Nicholas Johnson <mail@nicholasjohnson.ch> | 2024-11-22 00:00:00 +0000 |
commit | 1196329333e8633d57e938d697bb60b06c3370e7772e9f79737e87492a2b19f9 (patch) | |
tree | f54b3469182c104c47af5d098d78a8f0da9c1fce6ef47234aa44239daa852ef0 /layouts | |
parent | eb02383d946c397a53758970ade4d9c1451df6f135b400835456d6dd8aa216e3 (diff) | |
download | hugo-theme-journal-1196329333e8633d57e938d697bb60b06c3370e7772e9f79737e87492a2b19f9.tar.gz hugo-theme-journal-1196329333e8633d57e938d697bb60b06c3370e7772e9f79737e87492a2b19f9.zip |
Map ref numbers to their superscripts using dict
This removes the extra iterations over reference numbers caused by using
the replace function.
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/_default/single.gmi | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/layouts/_default/single.gmi b/layouts/_default/single.gmi index a2f517d..7666f8c 100644 --- a/layouts/_default/single.gmi +++ b/layouts/_default/single.gmi @@ -51,19 +51,25 @@ {{ $ref_text := $chunk_ref.text -}} {{/* create superscript of $ref_index */ -}} - {{ $ref_index := replace $ref_index "0" "⁰" -}} - {{ $ref_index = replace $ref_index "1" "¹" -}} - {{ $ref_index = replace $ref_index "2" "²" -}} - {{ $ref_index = replace $ref_index "3" "³" -}} - {{ $ref_index = replace $ref_index "4" "⁴" -}} - {{ $ref_index = replace $ref_index "5" "⁵" -}} - {{ $ref_index = replace $ref_index "6" "⁶" -}} - {{ $ref_index = replace $ref_index "7" "⁷" -}} - {{ $ref_index = replace $ref_index "8" "⁸" -}} - {{ $ref_index = replace $ref_index "9" "⁹" -}} + {{ $superscript_map := dict + "0" "⁰" + "1" "¹" + "2" "²" + "3" "³" + "4" "⁴" + "5" "⁵" + "6" "⁶" + "7" "⁷" + "8" "⁸" + "9" "⁹" + -}} + {{ $ref_superscript := "" -}} + {{ range (split $ref_index "") -}} + {{ $ref_superscript = print $ref_superscript (index $superscript_map .) -}} + {{ end -}} {{/* replace Markdown links with link text and their superscripted reference numbers */ -}} - {{ $rendered_text = replace $rendered_text (index . 0) (print $ref_text $ref_index) 1 -}} + {{ $rendered_text = replace $rendered_text (index . 0) (print $ref_text $ref_superscript) 1 -}} {{ end -}} |