-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlights.ps1
60 lines (54 loc) · 1.49 KB
/
highlights.ps1
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
[CmdletBinding()]
param (
[switch]$rewrite = $false
)
$highlights = (Get-Content _data/highlights.json) | ConvertFrom-Json
function Main {
Add-Type -AssemblyName System.IO
$highlights.PsObject.Properties | ForEach-Object {
$title = $_.Name
Set-Highlights $_ '_highlights' $_.Name
}
}
function Set-Highlights($current, $baseDirectory, $type) {
Write-Host "=======================" -ForegroundColor Cyan
Write-Host "Handling $baseDirectory/$type" -ForegroundColor Cyan
Write-Host "=======================" -ForegroundColor Cyan
$current.Value | ForEach-Object {
$title = $_.Name
$path = "$baseDirectory/$type/$title.md"
$content = @"
---
title: $title
type: $type
---
"@
Set-FileContent -name $title -path $path -content $content
}
}
function Set-FileContent {
param (
[string]$name,
[string]$path,
[string]$content
)
$fileExists = Test-Path $path;
if (!$fileExists -or $rewrite) {
$fi = ([System.IO.FileInfo]$path)
if (-not $fi.Directory.Exists) {
$fi.Directory.Create();
Write-Host "Directory created '$($fi.Directory)'"
}
Set-Content -Value $content -Path $path
if ($fileExists) {
Write-Host "File $name updated" -ForegroundColor DarkMagenta
}
else {
Write-Host "File $name created" -ForegroundColor DarkGreen
}
}
else {
Write-Verbose "File exists $name"
}
}
Main