|
| 1 | +# GitHub Pages Documentation Generation |
| 2 | + |
| 3 | +A complete solution for generating, validating, and deploying documentation sites to GitHub Pages using MkDocs with the Material theme. |
| 4 | + |
| 5 | +## Philosophy |
| 6 | + |
| 7 | +- **Single responsibility**: Each module handles one concern (generate, validate, deploy) |
| 8 | +- **Standard library when possible**: External deps only where necessary (mkdocs, pyyaml) |
| 9 | +- **Self-contained and regeneratable**: Module can be rebuilt from this specification |
| 10 | +- **Zero-BS**: No stubs, no placeholders - everything works |
| 11 | + |
| 12 | +## Module Structure |
| 13 | + |
| 14 | +``` |
| 15 | +github_pages/ |
| 16 | +├── __init__.py # Public API (dataclasses + function exports) |
| 17 | +├── generator.py # Site generation with MkDocs |
| 18 | +├── validator.py # Three-pass documentation validation |
| 19 | +├── deployer.py # GitHub Pages deployment via gh-pages branch |
| 20 | +├── mkdocs_config.py # MkDocs configuration builder |
| 21 | +├── tests/ # Comprehensive test suite |
| 22 | +│ ├── conftest.py # Shared fixtures |
| 23 | +│ ├── test_generator.py |
| 24 | +│ ├── test_validator.py |
| 25 | +│ ├── test_deployer.py |
| 26 | +│ ├── test_mkdocs_config.py |
| 27 | +│ └── test_integration.py |
| 28 | +└── README.md # This file |
| 29 | +``` |
| 30 | + |
| 31 | +## Public API |
| 32 | + |
| 33 | +### Configuration Dataclasses |
| 34 | + |
| 35 | +```python |
| 36 | +from github_pages import SiteConfig, DeploymentConfig |
| 37 | + |
| 38 | +# Site generation configuration |
| 39 | +site_config = SiteConfig( |
| 40 | + project_name="My Project", |
| 41 | + project_url="https://github.com/user/repo", |
| 42 | + docs_dir="docs", # Default |
| 43 | + output_dir="site", # Default |
| 44 | + theme="material", # Default |
| 45 | + theme_features=None, # Optional custom features |
| 46 | + nav_structure=None, # Optional custom navigation |
| 47 | +) |
| 48 | + |
| 49 | +# Deployment configuration |
| 50 | +deploy_config = DeploymentConfig( |
| 51 | + site_dir="site", |
| 52 | + repo_path=".", # Default |
| 53 | + commit_message="Update docs", # Default |
| 54 | + force_push=False, # Default - NEVER force by default |
| 55 | +) |
| 56 | +``` |
| 57 | + |
| 58 | +### Result Dataclasses |
| 59 | + |
| 60 | +```python |
| 61 | +from github_pages import GenerationResult, ValidationResult, DeploymentResult |
| 62 | + |
| 63 | +# GenerationResult fields: |
| 64 | +# - success: bool |
| 65 | +# - site_dir: Path |
| 66 | +# - pages: list[str] |
| 67 | +# - errors: list[str] |
| 68 | +# - warnings: list[str] |
| 69 | +# - config_file: Path | None |
| 70 | + |
| 71 | +# ValidationResult fields: |
| 72 | +# - passed: bool |
| 73 | +# - issues: list[ValidationIssue] |
| 74 | +# - pass1_coverage: float (target: 100%) |
| 75 | +# - pass2_clarity_score: float (target: >= 80%) |
| 76 | +# - pass3_grounded_pct: float (target: >= 95%) |
| 77 | + |
| 78 | +# DeploymentResult fields: |
| 79 | +# - success: bool |
| 80 | +# - branch: str (always "gh-pages") |
| 81 | +# - commit_sha: str | None |
| 82 | +# - url: str | None (GitHub Pages URL) |
| 83 | +# - errors: list[str] |
| 84 | +``` |
| 85 | + |
| 86 | +### Main Functions |
| 87 | + |
| 88 | +```python |
| 89 | +from github_pages import generate_site, validate_site, deploy_site, preview_locally |
| 90 | + |
| 91 | +# Generate documentation site |
| 92 | +result = generate_site(site_config) |
| 93 | +if not result.success: |
| 94 | + print(f"Generation failed: {result.errors}") |
| 95 | + |
| 96 | +# Validate documentation quality |
| 97 | +validation = validate_site("site") |
| 98 | +if not validation.passed: |
| 99 | + for issue in validation.issues: |
| 100 | + print(f"[{issue.severity}] {issue.message}") |
| 101 | + if issue.suggestion: |
| 102 | + print(f" Suggestion: {issue.suggestion}") |
| 103 | + |
| 104 | +# Deploy to GitHub Pages |
| 105 | +deployment = deploy_site(deploy_config) |
| 106 | +if deployment.success: |
| 107 | + print(f"Deployed to {deployment.url}") |
| 108 | + |
| 109 | +# Start local preview server (blocks) |
| 110 | +preview_locally("mkdocs.yml", port=8000) |
| 111 | +``` |
| 112 | + |
| 113 | +## Three-Pass Validation |
| 114 | + |
| 115 | +The validator implements three distinct validation passes: |
| 116 | + |
| 117 | +### Pass 1: Coverage (Target: 100%) |
| 118 | + |
| 119 | +- Verifies all specified features are documented |
| 120 | +- If no features specified, checks that content exists |
| 121 | +- Creates issues for undocumented features |
| 122 | + |
| 123 | +### Pass 2: Clarity (Target: >= 80%) |
| 124 | + |
| 125 | +- **Navigation depth**: <= 3 levels recommended |
| 126 | +- **Heading quality**: Descriptive headings score higher |
| 127 | +- **Link quality**: Contextful links (not "click here") |
| 128 | +- **Structure**: No walls of text (paragraphs > 300 words) |
| 129 | + |
| 130 | +Scoring weights: |
| 131 | + |
| 132 | +- Navigation: 20% |
| 133 | +- Headings: 30% |
| 134 | +- Links: 20% |
| 135 | +- Structure: 30% |
| 136 | + |
| 137 | +### Pass 3: Reality (Target: >= 95%) |
| 138 | + |
| 139 | +- **No future tense**: "will be", "coming soon" (unless in [PLANNED] section) |
| 140 | +- **No TODOs**: Unfinished work markers |
| 141 | +- **No placeholders**: foo/bar examples in code blocks |
| 142 | + |
| 143 | +Content marked with `[PLANNED]` is excluded from reality checks. |
| 144 | + |
| 145 | +## Usage Example |
| 146 | + |
| 147 | +```python |
| 148 | +from github_pages import ( |
| 149 | + SiteConfig, |
| 150 | + DeploymentConfig, |
| 151 | + generate_site, |
| 152 | + validate_site, |
| 153 | + deploy_site, |
| 154 | +) |
| 155 | + |
| 156 | +# 1. Generate |
| 157 | +config = SiteConfig( |
| 158 | + project_name="My Project", |
| 159 | + project_url="https://github.com/myorg/myproject", |
| 160 | +) |
| 161 | + |
| 162 | +gen_result = generate_site(config) |
| 163 | +if not gen_result.success: |
| 164 | + raise RuntimeError(f"Generation failed: {gen_result.errors}") |
| 165 | + |
| 166 | +# 2. Validate |
| 167 | +val_result = validate_site(gen_result.site_dir) |
| 168 | +print(f"Coverage: {val_result.pass1_coverage}%") |
| 169 | +print(f"Clarity: {val_result.pass2_clarity_score}%") |
| 170 | +print(f"Grounded: {val_result.pass3_grounded_pct}%") |
| 171 | + |
| 172 | +if not val_result.passed: |
| 173 | + print("Validation issues:") |
| 174 | + for issue in val_result.issues: |
| 175 | + print(f" [{issue.pass_number}] {issue.message}") |
| 176 | + |
| 177 | +# 3. Deploy (only if validation passes) |
| 178 | +if val_result.passed: |
| 179 | + deploy_config = DeploymentConfig( |
| 180 | + site_dir=str(gen_result.site_dir), |
| 181 | + ) |
| 182 | + deploy_result = deploy_site(deploy_config) |
| 183 | + |
| 184 | + if deploy_result.success: |
| 185 | + print(f"Deployed to: {deploy_result.url}") |
| 186 | + else: |
| 187 | + print(f"Deployment failed: {deploy_result.errors}") |
| 188 | +``` |
| 189 | + |
| 190 | +## Dependencies |
| 191 | + |
| 192 | +Required packages: |
| 193 | + |
| 194 | +- `mkdocs>=1.5.0` |
| 195 | +- `mkdocs-material>=9.5.0` |
| 196 | +- `pyyaml` |
| 197 | + |
| 198 | +Install with: |
| 199 | + |
| 200 | +```bash |
| 201 | +pip install mkdocs mkdocs-material pyyaml |
| 202 | +``` |
| 203 | + |
| 204 | +## CI/CD Integration |
| 205 | + |
| 206 | +Example GitHub Actions workflow: |
| 207 | + |
| 208 | +```yaml |
| 209 | +name: Deploy Docs |
| 210 | + |
| 211 | +on: |
| 212 | + push: |
| 213 | + branches: [main] |
| 214 | + paths: ["docs/**", "README.md"] |
| 215 | + |
| 216 | +jobs: |
| 217 | + deploy: |
| 218 | + runs-on: ubuntu-latest |
| 219 | + steps: |
| 220 | + - uses: actions/checkout@v4 |
| 221 | + |
| 222 | + - name: Setup Python |
| 223 | + uses: actions/setup-python@v5 |
| 224 | + with: |
| 225 | + python-version: "3.11" |
| 226 | + |
| 227 | + - name: Install dependencies |
| 228 | + run: pip install mkdocs mkdocs-material pyyaml |
| 229 | + |
| 230 | + - name: Generate and validate |
| 231 | + run: | |
| 232 | + python -c " |
| 233 | + from github_pages import SiteConfig, generate_site, validate_site |
| 234 | +
|
| 235 | + config = SiteConfig( |
| 236 | + project_name='${{ github.repository }}', |
| 237 | + project_url='https://github.com/${{ github.repository }}', |
| 238 | + ) |
| 239 | +
|
| 240 | + result = generate_site(config) |
| 241 | + assert result.success, f'Generation failed: {result.errors}' |
| 242 | +
|
| 243 | + validation = validate_site(result.site_dir) |
| 244 | + for issue in validation.issues: |
| 245 | + print(f'[{issue.severity}] {issue.message}') |
| 246 | +
|
| 247 | + assert validation.passed, 'Validation failed' |
| 248 | + " |
| 249 | +
|
| 250 | + - name: Deploy |
| 251 | + run: | |
| 252 | + git config user.name github-actions |
| 253 | + git config user.email github-actions@github.com |
| 254 | + mkdocs gh-deploy --force |
| 255 | +``` |
| 256 | +
|
| 257 | +## Testing |
| 258 | +
|
| 259 | +Run the test suite: |
| 260 | +
|
| 261 | +```bash |
| 262 | +cd .claude/skills/documentation-writing |
| 263 | +PYTHONPATH=. python -m pytest github_pages/tests/ -v |
| 264 | +``` |
| 265 | + |
| 266 | +Test structure follows the testing pyramid: |
| 267 | + |
| 268 | +- 60% unit tests (fast, mocked dependencies) |
| 269 | +- 30% integration tests (multiple components) |
| 270 | +- 10% end-to-end tests (complete workflows) |
| 271 | + |
| 272 | +## Error Handling |
| 273 | + |
| 274 | +All functions provide clear error handling: |
| 275 | + |
| 276 | +- `generate_site`: Raises `TypeError` for None config, `FileNotFoundError` for missing docs |
| 277 | +- `validate_site`: Raises `FileNotFoundError` for missing site directory |
| 278 | +- `deploy_site`: Raises `TypeError` for None config, `ValueError` for missing/empty site |
| 279 | + |
| 280 | +Results include error lists for non-fatal issues that don't prevent operation. |
| 281 | + |
| 282 | +## Safety Features |
| 283 | + |
| 284 | +- **Never force push by default**: `force_push=False` in DeploymentConfig |
| 285 | +- **Branch switching with rollback**: Returns to original branch on failure |
| 286 | +- **Uncommitted changes warning**: Detects dirty working directory |
| 287 | +- **Safe subprocess handling**: Timeouts and error capture for external commands |
0 commit comments