|
| 1 | +import { CategoriesSelector } from '~/components/Common/CategoriesSelector/index.tsx'; |
| 2 | +import { ArticleCard } from '~/components/Post/ArticleCard/index.tsx'; |
| 3 | +import { getPostsMetadata } from '~/lib/post.ts'; |
| 4 | +import styles from './page.module.css'; |
| 5 | +import type { FC } from 'react'; |
| 6 | + |
| 7 | +type CategoriesParams = { |
| 8 | + categories?: string[]; |
| 9 | +}; |
| 10 | + |
| 11 | +type PageProps = { |
| 12 | + params: Promise<CategoriesParams>; |
| 13 | +}; |
| 14 | + |
| 15 | +/** |
| 16 | + * List of available categories |
| 17 | + */ |
| 18 | +const CATEGORIES = [ |
| 19 | + { |
| 20 | + category: 'All articles', |
| 21 | + slug: '', |
| 22 | + }, |
| 23 | + { |
| 24 | + category: 'Information', |
| 25 | + slug: 'information', |
| 26 | + }, |
| 27 | + { |
| 28 | + category: 'Use cases', |
| 29 | + slug: 'use-cases', |
| 30 | + }, |
| 31 | + { |
| 32 | + category: 'Releases', |
| 33 | + slug: 'releases', |
| 34 | + }, |
| 35 | +]; |
| 36 | + |
| 37 | +export const generateStaticParams = () => { |
| 38 | + const params = [ |
| 39 | + { categories: [] }, // For the base route without any categories |
| 40 | + ...CATEGORIES.slice(1).map(category => ({ categories: [category.slug] })), // For each individual category |
| 41 | + ]; |
| 42 | + |
| 43 | + return params; |
| 44 | +}; |
| 45 | + |
| 46 | +const Page: FC<PageProps> = async ({ params }) => { |
| 47 | + const currentCategories = (await params).categories || []; |
| 48 | + const postsMetadata = await getPostsMetadata(currentCategories[0]); |
| 49 | + |
| 50 | + return ( |
| 51 | + <main className={styles.page}> |
| 52 | + <h1>Article list</h1> |
| 53 | + <p> |
| 54 | + Here you can find all the articles available on the website. You can |
| 55 | + filter them by category using the dropdown below. |
| 56 | + </p> |
| 57 | + <CategoriesSelector |
| 58 | + currentCategories={currentCategories} |
| 59 | + categories={CATEGORIES} |
| 60 | + /> |
| 61 | + {postsMetadata.length === 0 ? ( |
| 62 | + <div className={styles.noArticles}> |
| 63 | + <p>No articles here for now</p> |
| 64 | + </div> |
| 65 | + ) : ( |
| 66 | + <div className={styles.articles}> |
| 67 | + {postsMetadata.map(post => ( |
| 68 | + <ArticleCard key={post.slug} {...post} /> |
| 69 | + ))} |
| 70 | + </div> |
| 71 | + )} |
| 72 | + </main> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +export default Page; |
0 commit comments