-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63b5df6
commit 4e9c278
Showing
4 changed files
with
84 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Link from 'next/link'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import matter from 'gray-matter'; | ||
|
||
export default function Blog({ posts }){ | ||
return ( | ||
<div className="max-w-3xl mx-auto px-6 py-12"> | ||
<h1 className="text-5xl font-semibold my-3">Blog</h1> | ||
<ul> | ||
{posts.map(post => ( | ||
<li key={post.id}> | ||
<Link href={`/blog/${post.id}`}> | ||
<h2 className="text-2xl font-bold">{post.title}</h2> | ||
<p className="text-gray-600">{post.date}</p> | ||
<p>{post.summary}</p> | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export const getStaticProps = async () => { | ||
const postsDirectory = path.join(process.cwd(), 'posts'); | ||
const filenames = fs.readdirSync(postsDirectory); | ||
|
||
const posts = filenames.map(filename => { | ||
const id = filename.replace(/\.md$/, ''); | ||
const fullPath = path.join(postsDirectory, filename); | ||
const fileContents = fs.readFileSync(fullPath, 'utf8'); | ||
const { data: frontMatter } = matter(fileContents); | ||
|
||
return { | ||
id, | ||
...frontMatter, | ||
}; | ||
}); | ||
|
||
return { | ||
props: { | ||
posts, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters