Link Maintenance Guide¶
This guide documents the processes and tools for maintaining link health across the Ultimate MkDocs documentation site.
Overview¶
Link maintenance is critical for user experience and SEO. This guide covers:
- Automated link checking via pre-commit hooks
- Manual link validation processes
- Common link issues and their solutions
- Best practices for creating maintainable links
Link Checking Infrastructure¶
Pre-commit Hook Integration¶
The project uses automated link checking through pre-commit hooks to catch broken links before they reach production.
Configuration location: .pre-commit-config.yaml
- repo: local
hooks:
- id: link-check
name: Internal link validation
entry: python
language: system
args: [tests/test_links.py, --check-internal-only]
files: \.md$
pass_filenames: false
Link Checker Tool¶
Location: tests/test_links.py
The link checker validates: - Internal markdown links - Asset references (images, files) - Navigation references - Anchor links within pages
Exclusions (automatically skipped):
- HTML-encoded email addresses
- Template placeholders [VARIABLE]
- Intentional demo broken links
- External URLs (optional flag)
Running Link Validation¶
Automated (Recommended)¶
# Via pre-commit (runs on git commit)
git commit -m "Your changes"
# Manual pre-commit run
pre-commit run link-check --all-files
Manual Validation¶
# Check internal links only
python tests/test_links.py --check-internal-only
# Build site first if needed
mkdocs build --clean
python tests/test_links.py --check-internal-only
CI/CD Integration¶
The link checker is configured to skip in CI environments to avoid timeouts:
Common Link Issues and Solutions¶
1. Missing Asset Files¶
Problem: References to non-existent images or files
Solutions: - Create the missing asset file - Update the reference to point to an existing file - Remove the reference if no longer needed
2. Broken Internal Navigation¶
Problem: Links to missing documentation pages
Solutions: - Create the missing page with appropriate content - Update the link to point to the correct existing page - Use relative paths correctly (../ for parent directory)
3. Incorrect Anchor References¶
Problem: Links to non-existent page sections
Solutions: - Verify the target page has the referenced section - Update the anchor to match the actual section heading - Use the correct anchor format (lowercase, hyphens for spaces)
4. Template Placeholder Issues¶
Problem: Unresolved template variables in links
Solutions: - Replace template variables with actual values - Add exclusion pattern for legitimate template files - Move template files to appropriate template directories
Link Creation Best Practices¶
Internal Links¶
Use relative paths:
✅ Good: [Configuration](../getting-started/configuration.md)
❌ Avoid: [Configuration](/getting-started/configuration.md)
Include file extensions:
Use descriptive anchor text:
Asset References¶
Use consistent paths:
✅ Good: <img loading="lazy" src="../assets/images/architecture.svg" alt="Diagram">
❌ Avoid: <img loading="lazy" src="../../docs/assets/images/architecture.svg" alt="Diagram">
Provide alt text:
✅ Good: <img loading="lazy" src="../assets/images/architecture.svg" alt="System architecture diagram">
❌ Avoid: <img loading="lazy" src="../assets/images/architecture.svg" alt="">
Navigation Structure¶
Keep directory structure logical:
docs/
├── getting-started/
│ ├── index.md
│ └── configuration.md
├── features/
│ ├── index.md
│ └── advanced-features.md
└── api/
├── index.md
└── reference.md
Maintenance Workflow¶
Weekly Maintenance¶
-
Run full link check:
-
Review any new broken links
- Update or fix broken references
- Commit fixes with descriptive messages
After Content Updates¶
-
Test locally before committing:
-
Run pre-commit hooks:
-
Address any link failures before merging
Monthly Audits¶
- Check external link health (if enabled)
- Review link patterns for consistency
- Update documentation as needed
- Optimize asset organization if needed
Troubleshooting¶
Link Checker False Positives¶
If the link checker reports valid links as broken:
-
Check file existence:
-
Verify link syntax:
- No spaces in file names
- Correct file extension
-
Proper relative path construction
-
Update exclusion patterns if needed in
tests/test_links.py
Performance Issues¶
If link checking is slow:
-
Use build caching:
-
Skip in CI (already configured)
-
Reduce scope to specific directories:
Build Integration Issues¶
If pre-commit hooks fail consistently:
-
Check dependencies:
-
Update pre-commit:
-
Skip specific checks temporarily:
Tools and Configuration¶
Essential Files¶
.pre-commit-config.yaml
- Hook configurationtests/test_links.py
- Link validation scriptmkdocs.yml
- Site configuration- This guide (
docs/team/link-maintenance-guide.md
)
Useful Commands¶
# Quick link check
python tests/test_links.py --check-internal-only
# Full validation with external links
python tests/test_links.py
# Build and validate
mkdocs build --clean && python tests/test_links.py
# Pre-commit specific hook
pre-commit run link-check
# Fix common formatting issues
pre-commit run --all-files
Integration with Development Workflow¶
For Contributors¶
- Before making changes: Understand the link structure
- When adding content: Follow link best practices
- Before committing: Ensure pre-commit hooks pass
- In pull requests: Check that no new broken links are introduced
For Maintainers¶
- Regular audits: Monthly link health checks
- Update patterns: Keep exclusion patterns current
- Performance monitoring: Watch for link checker slowdowns
- Documentation updates: Keep this guide current
Success Metrics¶
Based on the Task #66 implementation:
- Reduced broken links: From 83 to 33 (60% improvement)
- Enhanced detection: Added filters for false positives
- Automated fixing: Pre-commit hooks handle formatting
- Comprehensive coverage: All link types validated
Future Enhancements¶
Consider implementing:
- External link validation (with rate limiting)
- Link health dashboards for monitoring
- Automated link fixing for common patterns
- Integration with CI/CD for blocking deployments
- Performance optimizations for large sites
This guide ensures consistent link quality and helps maintain the professional standard of the Ultimate MkDocs documentation platform.