Skip to content

Commit a2c5527

Browse files
committed
feat(page): add page /difficulties/{slug}
1 parent 5c5405b commit a2c5527

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/pages/difficulties/[slug].astro

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

0 commit comments

Comments
 (0)