DEV Community

Konstantin
Konstantin

Posted on • Edited on • Originally published at konstantin.io

2 1

Running «Gatsby.js» blog with github pages

There are many tutorials on how to run a gatsby website with github pages, but most if not all of them are focused on how to generate a website for your repository.

Github has a feature where it provides you with ability to host your static website, i.e. «username.github.io» and link a domain name to it.

To do that you can create a repository username.github.io. You can find more info on that here

Now the problem with gatsby and github pages is that the generated resources are not in the root folder of your repository and if you use gh-pages package it will rewrite all your source files when you publish.

To fix that, you need to create a dev branch which will contain all your sources and add deploy script to your package.json that will contain following:

{
  "scripts": {
    "deploy": "gatsby build && gh-pages -d public -b master"
  }
}
Enter fullscreen mode Exit fullscreen mode

So when we run npm run deploy on dev branch gatsby builds sources from dev branch and gh-pages publishes the result to the root folder on master branch.

Custom domain name

If you have already setup a custom domain for github pages, you would notice that there has to be a CNAME file in the root folder of your repository that contains custom domain name.

If we run npm run deploy this file would be deleted by generated website.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay