Skip to content

Commit 921b506

Browse files
committed
read from filesystem
1 parent 86f3851 commit 921b506

1 file changed

Lines changed: 37 additions & 12 deletions

File tree

app/blog/page.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,48 @@
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";
34

45
export default async function BlogIndex() {
56
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>
920

10-
return <pre>{JSON.stringify(postsData, null, 2)}</pre>;
21+
<pre>{JSON.stringify(posts, null, 2)}</pre>
22+
</div>
23+
</main>
24+
);
1125
}
1226

1327
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());
1735
return posts;
1836
};
1937

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[];
2348
};

0 commit comments

Comments
 (0)