Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (36 sloc) 1.6 KB
function Convert-FolderContentToMarkdownTableOfContents{
Create a Table of Contents in markdown
This function can be used to generate a markdown file that contains a Table of Contents based on the contents of a folder
It’s the folder’s location on the disk
to build the URL for each file. This will be added as a link
.PARAMETER FiletypeFilter
to filter the files on the folder
Convert-FolderContentToMarkdownTableOfContents -BaseFolder "D:\Github\<module folder>" -BaseURL "<user>/<repository>/tree/master" -FiletypeFilter "*.md"
param (
$nl = [System.Environment]::NewLine
$TOC = "## Index$nl"
$repoFolderStructure = Get-ChildItem -Path $BaseFolder -Directory | Where-Object Name -NotMatch "\.github|\.git"
foreach ($dir in ($repoFolderStructure | Sort-Object -Property Name)) {
$repoStructure = Get-ChildItem -Path $dir.FullName -Filter $FiletypeFilter
$TOC += "* $($dir.Name) $nl"
foreach ($md in ($repoStructure | Sort-Object -Property Name)) {
$suffix = $($md.Directory.ToString().Replace($BaseFolder, [string]::Empty)).Replace("\", "/")
$fileName = $md.Name -replace $md.Extension
$TOC += " * [$fileName]($([uri]::EscapeUriString(""$baseURL$suffix/$($md.Name)"")))$nl"
return $TOC