This is a preview of my original post cross-posted from my website's blog
What is Gatsby js
To build a blog today has become even more easy with the new JAM Stack (JavaScript, API, and Markup). JAM Stack stands for
A modern architecture - Create fast and secure sites and dynamic apps with JavaScript, APIs, and prerendered Markup, served without web servers.
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.
Building a Blog With Gatsby js
To create a blog with gatsby js, we need to do a couple of steps. Let's see in the example below.
Install the Gatsby CLI
npm install -g gatsby-cli
Create a new site
gatsby new gatsby-site
Change directories into site folder
cd gatsby-site
Start the development server
gatsby develop
After the four steps, your gatsby site will be ready, you can access the gatsby development environment at localhost:8000
by default. You can edit JavaScript pages in the src/pages
and the changes will be reloaded automatically in the browser.
Create a production build
gatsby build
With the build command, Gatsby will perform production build for your site, which in other words means generating static HTML pages.
Serve the production build locally
gatsby serve
Lastly, with the shell command, Gatsby will start local HTML server for testing your build site
Gatsby project structure
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
Top comments (7)
Boooooooo.
You can hit a setting on DEV to give the Google pagerank credit to your blog while keeping the content here.
Hello Aleksandar, is nice to say hello! I'm following your tutorial but I Get this error on my terminal, I tried several fixes but none of them works, so I was wondering if you can give me a hand trying to fix it or at least a first step to do it:
Any help would be very appreciated.
you delete node modules and again to create yarn install or npm install
Static blog, how do you update? A new commit/deploy every time you want to make a new post? Or you have a work around the static state of Netlify?
For now, I update the blog with a new commit/deploy for every new post. But in the future, I might go with something else in terms of updating.
Okay.
If you want you can you my backend nodejs + graphql and sqlite3.
github.com/jgilbertcastro/micro-blog