|
| 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