How to Create Pages Dynamically in Gatsby

How to Create Pages Dynamically in Gatsby

In this post, we will be looking into how you can create pages programmatically from data (markdown files) in Gatsby. In order to create these pages dynamically from markdown, we will be looking into Gatsby’s Node createPages API

In this post, we will be looking into how you can create pages programmatically from data (markdown files) in Gatsby.

In order to create these pages dynamically from markdown, we will be looking into Gatsby’s Node createPages API.

However, before we can do that, we need to install a couple of plugins that will source and transform markdown file in order for Gatsby to understand the markdown files path and its content, and be able to create those pages.


To create pages we would need to do the following 3 steps to make it happen dynamically.

Installation

By installing the following plugins

npm install --save gatsby-source-filesystem gatsby-transformer-remark

1. Reading markdown files and transform them

We will tell Gatsby about our content path with gatsby-source-filesystem from the filesystem by passing an options object that contains a variable and file path.

In addition, we can transform those markdown files content to HTML and frontmatter metadata to frontmatter by using gatsby-transformer-remark, which will transform those files into edges that contain node type of MarkdownRemark and each frontmatter fields into GraphQL fields that we can query later in our pages/components and map them at build time.

react programming javascript gatsbyjs graphql

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

React Query with GraphQL | react-query graphql

React-Query with GraphQL! You don't need to use Apollo or Relay for grabbing data from a GraphQL API. React-Query is agnostic and you can fetch data from any API. Learn how to do it in this video. I'm using react-query in combination with graphql-request and graphql-tag.

Increase Performance of React Applications Via Array JavaScript Methods

Increase Performance of React Applications Via Array JavaScript Methods. We will create a simple event management application in the react to add, update, and delete an event.

How to use Functional Programming in your React app | React Next

In the past few years, the buzz around functional programming has been growing, but it can be challenging to apply theoretical concepts to everyday work. How can we make the code we work on more functional? What advanced patterns can you use, and why should you do that? And what do React hooks have to do with all this? In this talk we’ll have a look at real-life examples and patterns you can use to make React apps more functional.

JavaScript Date: Building a React Hook For Date Selector

This week, I had to construct a date selector form in React that looks like this. As you can see, the user interface includes the surrounding month and date options in addition to the selected date. This means that I need to not only keep track of the current date, but I also need a way to conveniently figure out how many days are in the selected month.