show backlinks to ilink shortcodes (if showBacklinks site param is set

This commit is contained in:
Helmut Merz 2022-01-08 11:33:13 +01:00
parent a894b5f70d
commit 7729d0a132
5 changed files with 24 additions and 9 deletions

View file

@ -1,5 +1,5 @@
#
# de.yaml 2022-01-06
# de.yaml 2022-01-08
#
about:
@ -20,6 +20,9 @@ articles-in-section:
author:
other: Autor
backlinks:
other: Verlinkte Seiten
child-articles:
other: Untergeordnete Artikel

View file

@ -1,5 +1,5 @@
#
# en.yaml 2022-01-06
# en.yaml 2022-01-08
#
about:
@ -20,6 +20,9 @@ articles-in-section:
author:
other: Author
backlinks:
other: Backlinks
child-articles:
other: Child Articles

View file

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

View file

@ -69,6 +69,12 @@
(dict "related" $related "header" $header "id" "articles-in-section") -}}
{{- end }}
{{ if .Site.Params.showBacklinks -}}
{{- $related := .Scratch.Get "backlinks" -}}
{{- partial "card-related"
(dict "related" $related "header" (i18n "backlinks") "id" "backlinks") -}}
{{- end }}
{{ if .Params.toc -}}
<div class="card mt-3">
<div class="card-header">

View file

@ -6,9 +6,8 @@
{{- $inner := .Inner -}}
{{- range $pages -}}
{{- $url := printf "%s%s%s" .Permalink $fragsep $frag -}}
<a id="{{ .Params.pageid }}"
anchor="{{ .Params.pageid }}"
href="{{ $url }}">{{ or $inner .Title | markdownify }}</a>
{{- $backlink := printf "%s#%s" $this.Permalink .Params.pageid -}}
{{- .Scratch.Add "backlinks" (slice $this) -}}
{{- $text := or $inner .Title -}}
<a id="{{ $text | anchorize }}"
href="{{ $url }}">{{ $text | markdownify }}</a>
{{- .Scratch.SetInMap "backlinks" (anchorize $text) $this -}}
{{- end -}}