Render Markdown
To render markdown content, we’ll use the remark
library. First, let’s install it:
Then, open lib/posts.js
and add the following imports to the top of the file:
And update the getPostData()
function in the same file as follows to use remark
:
Important: We added the
async
keyword togetPostData
because we need to useawait
forremark
.async
/await
allow you to fetch data asynchronously.
That means we need to update getStaticProps
in pages/posts/[id].js
to use await
when calling getPostData
:
Finally, update the Post
component in pages/posts/[id].js
to render contentHtml
using dangerouslySetInnerHTML
:
Try visiting these pages again:
You should now see the blog content:
We’re almost done! Let’s polish each page next.