Deploy to GitHub Pages
Deploy your Specra documentation to GitHub Pages for free static hosting
Deploy to GitHub Pages
GitHub Pages offers free hosting for static sites, making it perfect for open source documentation. Deploy directly from your repository with GitHub Actions.
Why GitHub Pages?
- Free hosting - No cost for public repositories
- Custom domains - Use your own domain
- HTTPS included - Automatic SSL certificates
- Git-based - Deploy from your repository
- Version control - Full history of your docs
- Community trust - Familiar platform for developers
Prerequisites
- GitHub repository (public or private)
- Specra documentation project
- Git installed locally
Configuration
First, configure Specra for static export.
Without Custom Domain
For URLs like username.github.io/repo-name:
1{2 "deployment": {3 "target": "github-pages",4 "basePath": "repo-name",5 "customDomain": false6 }7}With Custom Domain
For custom domains like docs.example.com:
1{2 "deployment": {3 "target": "custom-domain-static",4 "basePath": "",5 "customDomain": true6 }7}Also create public/CNAME with your domain:
1docs.example.comDeployment Methods
Choose your preferred deployment method:
Method 1: GitHub Actions (Recommended)
Automatic deployment on every push to main.
Create Workflow File
1name: Deploy to GitHub Pages2 3on:4 push:5 branches: [main]6 7permissions:8 contents: read9 pages: write10 id-token: write11 12concurrency:13 group: "pages"14 cancel-in-progress: false15 16jobs:17 build:18 runs-on: ubuntu-latest19 steps:20 - name: Checkout21 uses: actions/checkout@v422 23 - name: Setup Node24 uses: actions/setup-node@v425 with:26 node-version: '20'27 cache: 'npm'28 29 - name: Install dependencies30 run: npm ci31 32 - name: Build site33 run: npm run build:export34 env:35 NODE_ENV: production36 37 - name: Upload artifact38 uses: actions/upload-pages-artifact@v339 with:40 path: ./out41 42 deploy:43 needs: build44 runs-on: ubuntu-latest45 environment:46 name: github-pages47 url: ${{ steps.deployment.outputs.page_url }}48 steps:49 - name: Deploy to GitHub Pages50 id: deployment51 uses: actions/deploy-pages@v4Enable GitHub Pages
- Go to repository Settings → Pages
- Source: GitHub Actions
- Save
No need to select a branch - the workflow handles deployment.
Push and Deploy
1git add .2git commit -m "Add GitHub Pages deployment"3git pushYour site deploys automatically! Check the Actions tab for progress.
Method 2: Manual Deployment
Deploy manually using the gh-pages package.
Install gh-pages
1npm install --save-dev gh-pagesAdd Deploy Script
1{2 "scripts": {3 "deploy": "npm run build:export && gh-pages -d out"4 }5}Deploy
1npm run deployThis builds your site and pushes the out folder to the gh-pages branch.
Enable GitHub Pages
- Go to Settings → Pages
- Source: Deploy from a branch
- Branch:
gh-pages// (root) - Save
Custom Domain Setup
Use your own domain with GitHub Pages:
Add CNAME File
docs.example.com
Update config:
1{2 "deployment": {3 "target": "custom-domain-static",4 "customDomain": true,5 "basePath": ""6 }7}Configure DNS
For subdomain (docs.example.com):
Type: CNAME
Name: docs
Value: username.github.io
For apex domain (example.com):
Type: A
Name: @
Value: 185.199.108.153
Value: 185.199.109.153
Value: 185.199.110.153
Value: 185.199.111.153
Enable HTTPS
- Go to Settings → Pages
- Check "Enforce HTTPS"
- GitHub automatically provisions an SSL certificate
Advanced GitHub Actions
With Search Indexing
Index your docs in MeiliSearch during deployment:
1jobs:2 build:3 runs-on: ubuntu-latest4 steps:5 - uses: actions/checkout@v46 7 - name: Setup Node8 uses: actions/setup-node@v49 with:10 node-version: '20'11 cache: 'npm'12 13 - name: Install dependencies14 run: npm ci15 16 - name: Build site17 run: npm run build:export18 19 - name: Index search20 run: npm run index:search21 env:22 MEILISEARCH_HOST: ${{ secrets.MEILISEARCH_HOST }}23 MEILISEARCH_API_KEY: ${{ secrets.MEILISEARCH_MASTER_KEY }}24 25 - name: Upload artifact26 uses: actions/upload-pages-artifact@v327 with:28 path: ./outAdd secrets in Settings → Secrets and variables → Actions.
Deploy on Tag
Only deploy when you create a release tag:
1on:2 push:3 tags:4 - 'v*'Create and push a tag to deploy:
1git tag v1.0.02git push origin v1.0.0Multiple Environments
Deploy different branches to different GitHub Pages sites:
1on:2 push:3 branches:4 - main5 - staging6 7jobs:8 build:9 runs-on: ubuntu-latest10 steps:11 # ... build steps ...12 13 - name: Deploy to production14 if: github.ref == 'refs/heads/main'15 uses: actions/deploy-pages@v416 17 - name: Deploy to staging18 if: github.ref == 'refs/heads/staging'19 # Deploy to a different repo or branchTroubleshooting
404 Errors on Routes
Static exports don't support dynamic routing the same way. Ensure all routes are pre-rendered.
Solution: Add a 404.html that redirects to index:
1<!DOCTYPE html>2<html>3 <head>4 <meta http-equiv="refresh" content="0;url=/" />5 </head>6 <body>7 Redirecting...8 </body>9</html>Assets Not Loading
Check your basePath configuration:
1# View your site2open https://username.github.io/repo-name3 4# Check if assets load from5https://username.github.io/repo-name/_app/immutable/...If assets 404, verify:
basePathin config matches repo name exactly- You're using
npm run build:exportnotnpm run build
Custom Domain Not Working
Check DNS propagation:
1dig docs.example.com2# Should show CNAME to username.github.ioCheck CNAME file:
- Must be in
public/folder - Contains only your domain, no protocol
- No trailing slash
Common issues:
- DNS not propagated yet (wait up to 24 hours)
- CNAME file missing or incorrect
- Domain verification failed in GitHub settings
Build Fails in Actions
View logs:
- Go to Actions tab
- Click the failed workflow
- Expand build step to see errors
Common fixes:
- Increase Node version in workflow
- Clear npm cache:
npm ci --cache .npm - Check for missing dependencies
Performance Tips
Enable Caching
Cache node_modules for faster builds:
1- name: Setup Node2 uses: actions/setup-node@v43 with:4 node-version: '20'5 cache: 'npm'Optimize Images
Pre-optimize images before committing:
1npm install -D imagemin-cli2 3# Optimize all images4npx imagemin public/images/* --out-dir=public/imagesReduce Bundle Size
Check what's in your bundle:
1npm install -D vite-bundle-visualizer2 3ANALYZE=true npm run build:exportLimits
GitHub Pages has some limits:
- Repository size: 1GB recommended
- Site size: 1GB published site
- Bandwidth: 100GB/month soft limit
- Builds: 10 per hour
These limits are generous for documentation sites.
Migration from Other Platforms
From Vercel
- Update
specra.config.jsondeployment section - Run
npm run build:exportlocally to test - Set up GitHub Actions workflow
- Push to trigger deployment
From Netlify
Same process as Vercel. The static output works on both platforms.
Best Practices
Use GitHub Actions - Automatic deployment on every push
Version your docs - Use git tags for documentation versions
Test locally - Run npm run build:export && npx serve out before pushing
Monitor builds - Set up notifications for failed deployments
Use custom domain - Professional appearance and stable URLs
Enable HTTPS - Always enforce HTTPS for security