From 9a0f0809621af1bf9d00131908d72bb1f46888cd Mon Sep 17 00:00:00 2001 From: David Eisinger Date: Fri, 2 Jun 2023 23:53:47 -0400 Subject: [PATCH] Add backlinks to journal + notes --- themes/v2/layouts/journal/single.html | 1 + themes/v2/layouts/notes/single.html | 1 + themes/v2/layouts/partials/backlinks.html | 27 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 themes/v2/layouts/partials/backlinks.html diff --git a/themes/v2/layouts/journal/single.html b/themes/v2/layouts/journal/single.html index 61d2334..7694593 100644 --- a/themes/v2/layouts/journal/single.html +++ b/themes/v2/layouts/journal/single.html @@ -18,4 +18,5 @@ {{ .Content }} {{- partial "references.html" . -}} + {{- partial "backlinks.html" . -}} {{ end }} diff --git a/themes/v2/layouts/notes/single.html b/themes/v2/layouts/notes/single.html index 303c5b7..0e14d4d 100644 --- a/themes/v2/layouts/notes/single.html +++ b/themes/v2/layouts/notes/single.html @@ -6,4 +6,5 @@ {{ .Content }} {{- partial "references.html" . -}} + {{- partial "backlinks.html" . -}} {{ end }} diff --git a/themes/v2/layouts/partials/backlinks.html b/themes/v2/layouts/partials/backlinks.html new file mode 100644 index 0000000..cefe49b --- /dev/null +++ b/themes/v2/layouts/partials/backlinks.html @@ -0,0 +1,27 @@ +{{ $currlink := .RelPermalink }} +{{ $noslash := substr .RelPermalink 0 -1 }} +{{ $backlinks := slice }} + +{{ range .Site.Pages }} + {{ $found := findRE $noslash .Content 1 }} + + {{ if and ($found) (ne $currlink .RelPermalink) }} + {{ $backlinks = $backlinks | append . }} + {{ end }} +{{ end }} + +{{ with $backlinks }} +
+ +
+

Backlinks

+ + +
+{{ end }}