-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathConvert-PoshCodeData.ps1
More file actions
107 lines (85 loc) · 3.22 KB
/
Convert-PoshCodeData.ps1
File metadata and controls
107 lines (85 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function Export-PowerSite {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
$OutputPath,
[Parameter(ValueFromPipelineByPropertyName)]
$parent,
[Parameter(ValueFromPipelineByPropertyName)]
[Alias("child")]
$children,
[Parameter(ValueFromPipelineByPropertyName)]
[alias("pid")]
$id,
[Parameter(ValueFromPipelineByPropertyName)]
[alias("poster")]
$author,
[Parameter(ValueFromPipelineByPropertyName)]
$title,
[Parameter(ValueFromPipelineByPropertyName)]
$date,
[Parameter(ValueFromPipelineByPropertyName)]
$description,
[Parameter(ValueFromPipelineByPropertyName)]
[alias("format")]
$language,
[Parameter(ValueFromPipelineByPropertyName)]
$code
)
begin {
$OutputPath = Convert-Path $OutputPath
Get-Item $OutputPath\Static\scripts -ErrorAction SilentlyContinue |
Remove-Item -Confirm -Recurse
Get-Item $OutputPath\Pages\scripts -ErrorAction SilentlyContinue |
Remove-Item -Confirm -Recurse
$null = New-Item $OutputPath\Static\scripts -Type Directory -Force
$null = New-Item $OutputPath\Pages\scripts -Type Directory -Force
}
process {
if($language -eq "posh") {
$language = "powershell"
}
$extension = switch($language) {
"asp" { ".asp" }
"bash" { ".sh" }
"cpp" { ".cpp" }
"csharp" { ".cs" }
"javascript" { ".js" }
"powershell" { ".ps1" }
"text" { ".txt" }
"vbnet" { ".vb" }
"xml" { ".xml" }
default { ".txt" }
}
# Work around PowerShell's insistence on BOMs
function Write-AllLines {
param($Path, $Content)
$null = New-Item $Path -Type File -Force
[IO.File]::WriteAllLines((Convert-Path $Path), $content)
}
Write-AllLines "$OutputPath\Pages\scripts\$id.md" @"
---
pid: $id
author: $author
title: $title
date: $date
tags: $language
file: Static\scripts\$id$extension
$(if($parent){ "parent: $($parent -join ',')"})
$(if($children){ "children: $($children -join ',')"})
---
### Download [$title$extension](/scripts/$id$extension)$(if($parent -ne 0) { " - [parent](/scripts/$parent.html)" })$( if($children){ " - children: $($(foreach($child in $children) { "[$child](/scripts/$child.html)" }) -join ', ')" })
$description
``````$language
$code
``````
"@
Write-Progress (Resolve-Path "$OutputPath\Pages\scripts\$id.md")
Write-AllLines "$OutputPath\Static\scripts\$id$extension" $code
Write-Progress (Resolve-Path "$OutputPath\Static\scripts\$id$extension")
}
}
Push-Location $PSScriptRoot
Write-Warning "This dump contains some malware samples which will trigger your AV"
New-Item $PSScriptRoot\export -Type Directory -Force
Import-Csv $PSScriptRoot\PoshCodeData.csv | Export-PowerSite $PSScriptRoot\export