Skip to content

Commit 369d557

Browse files
committed
feat: show tag / cat count on post page
(resolve #1189)
1 parent 2f4b3e2 commit 369d557

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

src/layouts/Common.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import LicenceBox from "@/components/licences/LicenceBox.astro";
55
import type { IconName } from "@/scripts/icons";
66
import Icon from "@/components/Icon.astro";
77
import { getEntry } from "astro:content";
8+
import { getCatsInfo, getTagsInfo } from "@/scripts/tags";
89
export interface Props {
910
layoutProps: {
1011
url?: string;
@@ -98,7 +99,7 @@ import { getCatSlug } from "@/scripts/tags";
9899
分类:
99100
{cats.map((cat) => (
100101
<a class="cat" href={`/categories/${getCatSlug(cat)}/`}>
101-
{cat}
102+
{cat} <sup>{getCatsInfo().get(cat)}</sup>
102103
</a>
103104
))}
104105
</div>
@@ -112,7 +113,7 @@ import { getCatSlug } from "@/scripts/tags";
112113
标签:
113114
{tags.map((tag) => (
114115
<a class="tag" href={`/tags/${tag}/`}>
115-
{tag}
116+
{tag} <sup>{getTagsInfo().get(tag)}</sup>
116117
</a>
117118
))}
118119
</div>

src/posts/_dip.typ

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import "/src/docs/html-template.typ": *
2+
#template[
3+
= 第 2 章
4+
#include "/node_modules/buaa-digital-image-processing/chap02/main.typ"
5+
6+
= 第 3 章
7+
#include "/node_modules/buaa-digital-image-processing/chap03/main.typ"
8+
9+
= 第 4 章
10+
// #include "/node_modules/buaa-digital-image-processing/chap04/main.typ"
11+
12+
= 第 10 章
13+
// #include "/node_modules/buaa-digital-image-processing/chap10/main.typ"
14+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: 数字图像处理
3+
date: 2025-06-26T20:16:23.340Z
4+
noscript: true
5+
licence: false
6+
layout: "@/layouts/Default.astro"
7+
tags: []
8+
categories:
9+
- Typst
10+
draft: true
11+
---
12+
13+
import Content from "./_dip.typ"
14+
15+
<Content />

src/posts/npm-universe/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tags:
1111
- Astro
1212
- meme
1313
categories:
14-
- typst
14+
- Typst
1515
---
1616

1717
众所周知,[Typst Universe](https://typst.app/universe/) 是 typst 生态中的三方包 registry。在 2025 年的年中,向大家介绍新一代的 typst 包管理和三方包仓库:NPM Universe。顾名思义,就是使用一个名叫「npm」的命令行工具的 Typst Universe 替代品。

src/scripts/tags.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { getBlogPosts } from "@/scripts/post";
22
const posts = await getBlogPosts();
33

4-
export async function getTagsInfo() {
5-
const tagsInfo = new Map<string, number>();
4+
const tagsInfo = new Map<string, number>();
5+
export function getTagsInfo() {
6+
if (tagsInfo.size > 0) return tagsInfo;
67
posts.map((post) => {
78
if (!post.data.tags) return;
89
if (typeof post.data.tags === "string") {
@@ -15,8 +16,9 @@ export async function getTagsInfo() {
1516
return tagsInfo;
1617
}
1718

19+
const catsInfo = new Map<string, number>();
1820
export function getCatsInfo() {
19-
const catsInfo = new Map<string, number>();
21+
if (catsInfo.size > 0) return catsInfo;
2022
posts.map((post) => {
2123
if (!post.data.categories) return;
2224
if (typeof post.data.categories === "string")

0 commit comments

Comments
 (0)