11# !/usr/bin/env pwsh
2+ # This script is designed to be run in a PowerShell environment.
3+
4+ # Name: TCAT Wiki - Navigation Section Generator
5+ # Version: 1.0.1
6+ # Date: 2025-09-17
7+ # Author: Amy Bordenave, Taskar Center for Accessible Technology, University of Washington
8+ # License: CC-BY-ND 4.0 International
9+
210<#
311. SYNOPSIS
412 Generates MkDocs navigation structure from docs directory
715 Scans the docs directory structure and generates a YAML navigation tree
816 that can be inserted into mkdocs.yml. Uses frontmatter titles when available,
917 otherwise derives titles from filenames and directory names.
18+
1019. PARAMETER docsPath
1120 Path to the documentation directory to scan (default: "docs")
1221
13- . PARAMETER outputFile
14- Output file path for the generated navigation YAML (default: console output )
22+ . PARAMETER mkdocsPath
23+ Path to the mkdocs.yml file (default: "../mkdocs.yml" )
1524
1625. PARAMETER updateMkdocs
1726 Update the mkdocs.yml file directly by replacing the nav section
1827
19- . PARAMETER mkdocsPath
20- Path to the mkdocs.yml file (default: "../mkdocs.yml")
21-
2228. EXAMPLE
2329 .\generate-nav.ps1
2430 Generates navigation and outputs to console
2531
26- . EXAMPLE
27- .\generate-nav.ps1 -outputFile "nav.yml"
28- Generates navigation and saves to nav.yml
29-
3032. EXAMPLE
3133 .\generate-nav.ps1 -updateMkdocs
3234 Updates mkdocs.yml directly with generated navigation
3638 [Parameter (HelpMessage = " Path to the documentation directory" )]
3739 [string ]$docsPath = " " ,
3840
39- [Parameter (HelpMessage = " Output file path for generated navigation" )]
40- [string ]$outputFile = " " ,
41-
4241 [Parameter (HelpMessage = " Update mkdocs.yml directly" )]
4342 [switch ]$updateMkdocs ,
4443
@@ -118,7 +117,7 @@ function Build-DirectoryNav {
118117 )
119118
120119 $items = @ ()
121- $indent = " " * $indentLevel
120+ $indent = " " * $indentLevel
122121
123122 # Get directory name and relative path
124123 $dirInfo = Get-Item $dirPath
@@ -139,7 +138,7 @@ function Build-DirectoryNav {
139138
140139 # Add index.md first if it exists
141140 if ($hasIndex ) {
142- $subItems += " $indent - $relativePath /index.md"
141+ $subItems += " $indent - $relativePath /index.md"
143142 }
144143
145144 # Add other files in this directory
@@ -149,7 +148,7 @@ function Build-DirectoryNav {
149148 if (-not $fileTitle ) {
150149 $fileTitle = ConvertTo-Title $file.BaseName
151150 }
152- $subItems += " $indent - $ ( $fileTitle ) : $fileRelativePath "
151+ $subItems += " $indent - $ ( $fileTitle ) : $fileRelativePath "
153152 }
154153
155154 # Add subdirectories
@@ -245,7 +244,7 @@ foreach ($file in $rootFiles) {
245244
246245# Generate final navigation YAML with proper indentation
247246$indentedNavItems = $navItems | ForEach-Object { " $_ " }
248- $navYaml = " nav:" + [Environment ]::NewLine + ($indentedNavItems -join [Environment ]::NewLine)
247+ $navYaml = " nav:" + [Environment ]::NewLine + ($indentedNavItems -join [Environment ]::NewLine) + [ Environment ]::NewLine
249248
250249# Output results
251250if ($updateMkdocs ) {
@@ -304,11 +303,6 @@ if ($updateMkdocs) {
304303 Set-Content - Path $mkdocsPath - Value $newContent - Encoding UTF8 - NoNewline
305304 Write-Host " Successfully updated mkdocs.yml navigation section" - ForegroundColor Green
306305}
307- elseif ($outputFile ) {
308- # Save to output file
309- Set-Content - Path $outputFile - Value $navYaml - Encoding UTF8
310- Write-Host " Navigation saved to: $outputFile " - ForegroundColor Green
311- }
312306else {
313307 # Output to console
314308 Write-Host " "
0 commit comments