|
| 1 | +# Deploy MkDocs to GitHub Pages - Manual Method |
| 2 | + |
| 3 | +## Step 1: Enable GitHub Pages |
| 4 | +1. Go to your repository on GitHub |
| 5 | +2. Click on **Settings** tab |
| 6 | +3. Scroll down to **Pages** section |
| 7 | +4. Under **Source**, select **Deploy from a branch** |
| 8 | +5. Select **gh-pages** branch and **/(root)** folder |
| 9 | +6. Click **Save** |
| 10 | + |
| 11 | +## Step 2: Build and Deploy Manually |
| 12 | + |
| 13 | +### Option A: Using GitHub Actions (Recommended) |
| 14 | +The workflow file `.github/workflows/deploy-mkdocs.yml` has been created for you. |
| 15 | + |
| 16 | +**To trigger deployment:** |
| 17 | +1. Commit and push the workflow file to your main branch |
| 18 | +2. Go to **Actions** tab in your repository |
| 19 | +3. Click on the **Deploy MkDocs to GitHub Pages** workflow |
| 20 | +4. Click **Run workflow** |
| 21 | + |
| 22 | +### Option B: Manual Deployment Script |
| 23 | + |
| 24 | +Create a deployment script: |
| 25 | + |
| 26 | +```bash |
| 27 | +#!/bin/bash |
| 28 | +# deploy.sh |
| 29 | + |
| 30 | +# Build the site |
| 31 | +mkdocs build |
| 32 | + |
| 33 | +# Create gh-pages branch if it doesn't exist |
| 34 | +git checkout --orphan gh-pages |
| 35 | +git reset --hard |
| 36 | + |
| 37 | +# Copy built site files |
| 38 | +cp -r site/* . |
| 39 | +rm -rf site/ |
| 40 | + |
| 41 | +# Add and commit |
| 42 | +git add . |
| 43 | +git commit -m "Deploy MkDocs site" |
| 44 | + |
| 45 | +# Push to gh-pages branch |
| 46 | +git push origin gh-pages --force |
| 47 | + |
| 48 | +# Go back to main branch |
| 49 | +git checkout main |
| 50 | +``` |
| 51 | + |
| 52 | +Make it executable and run: |
| 53 | +```bash |
| 54 | +chmod +x deploy.sh |
| 55 | +./deploy.sh |
| 56 | +``` |
| 57 | + |
| 58 | +## Step 3: Access Your Site |
| 59 | + |
| 60 | +After deployment, your site will be available at: |
| 61 | +``` |
| 62 | +https://YOUR_USERNAME.github.io/YOUR_REPOSITORY_NAME/ |
| 63 | +``` |
| 64 | + |
| 65 | +For example: |
| 66 | +``` |
| 67 | +https://omchoksi108.github.io/Devoverflow-Backend/ |
| 68 | +``` |
| 69 | + |
| 70 | +## Step 4: Custom Domain (Optional) |
| 71 | + |
| 72 | +To use a custom domain: |
| 73 | +1. Go to repository **Settings** → **Pages** |
| 74 | +2. Under **Custom domain**, enter your domain |
| 75 | +3. Add a `CNAME` file to your `docs/` directory with your domain name |
| 76 | +4. Configure DNS settings with your domain provider |
| 77 | + |
| 78 | +## Troubleshooting |
| 79 | + |
| 80 | +### Site not updating? |
| 81 | +- Wait 2-3 minutes after deployment |
| 82 | +- Check the **Actions** tab for any build errors |
| 83 | +- Clear your browser cache |
| 84 | + |
| 85 | +### Build failing? |
| 86 | +- Check the MkDocs configuration in `mkdocs.yml` |
| 87 | +- Ensure all required dependencies are installed |
| 88 | +- Verify file paths in navigation are correct |
| 89 | + |
| 90 | +### 404 errors? |
| 91 | +- Make sure GitHub Pages is enabled |
| 92 | +- Check that the `gh-pages` branch exists |
| 93 | +- Verify the build output is in the correct location |
0 commit comments