diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-24 13:47:08 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-24 13:47:08 +0800 |
| commit | 576fe6ffd0bd62fe2873a0bc5429483cd0f2b630 (patch) | |
| tree | d606a15415324826d30bbf01b783560df5d55166 | |
| parent | 140d1f5faf99b645d80e4eab8338536a7a2b2fa3 (diff) | |
feat: show card reference link
| -rw-r--r-- | assets/css/components/_card.scss | 13 | ||||
| -rw-r--r-- | content/posts/稻草人周刊-vol-21.md | 2 | ||||
| -rw-r--r-- | 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/稻草人周刊-vol-21.md b/content/posts/稻草人周刊-vol-21.md index 392c9a2c..1345a54d 100644 --- a/content/posts/稻草人周刊-vol-21.md +++ b/content/posts/稻草人周刊-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" . }} - <div id="post-content" class="post-content markdown-body"> - <div class="card"> + <div id="post-content" class="post-content"> + <div class="card markdown-body"> <a href="{{ .Permalink }}" class="card-corner"></a> <!-- 右上角折角 --> <div class="card-header"> <h3 class="card-title">{{ .Title }}</h3> @@ -21,6 +21,30 @@ {{ .Content }} </div> </div> + + {{- /* 查询引用了这个卡片的文章 */ -}} + {{- $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 }} + <section class="referenced-articles"> + <h2>引用了本卡片的文章</h2> + <ul> + {{- range $referencedBy }} + <li> + <a href="{{ .Permalink }}">{{ .Title }}</a> + </li> + {{- end }} + </ul> + </section> + {{ end }} </div> </article> {{ partial "snippets/document-end.html" . }} |
