Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created November 5, 2017 22:05
Show Gist options
  • Save chrisbrownie/102f77772458fd2a97a03de768d7d29e to your computer and use it in GitHub Desktop.
Save chrisbrownie/102f77772458fd2a97a03de768d7d29e to your computer and use it in GitHub Desktop.
DocFx TOC generator
$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