Documentation Maintenance Tools¶
This project includes several specialized tools to help maintain cross-references and links within the documentation, especially when reorganizing or restructuring content.
Quick Start Workflow for New Users¶
If you're new to these documentation tools, here's the typical workflow for fixing cross-references after a documentation reorganization:
- Generate initial mappings file based on your documentation structure:
- Review the generated mappings to ensure they reflect your desired document organization:
- Run the cross-reference fixer in dry-run mode to see what changes would be made:
- Apply the changes after reviewing the expected updates:
- Test the documentation by building and previewing:
- Process any warnings to fix remaining broken links:
- Update navigation if needed:
Available Tools¶
1. generate-doc-mappings.sh
¶
Automatically generates path mappings for documentation cross-references by scanning the filesystem structure and analyzing the MkDocs navigation.
Usage:
Options:
--process-warnings FILE
: Process MkDocs warning file to add specific broken links--output-file FILE
: Specify output mapping file (default: docs/auto_mappings.txt)--append
: Append to existing mapping file instead of overwriting--verbose
: Show detailed information about mappings being created--dry-run
: Show what would be done without writing any files--keep-history
: Keep a history of mapping files (default: true)--history-dir DIR
: Specify directory for mapping history--help
: Show help message
Example:
Key Features:
- Automatically scans filesystem to detect index.md files and directory structure
- Parses mkdocs.yml to understand the official navigation structure
- Generates mappings for common path patterns (dir.md → dir/index.md)
- Can process MkDocs warnings to identify specific broken links
- Handles relative paths including multi-level parent directory references
- Maintains mapping history for tracking changes over time
2. fix-links-simple.sh
¶
Fixes cross-references in Markdown files using a mapping file after a documentation reorganization.
Usage:
Options:
-h, --help
: Show help message-d, --dry-run
: Check for issues without making changes-q, --quiet
: Minimize output-v, --verbose
: Show detailed progress information-p, --path DIR
: Limit processing to a specific subdirectory-f, --verify-files
: Verify that destination files actually exist (slower)-m, --mappings FILE
: Use custom mappings file (default: docs/path_mappings.txt)--docsdir DIR
: Use custom docs directory (default: ./docs)
Example:
Key Features:
- Handles both standard Markdown links and directory-style links
- Tracks and reports on links that are already correctly formatted
- Provides detailed metrics on link formats and compliance
- Generates detailed reports of changes
- Supports dry-run mode for previewing changes
- Can target specific subdirectories or process the entire documentation
3. fix-relative-links.sh
¶
Specialized script for fixing relative path issues in Markdown links, ensuring links work correctly regardless of file location in the directory hierarchy.
Usage:
Options:
-h, --help
: Show help message-d, --dry-run
: Check for issues without making changes-q, --quiet
: Minimize output-v, --verbose
: Show detailed progress information-p, --path DIR
: Limit processing to a specific subdirectory or file-o, --output-dir DIR
: Specify output directory (default: same as input)-r, --report FILE
: Specify report file
Example:
Key Features:
- Automatically calculates correct relative paths between files
- Fixes links that MkDocs would interpret incorrectly
- Maintains link anchors and other components
- Intelligently identifies and resolves common patterns
- Works with both files and directories
- Provides detailed reporting on fixed links
- Supports dry-run mode for previewing changes
4. update-mkdocs-nav.sh
¶
Updates the navigation section in mkdocs.yml based on the filesystem structure or a combination of auto-generation and manual structure.
Usage:
Options:
--auto
: Generate navigation automatically based on filesystem--update
: Update existing navigation with new files--hybrid
: Use hybrid approach (maintain structure, add new files)--backup
: Create backup of mkdocs.yml before modifying--dry-run
: Show what would be done without changing files--verbose
: Show detailed progress information--output FILE
: Write to specified file instead of updating mkdocs.yml--help
: Show help message
Example:
Key Features:
- Multiple navigation generation modes to suit different needs
- Preserves existing structure while adding new files when using hybrid or update modes
- Includes new directories and files in appropriate locations
- Keeps custom ordering and organization when using update mode
- Detects renamed sections and provides suggestions
- Provides detailed reports on changes made
Common Workflows¶
This section provides step-by-step instructions for common documentation maintenance tasks, with proper ordering of operations for each scenario.
Reorganizing a Documentation Section¶
When moving files to new locations or changing directory structure:
- First, move the files to their new locations using git or filesystem operations:
- Generate mappings for the moved files to track the changes:
- Fix cross-references in specific sections using the mappings:
- Fix relative path issues caused by directory depth changes:
- Update the navigation structure to reflect the new organization:
- Build and test the documentation to verify changes:
Converting Files to Directory Structure¶
When converting single files to directory-based organization with index.md:
- Create the directory structure and move files:
- Generate mappings specifically for the conversion pattern:
- Update cross-references throughout the documentation:
- Fix any remaining relative path issues:
- Update navigation to include new structure:
- Verify changes:
Fixing Link Issues After Detecting Broken Links¶
When MkDocs build reports broken links:
- Build documentation and capture warnings:
- Process warnings to generate mappings:
- Fix broken links using the generated mappings:
- Fix any remaining relative path issues:
- Verify fixes with another build:
Adding New Documentation Files¶
When adding new content to the documentation:
- Create the new files in the appropriate location:
- Update navigation to include new files:
- Build and test to verify integration:
Monitoring Overall Documentation Health¶
To regularly check the health of documentation cross-references:
- Verify links without making changes:
- Check for relative path issues:
- Review detailed link reports:
- Run comprehensive link checks:
- Build documentation to catch any remaining issues:
Setting Up Continuous Integration Checks¶
To include documentation verification in CI/CD pipelines:
- Add a documentation check step to your CI configuration:
- Create a reporting step to summarize findings:
Integration with docs-tools.sh¶
The docs-tools.sh
script provides a comprehensive wrapper for documentation tasks, including building, previewing, linting, and checking links.
Examples:
Best Practices¶
-
Always use the --verify-files flag with fix-links-simple.sh to ensure you're not creating links to non-existent files.
-
Run in dry-run mode first to preview changes before applying them.
-
Keep mapping files for reference as they document the reorganization and can be used again if needed.
-
Process MkDocs warnings to catch any missed cross-references.
-
Use the hybrid approach for navigation updates to maintain your custom organization while incorporating new files.
-
Commit changes in logical groups:
- Filesystem reorganization
- Cross-reference fixes
-
Navigation updates
-
Create backups before major reorganizations:
-
Test builds frequently to catch issues early.
-
Keep test files in script-tests directory: All test files for documentation tools (like test-links, test-warnings.md, test-cross-ref.md) should be kept in the
scripts/script-tests/
directory rather than in the main documentation. This prevents these files from appearing in the documentation build and generating warnings.