Creating a Markdown Blog

Fix getStaticPaths Function

Now we need to update our getStaticPaths function so that Next.js will build our Markdown files properly.

To do that, replace the getStaticPaths function in pages/post/[slug].js with the following:

export async function getStaticPaths () {
  const markdownFiles = await fsPromises.readdir('data')
  const paths = => {
    const slug = filename.replace(/.md$/, '')
    return {
      params: { slug }

  return {
    fallback: false

Now you can directly visit the following link, and it should work fine:


It's time for a question again.

Add the following code inside the Post page:


So, it'll look like this:

export default function Post ({ post }) {
  return (
      <div className='post'>
        <div className='time'>Published {ms( - post.createdAt, { long: true })} ago</div>
        <div className='content'>
Q: What will be the outcome?

šŸ™ We need your help

We need your help to keep maintain & add new content to this course. Here's how you can support us: