summaryrefslogtreecommitdiff
path: root/layouts/_partials/components
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-07-27 10:48:59 +0800
committerEltrac <hi@guhub.cn>2025-07-27 10:48:59 +0800
commitdc7d715dc30fd576f65f862ee3f1b0b46b48e690 (patch)
treed756ff19a9e85c387f0497b8eefa6212f12cce9d /layouts/_partials/components
parentefb3baca5a534e40555f379d6d3e6361b8e7cc8b (diff)
refactor: extract backlinks function as a component
Diffstat (limited to 'layouts/_partials/components')
-rw-r--r--layouts/_partials/components/backlinks.html37
1 files changed, 37 insertions, 0 deletions
diff --git a/layouts/_partials/components/backlinks.html b/layouts/_partials/components/backlinks.html
new file mode 100644
index 00000000..e97c295c
--- /dev/null
+++ b/layouts/_partials/components/backlinks.html
@@ -0,0 +1,37 @@
+{{ $type := .type }}
+{{ $filename := .filename }}
+{{ $ctx := .context }}
+{{ $referencedBy := slice }}
+
+{{ if eq $type "library" }}
+ {{ range $ctx.Site.Pages }}
+ {{ if and (isset .Params "mentioned_books") (in .Params.mentioned_books $filename) }}
+ {{ $referencedBy = $referencedBy | append . }}
+ {{ end }}
+ {{ end }}
+{{ else if eq $type "cards" }}
+ {{ range $ctx.Site.Pages }}
+ {{ if and (isset .Params "related_cards") (in .Params.related_cards $filename) }}
+ {{ $referencedBy = $referencedBy | append . }}
+ {{ end }}
+ {{ end }}
+{{ end }}
+
+{{- /* 如果有文章引用这个卡片,就显示它们 */ -}}
+{{ if gt (len $referencedBy) 0 }}
+<section class="related-posts post-content my-5">
+ <h2 class="text-size-base m-0 flex items-center gap-2">
+ <span>反向链接</span>
+ <span class="inline-block bg-blockBg rounded-full px-1 text-secondary cursor-help text-size-sm"
+ data-tooltip="这里列出了引用了该页面的其他文章">?</span>
+ </h2>
+ <ul class="my-4 list-none ps-4">
+ {{- range $referencedBy }}
+ <li class="flex gap-4">
+ <span class="text-secondary">→</span>
+ <a href="{{ .Permalink }}">{{ .Title }}</a>
+ </li>
+ {{- end }}
+ </ul>
+</section>
+{{ end }}