|
1 | | -import React from 'react'; |
2 | | -import { readdir } from 'fs/promises'; |
| 1 | +import React from "react"; |
| 2 | +import { readdir } from "fs/promises"; |
| 3 | +import { Dirent } from "fs"; |
3 | 4 |
|
4 | 5 | export default async function BlogIndex() { |
5 | 6 | const posts = await getPosts(); |
6 | | - const postsData = await Promise.all( |
7 | | - posts.map(async (post) => await getPostData(post.name)) |
8 | | - ); |
| 7 | + return ( |
| 8 | + <main className="min-h-screen bg-zinc-950"> |
| 9 | + <div className="container mx-auto px-4 py-12 md:py-24"> |
| 10 | + <header className="mb-16 text-center"> |
| 11 | + <h1 className="font-audiowide mb-4 text-4xl font-bold tracking-wider md:text-5xl lg:text-6xl"> |
| 12 | + <span className="bg-gradient-to-r from-purple-500 to-pink-500 bg-clip-text text-transparent"> |
| 13 | + Techno-Critical Essays |
| 14 | + </span> |
| 15 | + </h1> |
| 16 | + <p className="font-noto mx-auto max-w-2xl text-lg text-zinc-400"> |
| 17 | + Exploring the intersections of technology, society, and critical theory |
| 18 | + </p> |
| 19 | + </header> |
9 | 20 |
|
10 | | - return <pre>{JSON.stringify(postsData, null, 2)}</pre>; |
| 21 | + <pre>{JSON.stringify(posts, null, 2)}</pre> |
| 22 | + </div> |
| 23 | + </main> |
| 24 | + ); |
11 | 25 | } |
12 | 26 |
|
13 | 27 | const getPosts = async () => { |
14 | | - const posts = (await readdir('./app/blog', { withFileTypes: true })).filter( |
15 | | - (post) => post.isDirectory() |
16 | | - ); |
| 28 | + const posts = await getContentDirectory("./app/blog"); |
| 29 | + const postData = await Promise.all(posts.map(getPostData)); |
| 30 | + return postData; |
| 31 | +}; |
| 32 | + |
| 33 | +const getContentDirectory = async (contentPath: string) => { |
| 34 | + const posts = (await readdir(contentPath, { withFileTypes: true })).filter((post) => post.isDirectory()); |
17 | 35 | return posts; |
18 | 36 | }; |
19 | 37 |
|
20 | | -const getPostData = async (slug: string) => { |
21 | | - const { frontmatter } = await import(`./${slug}/page.mdx`); |
22 | | - return frontmatter; |
| 38 | +const getPostData = async (post: Dirent) => { |
| 39 | + const { frontmatter }: { frontmatter: FrontMatter } = await import(`./${post.name}/page.mdx`); |
| 40 | + return { ...post, frontmatter }; |
| 41 | +}; |
| 42 | + |
| 43 | +export type FrontMatter = { |
| 44 | + title: string; |
| 45 | + date: string; |
| 46 | + description: string; |
| 47 | + tags: string[]; |
23 | 48 | }; |
0 commit comments