|
| 1 | +# Docusaurus GitHub Pages Configuration Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Configure Docusaurus for GitHub Pages deployment by updating `docusaurus.config.ts` with the appropriate settings for the deployment target. |
| 6 | + |
| 7 | +## Configuration Template |
| 8 | + |
| 9 | +Update the Docusaurus config file (`docusaurus.config.ts`) with GitHub Pages-specific settings: |
| 10 | + |
| 11 | +```typescript |
| 12 | +const config: Config = { |
| 13 | + title: 'Your Documentation Title', |
| 14 | + tagline: 'Documentation description', |
| 15 | + favicon: 'img/favicon.ico', |
| 16 | + |
| 17 | + // GitHub Pages configuration |
| 18 | + url: 'https://username.github.io', // or 'https://username.github.io/repo-name' for project repos |
| 19 | + baseUrl: '/', // or '/<repository-name>/' for project repos |
| 20 | + organizationName: 'your-github-org-or-username', |
| 21 | + projectName: 'your-repository-name', |
| 22 | + deploymentBranch: 'gh-pages', // The branch GitHub Pages will serve from |
| 23 | + trailingSlash: false, |
| 24 | + |
| 25 | + // ... rest of configuration |
| 26 | +}; |
| 27 | +``` |
| 28 | + |
| 29 | +## Configuration Guidelines by Deployment Type |
| 30 | + |
| 31 | +### User/Organization Pages |
| 32 | + |
| 33 | +For repositories named `username.github.io` or `orgname.github.io`: |
| 34 | + |
| 35 | +```typescript |
| 36 | +const config: Config = { |
| 37 | + url: 'https://username.github.io', |
| 38 | + baseUrl: '/', |
| 39 | + organizationName: 'username', |
| 40 | + projectName: 'username.github.io', |
| 41 | + deploymentBranch: 'main', // or 'master' |
| 42 | + // ... rest of config |
| 43 | +}; |
| 44 | +``` |
| 45 | + |
| 46 | +**Key Points:** |
| 47 | +- `baseUrl` is `/` (at root) |
| 48 | +- `projectName` matches the repository name exactly |
| 49 | +- Can deploy from `main`, `master`, or `gh-pages` branch |
| 50 | + |
| 51 | +### Project Pages |
| 52 | + |
| 53 | +For repositories with separate names (e.g., `my-docs`, `documentation`, `agentic-ai`): |
| 54 | + |
| 55 | +```typescript |
| 56 | +const config: Config = { |
| 57 | + url: 'https://username.github.io/repo-name', |
| 58 | + baseUrl: '/repo-name/', |
| 59 | + organizationName: 'username', |
| 60 | + projectName: 'repo-name', |
| 61 | + deploymentBranch: 'gh-pages', |
| 62 | + // ... rest of config |
| 63 | +}; |
| 64 | +``` |
| 65 | + |
| 66 | +**Key Points:** |
| 67 | +- `baseUrl` includes the repository name with trailing slash: `/repo-name/` |
| 68 | +- `projectName` matches the repository name exactly |
| 69 | +- Always use `gh-pages` as deployment branch for project repositories |
| 70 | + |
| 71 | +## Project Analysis Checklist |
| 72 | + |
| 73 | +Before updating configuration, verify: |
| 74 | + |
| 75 | +- **Docusaurus configuration file exists**: `docusaurus.config.ts` or `docusaurus.config.js` |
| 76 | +- **Sidebar configuration is present**: `sidebars.js` or `sidebars.ts` |
| 77 | +- **Package.json specifies correct Node.js version**: Check `engines.node` field (typically v20+) |
| 78 | +- **All required dependencies are listed**: Including `@docusaurus/core`, `@docusaurus/preset-classic`, etc. |
| 79 | + |
| 80 | +## Configuration Best Practices |
| 81 | + |
| 82 | +### URL Configuration |
| 83 | +- **User/Organization Pages**: `url` = `https://username.github.io`, `baseUrl` = `/`, `projectName` = `username.github.io` |
| 84 | +- **Project Pages**: `url` = `https://username.github.io/repo-name`, `baseUrl` = `/repo-name/`, `projectName` = `repo-name` |
| 85 | + |
| 86 | +### Deployment Settings |
| 87 | +- Always use `gh-pages` as the deployment branch for project repositories |
| 88 | +- For user/organization pages, can use `main` or `master` branch |
| 89 | +- Ensure TypeScript configuration includes `typescript` in devDependencies |
| 90 | + |
| 91 | +### File Organization |
| 92 | +- Ensure Docusaurus config is at the root of the docs subdirectory (e.g., `website/docusaurus.config.ts`) |
| 93 | +- Verify `sidebars.ts` exists and properly references all documentation files |
| 94 | +- Check that documentation files follow naming conventions (kebab-case for files) |
| 95 | + |
| 96 | +## Common Configuration Issues |
| 97 | + |
| 98 | +### Incorrect baseUrl |
| 99 | + |
| 100 | +**Problem**: Site deploys but shows 404 or broken links |
| 101 | + |
| 102 | +**Solution**: Verify baseUrl matches deployment target: |
| 103 | +- For `https://username.github.io/repo-name`: baseUrl should be `/repo-name/` |
| 104 | +- For `https://username.github.io`: baseUrl should be `/` |
| 105 | + |
| 106 | +### Type Errors in docusaurus.config.ts |
| 107 | + |
| 108 | +**Problem**: TypeScript errors prevent build |
| 109 | + |
| 110 | +**Solution**: |
| 111 | +1. Verify all imported types are properly declared |
| 112 | +2. Check Config type definition: `import type { Config } from "@docusaurus/types"` |
| 113 | +3. Ensure all config properties match the current Docusaurus version |
| 114 | +4. Run `npm run typecheck` to identify specific errors |
| 115 | + |
| 116 | +### Plugin Incompatibilities |
| 117 | + |
| 118 | +**Problem**: Plugin conflicts or version mismatches |
| 119 | + |
| 120 | +**Solution**: |
| 121 | +1. Verify plugin versions match installed Docusaurus version |
| 122 | +2. Check plugin documentation for configuration requirements |
| 123 | +3. Review error messages for plugin-specific issues |
| 124 | +4. Update plugins to compatible versions if needed |
| 125 | + |
| 126 | +## Customization Examples |
| 127 | + |
| 128 | +### Adding Custom Domain |
| 129 | + |
| 130 | +To use a custom domain instead of `username.github.io/repo-name`: |
| 131 | + |
| 132 | +1. Update config: |
| 133 | +```typescript |
| 134 | +const config: Config = { |
| 135 | + url: 'https://your-custom-domain.com', |
| 136 | + baseUrl: '/', |
| 137 | + // ... rest of config |
| 138 | +}; |
| 139 | +``` |
| 140 | + |
| 141 | +2. Add CNAME file in static directory: `static/CNAME` |
| 142 | +3. Configure custom domain in GitHub repository settings |
| 143 | + |
| 144 | +### Modifying Preset Options |
| 145 | + |
| 146 | +Customize the classic preset in `docusaurus.config.ts`: |
| 147 | + |
| 148 | +```typescript |
| 149 | +presets: [ |
| 150 | + [ |
| 151 | + 'classic', |
| 152 | + { |
| 153 | + docs: { |
| 154 | + sidebarPath: './sidebars.ts', |
| 155 | + editUrl: 'https://github.com/username/repo/tree/main/docs/', |
| 156 | + }, |
| 157 | + blog: { |
| 158 | + showReadingTime: true, |
| 159 | + }, |
| 160 | + theme: { |
| 161 | + customCss: './src/css/custom.css', |
| 162 | + }, |
| 163 | + } satisfies Preset.Options, |
| 164 | + ], |
| 165 | +], |
| 166 | +``` |
| 167 | + |
| 168 | +## Verification Checklist |
| 169 | + |
| 170 | +After updating configuration: |
| 171 | + |
| 172 | +- [ ] `docusaurus.config.ts` is valid TypeScript (no type errors) |
| 173 | +- [ ] `url` and `baseUrl` match your GitHub Pages deployment target |
| 174 | +- [ ] `organizationName` and `projectName` are correct |
| 175 | +- [ ] `deploymentBranch` is set to appropriate branch ('gh-pages' for projects, 'main'/'master' for user pages) |
| 176 | +- [ ] `trailingSlash` is set to false for consistency |
| 177 | +- [ ] `npm run typecheck` passes with no errors |
| 178 | +- [ ] `npm run build` completes successfully |
0 commit comments