backlinks: provide optional btext parameter
This commit is contained in:
parent
f56dbfd3a9
commit
76244a73da
2 changed files with 9 additions and 7 deletions
|
@ -3,18 +3,20 @@
|
||||||
{{- $page := . -}}
|
{{- $page := . -}}
|
||||||
{{- $url := "" -}}
|
{{- $url := "" -}}
|
||||||
{{- $anchor := "" -}}
|
{{- $anchor := "" -}}
|
||||||
{{- $title := "" -}}
|
{{- $btext := "" -}}
|
||||||
{{- if reflect.IsMap . -}}
|
{{- if reflect.IsMap . -}}
|
||||||
{{- $anchor = .anchor -}}
|
{{- $anchor = .anchor -}}
|
||||||
{{- $page = .page -}}
|
{{- $page = .page -}}
|
||||||
{{- $title = .title -}}
|
{{- with .btext -}}
|
||||||
|
{{- $btext = printf " (%s)" . -}}
|
||||||
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if ne $anchor "" -}}
|
{{- if ne $anchor "" -}}
|
||||||
{{- $url = printf "%s#%v" $page.Permalink $anchor -}}
|
{{- $url = printf "%s#%v" $page.Permalink $anchor -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- $url = $page.Permalink -}}
|
{{- $url = $page.Permalink -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
<a href="{{ $url }}">{{ or $title $page.Title }}
|
<a href="{{ $url }}">{{ $page.Title }}{{ $btext }}
|
||||||
{{ if $page.Date -}}
|
{{ if $page.Date -}}
|
||||||
<small>{{ $page.Date.Format (i18n "dateFormat") }}</small>
|
<small>{{ $page.Date.Format (i18n "dateFormat") }}</small>
|
||||||
{{- else if $page.Params.Teaser -}}<small>{{ $page.Params.Teaser }}</small>
|
{{- else if $page.Params.Teaser -}}<small>{{ $page.Params.Teaser }}</small>
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
{{- $this.Scratch.Set "linkid" (add $linkid 1) -}}
|
{{- $this.Scratch.Set "linkid" (add $linkid 1) -}}
|
||||||
{{- $pages := where .Site.RegularPages "Params.pageid" "eq" $pid -}}
|
{{- $pages := where .Site.RegularPages "Params.pageid" "eq" $pid -}}
|
||||||
{{- $fragsep := cond (eq $frag "") "" "#" -}}
|
{{- $fragsep := cond (eq $frag "") "" "#" -}}
|
||||||
|
{{- $btext := or (.Get "btext") (printf "%d" $linkid) -}}
|
||||||
|
{{- $anchor := printf "link-%d" $linkid -}}
|
||||||
{{- $inner := .Inner -}}
|
{{- $inner := .Inner -}}
|
||||||
{{- range $pages -}}
|
{{- range $pages -}}
|
||||||
{{- $url := printf "%s%s%s" .Permalink $fragsep $frag -}}
|
{{- $url := printf "%s%s%s" .Permalink $fragsep $frag -}}
|
||||||
{{- $text := or $inner .Title -}}
|
{{- $text := or $inner .Title -}}
|
||||||
{{- $anchor := printf "link-%d" $linkid -}}
|
<a id="{{ $anchor }}"
|
||||||
{{- $title := printf "%s (%d)" $this.Title $linkid -}}
|
|
||||||
<a id="{{ $anchor }}"
|
|
||||||
href="{{ $url }}">{{ $text | markdownify }}</a>
|
href="{{ $url }}">{{ $text | markdownify }}</a>
|
||||||
{{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this "title" $title)) -}}
|
{{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this "btext" $btext)) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue