allow slice of map as input to list-item partial

This commit is contained in:
Helmut Merz 2022-01-08 17:11:57 +01:00
parent 7729d0a132
commit dcdd716553
2 changed files with 23 additions and 13 deletions

View file

@ -1,15 +1,23 @@
{{ range $idx, $page := . -}}
{{ range . -}}
<li>
{{- $url := .Permalink -}}
{{- if eq (printf "%T" $idx) "string" -}}
{{- $url = printf "%s#%v" .Permalink $idx -}}
{{- end -}}
{{- $page := . -}}
{{- $url := "" -}}
{{- $anchor := "" -}}
{{- if reflect.IsMap . -}}
{{- $anchor = .anchor}}
{{- $page = .page}}
{{- end -}}
{{- if ne $anchor "" -}}
{{- $url = printf "%s#%v" $page.Permalink $anchor -}}
{{- else -}}
{{- $url = $page.Permalink -}}
{{- end -}}
<a href="{{ $url }}"
class="text-decoration-none">{{ .Title }}&nbsp;&nbsp;
{{ if .Date -}}
<small>{{ .Date.Format (i18n "dateFormat") }}</small>
{{- else if .Params.Teaser -}}<small>{{ .Params.Teaser }}</small>
{{- else -}}<small>{{ .Summary }}</small>
class="text-decoration-none">{{ $page.Title }}&nbsp;&nbsp;
{{ if $page.Date -}}
<small>{{ $page.Date.Format (i18n "dateFormat") }}</small>
{{- else if $page.Params.Teaser -}}<small>{{ $page.Params.Teaser }}</small>
{{- else -}}<small>{{ $page.Summary }}</small>
{{- end }}
</a>
</li>

View file

@ -1,5 +1,6 @@
{{- $this := $.Page -}}
{{- $pages := where .Site.RegularPages "Params.pageid" "eq" (.Get "pid") -}}
{{- $pid := or (.Get "pid") (.Get "pageid") -}}
{{- $pages := where .Site.RegularPages "Params.pageid" "eq" $pid -}}
{{- $frag := .Get "id" -}}
{{- $fragsep := "" -}}
{{- if ne $frag "" -}}{{- $fragsep = "#" -}}{{- end -}}
@ -7,7 +8,8 @@
{{- range $pages -}}
{{- $url := printf "%s%s%s" .Permalink $fragsep $frag -}}
{{- $text := or $inner .Title -}}
<a id="{{ $text | anchorize }}"
{{- $anchor := $text | anchorize -}}
<a id="{{ $anchor }}"
href="{{ $url }}">{{ $text | markdownify }}</a>
{{- .Scratch.SetInMap "backlinks" (anchorize $text) $this -}}
{{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this)) -}}
{{- end -}}