From 76244a73da361e609c6d8878fac344c3f4fe34f1 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 14 Jul 2023 09:02:04 +0200 Subject: [PATCH] backlinks: provide optional btext parameter --- layouts/partials/list-item.html | 8 +++++--- layouts/shortcodes/ilink.html | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/layouts/partials/list-item.html b/layouts/partials/list-item.html index 1c15ce1..d11de21 100644 --- a/layouts/partials/list-item.html +++ b/layouts/partials/list-item.html @@ -3,18 +3,20 @@ {{- $page := . -}} {{- $url := "" -}} {{- $anchor := "" -}} - {{- $title := "" -}} + {{- $btext := "" -}} {{- if reflect.IsMap . -}} {{- $anchor = .anchor -}} {{- $page = .page -}} - {{- $title = .title -}} + {{- with .btext -}} + {{- $btext = printf " (%s)" . -}} + {{- end -}} {{- end -}} {{- if ne $anchor "" -}} {{- $url = printf "%s#%v" $page.Permalink $anchor -}} {{- else -}} {{- $url = $page.Permalink -}} {{- end -}} - {{ or $title $page.Title }}   + {{ $page.Title }}{{ $btext }}   {{ if $page.Date -}} {{ $page.Date.Format (i18n "dateFormat") }} {{- else if $page.Params.Teaser -}}{{ $page.Params.Teaser }} diff --git a/layouts/shortcodes/ilink.html b/layouts/shortcodes/ilink.html index 09b986a..3ee426c 100644 --- a/layouts/shortcodes/ilink.html +++ b/layouts/shortcodes/ilink.html @@ -5,13 +5,13 @@ {{- $this.Scratch.Set "linkid" (add $linkid 1) -}} {{- $pages := where .Site.RegularPages "Params.pageid" "eq" $pid -}} {{- $fragsep := cond (eq $frag "") "" "#" -}} +{{- $btext := or (.Get "btext") (printf "%d" $linkid) -}} +{{- $anchor := printf "link-%d" $linkid -}} {{- $inner := .Inner -}} {{- range $pages -}} {{- $url := printf "%s%s%s" .Permalink $fragsep $frag -}} {{- $text := or $inner .Title -}} - {{- $anchor := printf "link-%d" $linkid -}} - {{- $title := printf "%s (%d)" $this.Title $linkid -}} - {{ $text | markdownify }} - {{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this "title" $title)) -}} + {{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this "btext" $btext)) -}} {{- end -}}