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: about:
@ -20,6 +20,9 @@ articles-in-section:
author: author:
other: Autor other: Autor
backlinks:
other: Verlinkte Seiten
child-articles: child-articles:
other: Untergeordnete Artikel other: Untergeordnete Artikel

View file

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

View file

@ -1,6 +1,10 @@
{{ range . -}} {{ range $idx, $page := . -}}
<li> <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; class="text-decoration-none">{{ .Title }}&nbsp;&nbsp;
{{ if .Date -}} {{ if .Date -}}
<small>{{ .Date.Format (i18n "dateFormat") }}</small> <small>{{ .Date.Format (i18n "dateFormat") }}</small>

View file

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

View file

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