Back to writing

Deploying a Gatsby Site on GitHub Pages

See how BrightBytes turns MDX and React into a static blog, then preview, build, and publish it with Gatsby.

Illustration of a code window connected through a Git repository to a published blog.

BrightBytes is a Gatsby blog built from MDX articles and React components. GitHub Pages serves the generated HTML, scripts, and images, so reading the site does not require an application server.

The BrightBytes home page with its navigation, workbench illustration, and article feed.
The local BrightBytes development site. Draft articles are visible in this preview.

Architecture

MDX articles and React components become static Gatsby output, which is published to GitHub Pages.
  • MDX files contain article text, frontmatter, code examples, and local images.
  • React templates provide article pages, topic lists, search, and series navigation.
  • Gatsby resolves content and generates responsive images and static pages.
  • GitHub Pages hosts the resulting public/ directory.

Drafts appear during development and are excluded from the production article pages, feeds, search, and sitemap.

Run and build

From the BrightBytes checkout, use the repository's supported Node.js version:

bash
npm ci
npm run develop

Open the local URL printed by Gatsby. To add an article, create src/blog/<name>/index.mdx with a title, description, unique slug, date, tags, and any local images. Set draft: true while writing.

Stop the development server before producing the release build:

bash
npm run build
npm run check:build
npm run serve

The final command previews the generated site locally.

Publish it

The repository's deployment script builds with path-prefix support, checks the output, and sends public/ to the gh-pages branch:

npm run deploy

Configure GitHub Pages to serve that branch. Keep the site URL and path prefix aligned with the destination. For a custom domain, configure DNS and keep the domain in static/CNAME, which Gatsby copies into the build.

Where it fits

This setup works well for technical writing, project portfolios, and documentation that can be generated ahead of time. MDX keeps the article close to its code examples and images; reusable templates keep the presentation consistent across posts.

Thanks for reading.

I’m Ahmad Roshanfar, exploring embedded systems, Linux, and the software that brings hardware to life. Found something useful, or have a question? Let’s talk.