summaryrefslogtreecommitdiff
path: root/layouts/_partials/components/backlinks.html
blob: e97c295cd9c50ef75cc9a2f9fb036b22d8f96377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 }}