Skip to content

Commit 56e5bc5

Browse files
authored
Merge pull request #29 from ansidev/feature/page-tag
Page: /tags/{slug}
2 parents 8b7967f + 0754c71 commit 56e5bc5

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/assets/scss/_styles.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ a {
1313
}
1414

1515
.badge-default {
16-
@extend %badge;
17-
@apply bg-style-primary text-style-primary-inverted;
16+
@apply text-style-secondary border-b-2 border-dotted border-b-style-primary;
1817
}
1918

2019
.badge-outline {

src/pages/tags/[slug].astro

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
import { getCollection } from 'astro:content'
3+
import kebabCase from 'lodash.kebabcase'
4+
5+
import LeetCodeDifficulty from '@/components/LeetCodeDifficulty.astro'
6+
import PostList from '@/components/post/PostList.astro'
7+
import siteConfig from '@/configs/site'
8+
import AppLayout from '@/layouts/AppLayout.astro'
9+
10+
export async function getStaticPaths() {
11+
const allTags = new Set<string>()
12+
const allPosts = await getCollection(
13+
'leetcode-solutions',
14+
({ data }) => data.tags?.length > 0
15+
)
16+
allPosts.forEach((post) =>
17+
post.data.tags?.forEach((t: string) => allTags.add(t))
18+
)
19+
20+
return Array.from(allTags).map((tag) => {
21+
const slug = kebabCase(tag)
22+
const filteredPosts = allPosts.filter((post) =>
23+
post.data.tags?.includes(tag)
24+
)
25+
26+
return {
27+
params: { slug },
28+
props: {
29+
posts: filteredPosts,
30+
tag,
31+
},
32+
}
33+
})
34+
}
35+
36+
const { tag, posts } = Astro.props
37+
const { title, description, author } = siteConfig
38+
---
39+
40+
<AppLayout
41+
title={`${tag} - ${title}`}
42+
description={description}
43+
author={author.name}
44+
headerCssClasses="max-w-xl px-8"
45+
>
46+
<main class="mx-auto my-4 p-4 max-w-xl text-site-header-text">
47+
<div class="grid grid-flow-col auto-cols-max gap-2 m-4 justify-center">
48+
<h1 class="text-style-primary">
49+
Posts by tag:
50+
<span class="badge-default mx-2">{tag}</span>
51+
</h1>
52+
</div>
53+
<PostList posts={posts} />
54+
</main>
55+
</AppLayout>

0 commit comments

Comments
 (0)