Polishing the Post Page
Adding title
to the Post Page
In pages/posts/[id].js
, let’s add the title
tag using the post data. You'll need to add an import for next/head
at the top of the file and add the title
tag by updating the Post
component:
Formatting the Date
To format the date, we’ll use the date-fns
library. First, install it:
Next, create a file called components/date.js
and add the following Date
component:
Note: You can view the different
format()
string options on the date-fns website.
Now, open pages/posts/[id].js
, add an import for the Date
component at the top of the file, and use it over {postData.date}
:
If you access http://localhost:3000/posts/pre-rendering, you should now see the date written as "January 1, 2020".
Adding CSS
Finally, let’s add some CSS using the file styles/utils.module.css
we added before. Open pages/posts/[id].js
, then add an import for the CSS file, and replace the Post
component with the following code:
If you access http://localhost:3000/posts/pre-rendering, the page should now look a little better:
Great work! We’ll polish the index page next and we’ll be done!