MkDocs Navigation Automation¶
Overview¶
This document describes the automated solution for keeping the MkDocs navigation synchronized with the PowerShell module’s exported functions.
Problem Statement¶
Previously, the nav section in mkdocs.yml had to be manually maintained whenever new functions were added to the module. This led to:
- Missing functions in documentation navigation
- Duplicate entries
- Typos in file paths
- Inconsistent organization
Solution¶
An automated system that:
- Reads
FunctionsToExportfrom the module manifest (PSPreworkout.psd1) - Relies on aliases being exported only through
AliasesToExport - Categorizes functions into three logical groups
- Updates the
mkdocs.ymlnavigation section automatically - Triggers whenever the module manifest is updated on the main branch
Components¶
1. PowerShell Script (.github/cicd-scripts/Update-MkDocsNavigation.ps1)¶
Purpose: Updates the navigation section in mkdocs.yml based on the module manifest.
Key Functions:
Get-FunctionCategory: Determines which category a function belongs toGet-CategorizedFunctions: Reads and categorizes all exported functionsNew-NavigationYaml: Generates the YAML structure for the nav sectionUpdate-MkDocsYaml: Updates the mkdocs.yml file while preserving other content
Function Categories:
- Customize: Functions for configuring PowerShell environment
Initialize-PSEnvironmentConfigurationInstall-*cmdletsSet-*cmdletsEdit-*cmdlets for environment files- Develop: Functions for PowerShell development tasks
New-ScriptFromTemplateGet-TypeAcceleratorGet-LoadedAssembly-
Show-LoadedAssembly -
Daily Functions: General utility functions for daily operations
- All other functions (Get-, Test-, Update-, Out-, Show-*)
2. GitHub Actions Workflow (.github/workflows/Update MkDocs Navigation.yml)¶
Triggers:
- Push to
mainbranch with changes tosrc/PSPreworkout/PSPreworkout.psd1 - Manual workflow dispatch
Steps:
- Checkout repository
- Run
Update-MkDocsNavigation.ps1 - Check if mkdocs.yml was modified
- Commit and push changes if mkdocs.yml was updated
Permissions:
contents: write- to commit changespull-requests: write- for PR operations if needed
3. Pester Tests (src/Tests/Unit/Update-MkDocsNavigation.Tests.ps1)¶
Test Coverage:
- Script file validation (existence, syntax, help)
- Function categorization logic (12 tests)
- Navigation YAML generation (7 tests)
- Integration tests (5 tests)
Results: 27 tests passed, 0 failed
Usage¶
Automatic (Recommended)¶
The workflow automatically runs when you:
- Update
FunctionsToExportinsrc/PSPreworkout/PSPreworkout.psd1 - Push changes to the
mainbranch - The workflow updates
mkdocs.ymland commits it back
Manual¶
Run the script directly:
# From repository root
.\.github\cicd-scripts\Update-MkDocsNavigation.ps1
# With verbose output
.\.github\cicd-scripts\Update-MkDocsNavigation.ps1 -Verbose
# With custom paths
.\.github\cicd-scripts\Update-MkDocsNavigation.ps1 -ManifestPath "path/to/manifest.psd1" -MkDocsPath "path/to/mkdocs.yml"
Benefits¶
- Automation: No manual maintenance of navigation structure
- Consistency: Functions always appear in the same order (alphabetical within categories)
- Accuracy: Prevents typos, duplicates, and missing entries
- Time Savings: Eliminates manual updates to mkdocs.yml
- Documentation Quality: Ensures documentation is always in sync with code
Maintenance¶
Adding New Functions¶
- Add the function to
src/PSPreworkout/Public/ - Add the function name to
FunctionsToExportin the manifest - Push to main branch
- The workflow automatically updates mkdocs.yml
Modifying Categories¶
To change which category a function belongs to:
- Edit the
Get-FunctionCategoryfunction in.github/cicd-scripts/Update-MkDocsNavigation.ps1 - Update the
$developFunctionsor$customizeFunctionsarrays - Run the script manually or push changes to trigger the workflow
Testing Changes¶
# Run the Pester tests
Import-Module Pester
Invoke-Pester -Path ./src/Tests/Unit/Update-MkDocsNavigation.Tests.ps1
Files Modified¶
- ✅
.github/cicd-scripts/Update-MkDocsNavigation.ps1- Created - ✅
.github/workflows/Update MkDocs Navigation.yml- Created - ✅
src/Tests/Unit/Update-MkDocsNavigation.Tests.ps1- Created - ✅
docs/MKDOCS-NAVIGATION-AUTOMATION.md- Updated with documentation - ✅
mkdocs.yml- Fixed navigation (removed duplicates, corrected typos, added missing functions)
Example: Before and After¶
Before¶
- Manual updates required
- Had duplicate “Install-CommandNotFoundUtility” entry
- Had typo “Install-CommandNoteFoundUtility”
- Missing “Get-HashtableValueType” and other functions
- “New-Credential” was listed but doesn’t exist in manifest
After¶
- Automatic updates
- No duplicates
- All typos corrected
- All exported functions included
- Non-existent functions removed
- Consistent alphabetical ordering
Future Enhancements¶
Possible improvements:
- Add metadata tags in function files to specify categories
- Support for multiple documentation levels (beginner/advanced)
- Auto-generate function index page
- Support for versioned documentation
Troubleshooting¶
Workflow doesn’t trigger¶
- Check that changes were pushed to
mainbranch - Verify
src/PSPreworkout/PSPreworkout.psd1was modified - Check workflow permissions in repository settings
Script fails locally¶
- Ensure you’re running from repository root
- Check PowerShell version (requires 5.1+)
- Verify manifest file exists at expected path
Tests fail¶
- Some tests may skip if running outside the repository structure
- Check that Pester 5.0+ is installed
- Verify test file paths are correct