From f844341b62c4483495b7ccbc306a3d89137f8039 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Fri, 4 Oct 2019 11:44:22 -0600 Subject: [PATCH 1/3] Added parameters --- .../New-GitHubMarkdownIndex.ps1 | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 b/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 index 7b85464..c02f239 100644 --- a/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 +++ b/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 @@ -1,15 +1,38 @@ function New-GitHubMarkdownIndex { param( - $Path = 'C:\Temp\Events', - $GitHubUri = 'https://github.com/jaapbrasser/events/tree/master' + [string] $Path = 'C:\Temp\Events', + [string] $GitHubUri = 'https://github.com/jaapbrasser/events/tree/master', + [string[]] $IncludeExtensions = @('.md','pdf','.123','123','234','.234'), + [switch] $NoClipBoard ) - Get-ChildItem -LiteralPath $Path | % { - $GHPath = $_.FullName -replace [regex]::Escape($Path) -replace '\\','/' -replace '\s','%20' - "* [$(Split-Path $_ -Leaf)]($GitHubUri$GHPath)" - $_ | ls -recurse | ? {$_.PSIsContainer -or $_.Extension -eq '.md'} | select -exp fullname | % { - $Count = ($_ -split '\\').Count-($Path.Split('\').Count+1) - $GHPath = $_ -replace [regex]::Escape($Path) -replace '\\','/' -replace '\s','%20' - "$(" "*$Count*2)* [$(Split-Path $_ -Leaf)]($GitHubUri$GHPath)" + + begin { + $IncludeExtensions = $IncludeExtensions | ForEach-Object { + if ($_ -notmatch '^\.') { + ".$_" + } else { + $_ + } } - } | clip.exe + + $BuildMarkDown = { + Get-ChildItem -LiteralPath $Path | ForEach-Object { + $GHPath = $_.FullName -replace [regex]::Escape($Path) -replace '\\','/' -replace '\s','%20' + "* [$(Split-Path $_ -Leaf)]($GitHubUri$GHPath)" + $_ | Get-ChildItem -Recurse | ? {$_.PSIsContainer -or $_.Extension -in $IncludeExtensions} | ForEach-Object { + $Count = ($_.FullName -split '\\').Count-($Path.Split('\').Count+1) + $GHPath = $_.FullName -replace [regex]::Escape($Path) -replace '\\','/' -replace '\s','%20' + "$(" "*$Count*2)* [$(Split-Path $_ -Leaf)]($GitHubUri$GHPath)" + } + } + } + } + + process { + if ($NoClipBoard) { + $BuildMarkDown.Invoke() + } else { + $BuildMarkDown.Invoke() | clip.exe + } + } } \ No newline at end of file From 0ff324bb56e2370b9d8b775ac87f674af182f821 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Fri, 4 Oct 2019 11:46:12 -0600 Subject: [PATCH 2/3] Added parameter help --- New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 b/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 index c02f239..93406b5 100644 --- a/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 +++ b/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 @@ -1,8 +1,12 @@ function New-GitHubMarkdownIndex { param( + # The path of the file structure that will be mapped in markdown [string] $Path = 'C:\Temp\Events', + # The GitHub uri that files will be linked to [string] $GitHubUri = 'https://github.com/jaapbrasser/events/tree/master', - [string[]] $IncludeExtensions = @('.md','pdf','.123','123','234','.234'), + # Included file types, specified by extension + [string[]] $IncludeExtensions = @('.md','pdf'), + # Whether to use clip.exe or to output to console [switch] $NoClipBoard ) From 85f77419cd01bec9a387da2b0d269ae4d8a416e0 Mon Sep 17 00:00:00 2001 From: Jaap Brasser Date: Fri, 4 Oct 2019 14:07:20 -0600 Subject: [PATCH 3/3] Added psiscontainer clause --- New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 b/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 index 93406b5..4663011 100644 --- a/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 +++ b/New-GitHubMarkdownIndex/New-GitHubMarkdownIndex.ps1 @@ -23,10 +23,12 @@ function New-GitHubMarkdownIndex { Get-ChildItem -LiteralPath $Path | ForEach-Object { $GHPath = $_.FullName -replace [regex]::Escape($Path) -replace '\\','/' -replace '\s','%20' "* [$(Split-Path $_ -Leaf)]($GitHubUri$GHPath)" - $_ | Get-ChildItem -Recurse | ? {$_.PSIsContainer -or $_.Extension -in $IncludeExtensions} | ForEach-Object { - $Count = ($_.FullName -split '\\').Count-($Path.Split('\').Count+1) - $GHPath = $_.FullName -replace [regex]::Escape($Path) -replace '\\','/' -replace '\s','%20' - "$(" "*$Count*2)* [$(Split-Path $_ -Leaf)]($GitHubUri$GHPath)" + if ($_.PSIsContainer) { + $_ | Get-ChildItem -Recurse | ? {$_.PSIsContainer -or $_.Extension -in $IncludeExtensions} | ForEach-Object { + $Count = ($_.FullName -split '\\').Count-($Path.Split('\').Count+1) + $GHPath = $_.FullName -replace [regex]::Escape($Path) -replace '\\','/' -replace '\s','%20' + "$(" "*$Count*2)* [$(Split-Path $_ -Leaf)]($GitHubUri$GHPath)" + } } } }