ilink shortcode: use unique numbers for ids (backlink anchors)
This commit is contained in:
parent
11748e3be8
commit
812c15df93
2 changed files with 5 additions and 3 deletions
|
@ -3,7 +3,7 @@
|
||||||
module:
|
module:
|
||||||
hugoVersion:
|
hugoVersion:
|
||||||
extended: true
|
extended: true
|
||||||
min: 0.91.2
|
min: 0.115.1
|
||||||
|
|
||||||
frontmatter:
|
frontmatter:
|
||||||
date:
|
date:
|
||||||
|
@ -24,6 +24,7 @@ related:
|
||||||
|
|
||||||
# non-standard: escaped JSON lines
|
# non-standard: escaped JSON lines
|
||||||
# with \\n and \\t for import to PostgreSQL jsonb column
|
# with \\n and \\t for import to PostgreSQL jsonb column
|
||||||
|
# see `sql` directory
|
||||||
mediaTypes:
|
mediaTypes:
|
||||||
x-text/ejsonl:
|
x-text/ejsonl:
|
||||||
suffixes:
|
suffixes:
|
||||||
|
@ -35,4 +36,3 @@ outputFormats:
|
||||||
isPlainText: true
|
isPlainText: true
|
||||||
mediaType: x-text/ejsonl
|
mediaType: x-text/ejsonl
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
{{- $pid := or (.Get "pid") (.Get "page") -}}
|
{{- $pid := or (.Get "pid") (.Get "page") -}}
|
||||||
{{- $frag := or (.Get "id") (.Get "anchor") -}}
|
{{- $frag := or (.Get "id") (.Get "anchor") -}}
|
||||||
{{- $this := $.Page -}}
|
{{- $this := $.Page -}}
|
||||||
|
{{- $linkid := or ($this.Scratch.Get "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 "") "" "#" -}}
|
||||||
{{- $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 := $text | anchorize -}}
|
{{- $anchor := printf "link-%d" $linkid -}}
|
||||||
<a id="{{ $anchor }}"
|
<a id="{{ $anchor }}"
|
||||||
href="{{ $url }}">{{ $text | markdownify }}</a>
|
href="{{ $url }}">{{ $text | markdownify }}</a>
|
||||||
{{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this)) -}}
|
{{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this)) -}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue