gatsby-tutorials (21 Part Series)
Welcome to part-16 of the series.
As told in the earlier post, this series is based on the learning from this awesome udemy course by John Smilga
In this part we will show the blog pages, when a user clicks on it. For this we will follow the same template approach, which we followed in tour.
So, create a file blog-template.js inside templates folder. And for now put a dummy data, which we are going to replace soon.
Let’s first write our graphql query in Graphiql playground.
Next, open gatsby-node.js and add this new query.
Next, we will loop through the node and create the page.
To, test whether everything is working we need to stop and start gatsby develop in terminal. After that move to any non-existing page in the browser and you can see those pages been created.
Click on any one of them and you will get our dummy text.
Let’s first create the query to show the single blog post in our playground.
Let’s also add the styles in the css folder as single-blog.module.css
Now, we will start to update our blog-template.js. We are using the query which we created in our playground. After that we are de-structuring data which we are receiving. We are right now showing the title and published field in the blog.
So, when we head over to a blog post we can see that it is getting rendered properly.
Let’s also add the author and a link to go back to Blog page.
Now, to display a markdown file which we are getting back in the description field, requires some configuration.
I found this blog, which was helpful me do the setup.
For displaying markdown files, we need to npm install the plugin gatsby-transformer-remark. So, head over to the terminal and stop the gatsby develop and install it.
Next, also add it in the gatsby-config.js file.
Next, move back to your blog-template.js. Here we need to update the query for description a bit to add transformer plugin thing.
Now, start your gatsby develop from the terminal and head over to a blog post after that. You can see the markdown rendered successfully.
This completes part-16 of the series. You can find the code for the same here.
Also, because of the continuous deployment it got successfully pushed to netlify site.