Created
May 29, 2021 16:39
-
-
Save BrunoQuaresma/b3ed37f9179acc46dc132245ba0f5e0f to your computer and use it in GitHub Desktop.
Next/mdx blog index page
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
export async function getStaticProps() { | |
const postDirectory = path.join(process.cwd(), "src/pages/blog"); | |
const postFilenames = fs | |
.readdirSync(postDirectory) | |
.filter((file) => path.extname(file).toLowerCase() === ".mdx"); | |
const postModules = await Promise.all( | |
postFilenames.map(async (p) => require(`./${p}`)) | |
); | |
return { | |
props: { | |
posts: postModules.map((post) => ({ | |
...post.meta, | |
date: (post.meta.date as Date).toISOString(), | |
})), | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment