GitHub Pages 09 ๐ Static Site Generators & Exports โ Deploying Astro, Hugo, Eleventy, and Next.js (output: ‘export’) with custom workflows
GitHub Pages was originally built around Jekyll, a Ruby-based Static Site Generator (SSG). However, the modern web ecosystem has moved toward more diverse tools like Astro for content-heavy sites, Hugo for speed, and Next.js or Eleventy for highly customizable experiences. While GitHub Pages still supports Jekyll natively, the preferred modern approach is to treat GitHub Pages as a “dumb” static host and use GitHub Actions as the “build server.” This allows you to use any framework or language, as long as it can produce a folder of static HTML, CSS, and JavaScript.
Deploying a modern SSG requires a shift from “pushing code” to “orchestrating a pipeline.” In this model, GitHub Actions handles the installation of dependencies (like Node.js or Go), the execution of the build command, and the final delivery of the resulting artifacts to the GitHub Pages infrastructure. This decoupling is what makes it possible to use frameworks like Next.js, which traditionally require a server, by opting into their “static export” modes.
This chapter explores the specific configuration requirements for the four most popular SSGs used with GitHub Pages. We will look at how to enable static exports in Next.js, how to configure base paths in Astro, and how to utilize specialized GitHub Actions for Hugo and Eleventy. The goal is to provide a unified strategy for taking any source code and transforming it into a production-ready GitHub Pages site.
Key point: To deploy a modern SSG to GitHub Pages, you must disable the internal Jekyll processing (via .nojekyll or the Actions source setting) and ensure your build command generates a completely self-contained static directory.
1. The compilation requirement.
Unlike plain HTML sites, modern frameworks use languages and syntaxes (like JSX, Markdown with MDX, or SASS) that browsers cannot read directly. SSGs exist to “compile” these developer-friendly formats into the standard web formats that GitHub Pages can serve.
2. Framework-specific optimizations.
Next.js and Astro provide built-in image optimization, code splitting, and pre-fetching. These features significantly improve the performance of a static site but require a dedicated build step to generate the optimized assets before they are hosted.
3. Decoupling source from output.
By using an SSG with GitHub Actions, you keep your repository clean. You only store your source code, and GitHub handles the generation of the dist or public folder. This prevents “git bloat” where the repository size grows indefinitely due to repeated commits of large, generated CSS and JS files.
4. Bypassing Jekyll limitations.
The native Jekyll engine on GitHub Pages is restricted for security reasons (e.g., no custom plugins). By building your site via Actions, you can use any plugin, version, or external tool you want, as the server only sees the final HTML result.
5. Unified environment management.
GitHub Actions allows you to inject environment variables (like API keys for a headless CMS) during the build phase. This allows your static site to “fetch” data from external sources and bake it into the HTML at build time, creating a fast, secure, “Jamstack” architecture.
a. Next.js: The output: 'export' Strategy
Next.js is primarily a server-side framework, but it features a powerful “Static Export” mode. To use Next.js on GitHub Pages, you must configure the next.config.js file to output static files instead of a Node.js server bundle.
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export', // Forces Next.js to produce a 'out' folder
basePath: '/my-repo-name', // Required for GitHub Pages sub-paths
images: {
unoptimized: true, // GitHub Pages doesn't support the Next.js image server
},
}
module.exports = nextConfig
The unoptimized: true setting is critical because the default <Image /> component in Next.js requires a running server to resize images on the fly. Since GitHub Pages is strictly static, you must tell Next.js to serve the original images without processing.
b. Astro: The Content-First Framework
Astro is designed for speed and is highly compatible with GitHub Pages. Like Vite-based projects, Astro requires a site and base configuration to correctly handle internal linking and asset loading when not hosted at the root domain.
// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
site: 'https://username.github.io',
base: '/my-repo-name', // The repository name
outDir: './dist',
});
Astroโs build process is straightforward. In your GitHub Actions workflow, you simply run npm install and npm run build. The resulting dist folder is then passed to the upload-pages-artifact action. Astro automatically handles the prefixing of your URLs with the base path you provided.
c. Hugo and Eleventy: The Pure SSGs
Hugo and Eleventy are “pure” in the sense that they were built from the ground up for static generation. Hugo is written in Go and is incredibly fast, while Eleventy (11ty) is a Node-based tool that prides itself on simplicity and “zero-client-side-JS” by default.
For Hugo, you typically use a community action to install the specific version of the Hugo extended binary required for features like SASS processing.
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: 'latest'
extended: true
- name: Build Hugo
run: hugo --minify --baseURL "https://username.github.io/my-repo/"
Eleventy works like most Node projects but defaults to a folder named _site. You must ensure your GitHub Actions upload-pages-artifact points to this specific folder name.
Complete Example Session
# ============================================
# PART 1: UNIFIED SSG DEPLOYMENT WORKFLOW
# ============================================
name: Deploy SSG Site
on:
push:
branches: ["main"]
permissions:
contents: read
pages: write
id-token: write
# ============================================
# PART 2: THE BUILD JOB (Common for Node SSGs)
# ============================================
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# ============================================
# PART 3: SETUP NODE.JS (For Next.js/Astro/11ty)
# ============================================
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: 'npm'
# ============================================
# PART 4: FRAMEWORK BUILD COMMANDS
# ============================================
- name: Install Dependencies
run: npm ci
# Next.js: npm run build (creates 'out')
# Astro: npm run build (creates 'dist')
# 11ty: npx @11ty/eleventy (creates '_site')
- name: Build with Framework
run: npm run build
# ============================================
# PART 5: CONFIGURING BUILD OUTPUT PATH
# ============================================
# This varies by framework!
# Next.js = ./out, Astro = ./dist, 11ty = ./_site
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@v3
with:
path: './out' # Example for Next.js
# ============================================
# PART 6: THE DEPLOY JOB
# ============================================
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# ============================================
# PART 7: HANDLING HUGO (Alternative Flow)
# ============================================
# If using Hugo, replace Part 3 & 4 with peaceiris/actions-hugo
# ============================================
# PART 8: ENVIRONMENT VARIABLES
# ============================================
# Use env: NEXT_PUBLIC_... for client-side keys
# ============================================
# PART 9: SUB-PATH FIXES
# ============================================
# Ensure config files (next.config.js/astro.config.mjs)
# have the 'basePath' or 'base' set correctly.
# ============================================
# PART 10: VERIFICATION
# ============================================
# Check that index.html is in the root of the artifact.
The parts covered the build job for various Node-based SSGs, the selection of the correct output directory, and the final deployment logic using OIDC.
Quick Reference
Framework Output Directories
| Framework | Default Output Folder | Config Flag |
|---|---|---|
| Next.js | out | output: 'export' |
| Astro | dist | outDir: './dist' |
| Eleventy | _site | --output=_site |
| Hugo | public | -d public |
Base Path Configurations
| Framework | File | Key |
|---|---|---|
| Next.js | next.config.js | basePath: '/repo' |
| Astro | astro.config.mjs | base: '/repo' |
| Hugo | config.toml | baseURL = "..." |
| Eleventy | eleventy.config.js | pathPrefix: "/repo/" |
Critical Next.js Settings
| Feature | Requirement |
|---|---|
| Images | unoptimized: true |
| Router | Use Link from next/link |
| Server Components | Supported (Static only) |
Best Practices
โ Do This:
// Use environment variables for the repo name
basePath: process.env.GITHUB_REPOSITORY ? `/${process.env.GITHUB_REPOSITORY.split('/')[1]}` : '', // โ
// Use npm ci instead of npm install in Actions
run: npm ci // โ
// Lock your Node version in the workflow
uses: actions/setup-node@v4
with: { node-version: '20' } // โ
โ Don’t Do This:
// Don't use Next.js 'middleware' (Server required) // โ
// Don't use absolute paths for images (/logo.png) // โ
// Don't forget the .nojekyll file if using folders
// starting with underscores (like _next) // โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Next.js Image Error | Server-side optimization fails | Set unoptimized: true in config |
| Missing CSS/JS | Base path not prefixed | Add basePath to framework config |
| 404 on _next folder | Jekyll hides underscore folders | Use Actions source or add .nojekyll |
| Next.js Link Error | Paths don’t include repo name | Configure basePath in next.config.js |
| Build Timeout | Huge image folders | Optimize images before build or use cache |
Real-World Examples
1. Next.js Static Config
const nextConfig = { output: 'export', basePath: '/docs' };
2. Astro Base URL
export default defineConfig({ base: '/blog' });
3. Hugo Build Action
uses: peaceiris/actions-hugo@v3
4. Eleventy Path Prefix
module.exports = { pathPrefix: "/my-site/" };
5. OIDC Permissions
permissions: { id-token: write, pages: write }
6. Next.js Unoptimized Images
images: { unoptimized: true }
7. Astro Site Meta
site: 'https://example.com'
8. Hugo Extended Binary
with: { extended: true }
9. Node Cache Config
with: { cache: 'npm' }
10. Manual Build Script
"build": "next build && next export" // Legacy Next.js
Visual
The SSG Build Pipeline
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ SOURCE CODE โ โ GITHUB ACTIONS โ โ GITHUB PAGES โ
โ (Next/Astro) โ โ (Build Server) โ โ (Static Host)โ
โโโโโโโโฌโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโฌโโโโโโโโ
โ โ โ
โ 1. Push Code โ โ
โโโโโโโโโโโโโโโโโโโโโโโโบโ โ
โ โ 2. npm ci โ
โ โ 3. npm run build โ
โ โ โ
โ โ 4. Upload Artifact โ
โ โโโโโโโโโโโโโโโโโโโโโโโบโ
โ โ โ
โผ โผ 5. LIVE SITE โผ
Next.js Export Logic
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NEXT.JS SOURCE (App Router) โ
โ /app/page.tsx โโโโบ index.html โ
โ /app/about.tsx โโโโบ about.html โ
โ /public/img.png โโโโบ /_next/static/... โ
โ โ
โ RESULT: A flat 'out' folder that requires no Node server. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Hugo Fast Build Structure
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HUGO DIRECTORY โ
โ content/ โโโโบ Markdown files โ
โ themes/ โโโโบ HTML Templates โ
โ static/ โโโโบ Passed through untouched โ
โ โ
โ OUTPUT: 'public/' (Extremely fast Go-based compilation) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Next.js Requirement | output: 'export' |
| Next.js Image | unoptimized: true |
| Astro Config | site and base |
| Hugo Action | peaceiris/actions-hugo |
| Eleventy Output | _site |
| Auth | OIDC (GitHub Actions) |
| Performance | Jamstack (Pre-built HTML) |
Key takeaways:
- GitHub Actions is your compiler. Use Actions to handle the build step for any SSG, allowing you to use frameworks that GitHub Pages doesn’t support natively.
- Next.js requires special care. You must enable static exports and disable image optimization to make Next.js compatible with a static host.
- Base paths are the #1 cause of failure. If your site is at
username.github.io/repo, ensure your SSG is configured to prefix all asset links with/repo. - Prefer OIDC over Secrets. Use the modern permissions block in your YAML to allow GitHub Actions to deploy to Pages without manual API tokens.
- Optimize locally, build globally. Use your SSG to optimize images and minify code during the build phase so the live site is as fast as possible.
- Check your output directory. Frameworks differ on where they put build files (
out,dist,public). Ensure yourupload-pages-artifactpoints to the right one.
Remember: GitHub Pages doesn’t care which framework you use. It only cares that it receives a valid folder of HTML, CSS, and JS. By mastering the custom workflow and static export settings of your chosen SSG, you can host modern, high-performance web applications for free on GitHub’s infrastructure.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!