feat: contextual backlinks (closes #106)
This commit is contained in:
parent
6e6dd4cb0b
commit
cea0f3eb74
7 changed files with 101 additions and 66 deletions
|
@ -7,13 +7,18 @@
|
|||
{{$inbound := index $linkIndex.index.backlinks $curPage}}
|
||||
{{$contentTable := getJSON "/assets/indices/contentIndex.json"}}
|
||||
{{if $inbound}}
|
||||
{{$cleanedInbound := apply (apply $inbound "index" "." "source") "replace" "." " " "-"}}
|
||||
{{- range $cleanedInbound | uniq -}}
|
||||
{{$l := printf "%s%s/" $host .}}
|
||||
{{$backlinks := dict "SENTINEL" "SENTINEL"}}
|
||||
{{range $k, $v := $inbound}}
|
||||
{{$cleanedInbound := replace $v.source " " "-"}}
|
||||
{{$ctx := $v.text}}
|
||||
{{$backlinks = merge $backlinks (dict $cleanedInbound $ctx)}}
|
||||
{{end}}
|
||||
{{- range $lnk, $ctx := $backlinks -}}
|
||||
{{$l := printf "%s%s/" $host $lnk}}
|
||||
{{$l = cond (eq $l "//") "/" $l}}
|
||||
{{with (index $contentTable .)}}
|
||||
{{with (index $contentTable $lnk)}}
|
||||
<li>
|
||||
<a href="{{$l}}">{{index (index . "title")}}</a>
|
||||
<a href="{{$l}}" data-ctx="{{$ctx}}" data-src="{{$lnk}}" class="internal-link">{{index (index . "title")}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
{{ $js := resources.Get "js/popover.js" | resources.Fingerprint "md5" | resources.Minify }}
|
||||
<script src="{{ $js.Permalink }}"></script>
|
||||
<script>
|
||||
initPopover({{strings.TrimRight "/" .Site.BaseURL }})
|
||||
const useContextual = {{ $.Site.Data.config.enableContextualBacklinks }}
|
||||
initPopover({{strings.TrimRight "/" .Site.BaseURL }}, useContextual)
|
||||
</script>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue