From dec9d570fc72eb3035d1a8634bb4cafeda49d7bf2d5fe7017ffa088831214638 Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Tue, 11 Jun 2024 00:00:00 +0000 Subject: Work around slices bug in Hugo v0.114.0 or newer I used a slice of maps instead of a slice of slices, as recommended in the Hugo issue tracking the bug: https://github.com/gohugoio/hugo/issues/11131#issuecomment-1601769489 --- layouts/_default/single.gmi | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/layouts/_default/single.gmi b/layouts/_default/single.gmi index c6b7356..2934781 100644 --- a/layouts/_default/single.gmi +++ b/layouts/_default/single.gmi @@ -36,10 +36,17 @@ {{/* find all the links within a chunk */ -}} {{ $chunk_refs := findRESubmatch `!?\[[\t ]*(.+?)[\t ]*\]\([\t ]*(.+?)(?:[\t ]+"(.+?)")?[\t ]*\)` $rendered_text -}} - {{ $scratch.Add "refs" $chunk_refs -}} {{ range $chunk_refs -}} {{ $ref_index = add $ref_index 1 -}} - {{ $ref_text := index . 1 -}} + {{ $chunk_ref := dict + "text" (index . 1) + "link" (index . 2) + "title" (index . 3) + -}} + + {{ $scratch.Add "refs" (slice $chunk_ref) -}} + + {{ $ref_text := $chunk_ref.text -}} {{/* create superscript of $ref_index */ -}} {{ $ref_index := replace $ref_index "0" "⁰" -}} @@ -106,9 +113,9 @@ ## {{ i18n "refs" }} {{ range $refs -}} {{ $ref_index = add $ref_index 1 -}} - {{ $ref_text := index . 1 -}} - {{ $ref_link := index . 2 -}} - {{ $ref_title := index . 3 -}} + {{ $ref_text := .text -}} + {{ $ref_link := .link -}} + {{ $ref_title := .title -}} {{/* render referenced links */}} {{ print "=> " $ref_link (emojify " :link: [") $ref_index "]: " (cond (ne (len $ref_title) 0) $ref_title $ref_text) | safeHTML -}} -- cgit v1.2.3