Skip to content

Commit 128b53d

Browse files
feat: display post tags
1 parent c55dc43 commit 128b53d

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

components/ArticleBlock.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React from "react";
22
import { format } from "date-fns";
33
import Link from "next/link";
44
import { CalendarIcon } from "./icons/CalendarIcon";
5+
import { Tag } from "@components/Tag";
56

67
interface ArticleBlockProps {
78
slug: string;
89
title: string;
910
description?: string;
1011
date: string;
11-
tags?: string[];
12+
tags: string[];
1213
}
1314

1415
export default function ArticleBlock({
@@ -25,8 +26,17 @@ export default function ArticleBlock({
2526
<h2>{title}</h2>
2627
</Link>
2728
<p>{description}</p>
28-
<span className="art-date"><CalendarIcon/>{formattedDate}</span>
29-
29+
{tags.length != 0 ? (
30+
<div className="tags">
31+
{tags?.map((tag) => (
32+
<Tag>{tag}</Tag>
33+
))}
34+
</div>
35+
) : null}
36+
<span className="art-date">
37+
<CalendarIcon />
38+
{formattedDate}
39+
</span>
3040
</article>
3141
);
3242
}

components/Tag.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Link from "next/link";
2+
import { slug } from "github-slugger";
3+
4+
interface TagProps {
5+
children: string;
6+
}
7+
export function Tag({ children }: TagProps) {
8+
return <span className="tag">{children}</span>;
9+
}

styles/components/_index.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
@forward "toc-links";
88
@forward "info-box";
99
@forward "recipe-info";
10-
@forward "article-block";
10+
@forward "article-block";
11+
@forward "tag";

styles/components/_tag.scss

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@use "../abstracts" as *;
2+
3+
.tags {
4+
display: flex;
5+
flex-wrap: wrap;
6+
gap: 0.5rem;
7+
}
8+
9+
.tag {
10+
cursor: pointer;
11+
font-family: $font-bold;
12+
font-size: 0.8rem;
13+
display: inline-block;
14+
padding: 0.25em 0.8em;
15+
border-radius: 0.7em;
16+
background-color: var(--collapsible-bg);
17+
18+
&:hover {
19+
background-color: var(--collapsible-summary-bg);
20+
}
21+
}

velite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const posts = defineCollection({
6464
description: s.string().max(200).optional(),
6565
date: s.isodate(),
6666
published: s.boolean().default(true),
67-
tags: s.array(s.string()).optional(),
67+
tags: s.array(s.string()).default([]),
6868
body: s.mdx(),
6969
})
7070
.transform(postComputedFields),

0 commit comments

Comments
 (0)