This is a preview of my original post cross-posted from my website's blog
Gatsby is a static site generator that is built on ReactJS. In its simplest definition, a static website is a group of HTML pages, which does not pull any data from a database when a viewer visits it. A static site looks the same for every visitor. Static sites are faster to load too, as the server sends the same response to every visitor. However, you can not customize content for visitors. Since Gatsby builds on top of React, you get all the benefits of React such as its performance, components, JSX, React library ecosystem and a large community. Gatsby Documentation is also very well written so you should not have any problems.
For many static websites, you will need to use external data sources during the build process. Gatsby provides support for many forms of data, including CMSs like WordPress, APIs, and Markdown. To access this data, Gatsby uses GraphQL.
If you know GraphQL, accessing data from Markdown using Gatsby feels easy. If GraphQL is new to you, it does add yet another thing to learn, however, the documentation on using GraphQL with Gatsby has a lot of information.
Note: GraphQL is a query language.
To create a blog with gatsby js, we need to do a couple of steps. Let's see in the example below.
npm install -g gatsby-cli
gatsby new gatsby-site
After the four steps, your gatsby site will be ready, you can access the gatsby development environment at
src/pages and the changes will be reloaded automatically in the browser.
With the build command, Gatsby will perform production build for your site, which in other words means generating static HTML pages.
Lastly, with the shell command, Gatsby will start local HTML server for testing your build site
With the Gatsby site installed you will get the default project structure, which is very simple with a couple of important config files to remember.
|-- /.cache |-- /plugins |-- /public |-- /src |-- /pages |-- /templates |-- html.js |-- /static |-- gatsby-config.js |-- gatsby-node.js |-- gatsby-ssr.js |-- gatsby-browser.js
Gatsby js project structure
There are four important files for gatsby site:
- gatsby-config.js - configure options for Gatsby with metadata like title, description, etc.
- gatsby-node.js - Gatsby Node.js API for customizing the default settings about the build process.
- gatsby-browser.js - Gatsby browser API for customizing the default settings for the browser.
- gatsby-ssr.js - Gatsby server-side rendering API for customizing the settings affecting server-side rendering.
You can read the rest of the post on my website's blog