From 576fe6ffd0bd62fe2873a0bc5429483cd0f2b630 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Mon, 24 Mar 2025 13:47:08 +0800 Subject: feat: show card reference link --- assets/css/components/_card.scss | 13 ++++++++++ ...\344\272\272\345\221\250\345\210\212-vol-21.md" | 2 ++ layouts/cards/single.html | 28 ++++++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/assets/css/components/_card.scss b/assets/css/components/_card.scss index de04feac..3735c861 100644 --- a/assets/css/components/_card.scss +++ b/assets/css/components/_card.scss @@ -53,3 +53,16 @@ } } } + +.card-page { + .referenced-articles { + h2 { + font-size: 1.2rem; + color: var(--secondary-text-color); + margin: 0; + } + ul { + margin: 0 + } + } +} diff --git "a/content/posts/\347\250\273\350\215\211\344\272\272\345\221\250\345\210\212-vol-21.md" "b/content/posts/\347\250\273\350\215\211\344\272\272\345\221\250\345\210\212-vol-21.md" index 392c9a2c..1345a54d 100644 --- "a/content/posts/\347\250\273\350\215\211\344\272\272\345\221\250\345\210\212-vol-21.md" +++ "b/content/posts/\347\250\273\350\215\211\344\272\272\345\221\250\345\210\212-vol-21.md" @@ -8,6 +8,8 @@ tags: - 设计 - 时间管理 - 生物学 +related_cards: + - anthropomorphic date: 2025-03-24 13:23:21 categories: 稻草人周刊 banner: https://image.guhub.cn/uPic/2025/03/blurry-flower-field.jpeg diff --git a/layouts/cards/single.html b/layouts/cards/single.html index b80f46c1..0651c511 100644 --- a/layouts/cards/single.html +++ b/layouts/cards/single.html @@ -4,8 +4,8 @@ id="article" > {{ partial "components/breadcrumbs.html" . }} -
-
+
+

{{ .Title }}

@@ -21,6 +21,30 @@ {{ .Content }}
+ + {{- /* 查询引用了这个卡片的文章 */ -}} + {{- $currentCard := .File.BaseFileName -}} + {{- $referencedBy := slice -}} + + {{- range .Site.Pages }} + {{- if and (isset .Params "related_cards") (in .Params.related_cards $currentCard) }} + {{- $referencedBy = $referencedBy | append . }} + {{- end }} + {{- end }} + + {{- /* 如果有文章引用这个卡片,就显示它们 */ -}} + {{ if gt (len $referencedBy) 0 }} +
+

引用了本卡片的文章

+
    + {{- range $referencedBy }} +
  • + {{ .Title }} +
  • + {{- end }} +
+
+ {{ end }}
{{ partial "snippets/document-end.html" . }} -- cgit v1.2.3