Created
November 5, 2017 22:05
-
-
Save chrisbrownie/102f77772458fd2a97a03de768d7d29e to your computer and use it in GitHub Desktop.
DocFx TOC generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$articleRoot = "articles" | |
$tocFileTypes = @("md") | |
function CreateTocForFolder { | |
Param( | |
[String]$Path | |
) | |
# First, create a toc for child folders | |
foreach ($folder in (Get-ChildItem -Path $Path -Directory)) { | |
CreateTocForFolder $folder.FullName | |
} | |
$toc = "" | |
"Creating toc for $($Path)" | |
foreach ($file in (Get-ChildItem -Path $Path)) { | |
if ($file.PSIsContainer) { | |
# It's a folder | |
" -Adding $($file.fullname) to toc" | |
#Todo make this read yaml and get the file metadata | |
$toc+= "- name: $($file.name)`n" | |
$toc+= " href: $($file.name)/`n" | |
} else { | |
# It's not a folder | |
if ($tocFileTypes -contains $($file.FullName.Split(".")[-1])) { | |
# Supported file type | |
" -Adding $($file.fullname) to toc" | |
#Todo make this read yaml and get the file metadata | |
$toc+= "- name: $($file.name)`n" | |
$toc+= " href: $($file.name)`n" | |
} else { | |
# Unsupported file type | |
} | |
} | |
} | |
Set-Content -Path (Join-Path $Path "toc.yml") -Value $toc -Force | |
} | |
CreateTocForFolder (Get-Item $articleRoot).FullName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment