Skip to content

Commit 0bd01b3

Browse files
author
wutali
committed
Add tag buttons
1 parent a0f61ae commit 0bd01b3

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

src/components/PostList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { PostContent } from "../lib/posts";
33
import PostItem from "./PostItem";
4-
import Tag from "./Tag";
4+
import TagLink from "./TagLink";
55
import Pagination from "./Pagination";
66
import { TagContent } from "../lib/tags";
77

@@ -36,7 +36,7 @@ export default function PostList({ posts, tags, pagination }: Props) {
3636
<ul className={"categories"}>
3737
{tags.map((it, i) => (
3838
<li key={i}>
39-
<Tag tag={it} />
39+
<TagLink tag={it} />
4040
</li>
4141
))}
4242
</ul>

src/components/TagButton.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Link from "next/link";
2+
import { TagContent } from "../lib/tags";
3+
4+
type Props = {
5+
tag: TagContent;
6+
};
7+
export default function TagButton({ tag }: Props) {
8+
return (
9+
<>
10+
<Link href={"/posts/tags/[[...slug]]"} as={`/posts/tags/${tag.slug}`}>
11+
<a>{tag.name}</a>
12+
</Link>
13+
<style jsx>{`
14+
a {
15+
display: inline-block;
16+
border-radius: 3px;
17+
background-color: rgba(21, 132, 125, 0.2);
18+
color: #15847d;
19+
transition: background-color 0.3s ease;
20+
padding: 0.25em 0.5em;
21+
}
22+
a:active,
23+
a:hover {
24+
background-color: rgba(21, 132, 125, 0.4);
25+
}
26+
`}</style>
27+
</>
28+
);
29+
}
File renamed without changes.

src/layouts/index.tsx

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@ import React from "react";
22
import Layout from "../components/Layout";
33
import Date from "../components/Date";
44
import styles from "../../public/styles/content.module.css";
5+
import TagButton from "../components/TagButton";
6+
import { getTag } from "../lib/tags";
57

68
type Props = {
79
title: string;
810
date: string;
11+
tags: string[];
912
};
10-
export default function Index({ title, date }: Props) {
13+
export default function Index({ title, date, tags }: Props) {
1114
return ({ children: content }) => {
1215
return (
1316
<Layout>
1417
<div className={"post"}>
1518
<h1>{title}</h1>
1619
<Date dateString={date} />
1720
<div className={styles.content}>{content}</div>
21+
<ul className={"tag-list"}>
22+
{tags.map((it) => (
23+
<li>
24+
<TagButton tag={getTag(it)} />
25+
</li>
26+
))}
27+
</ul>
1828
</div>
1929
<style jsx>
2030
{`
@@ -23,11 +33,20 @@ export default function Index({ title, date }: Props) {
2333
width: 100%;
2434
margin: 0 auto;
2535
}
26-
2736
h1 {
2837
margin: 0 0 0.5rem;
2938
font-size: 2.25rem;
3039
}
40+
.tag-list {
41+
list-style: none;
42+
text-align: right;
43+
margin: 1.75rem 0 0 0;
44+
padding: 0;
45+
}
46+
.tag-list li {
47+
display: inline-block;
48+
margin-left: 0.5rem;
49+
}
3150
`}
3251
</style>
3352
<style global jsx>

0 commit comments

Comments
 (0)