-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadventures.ps1
56 lines (52 loc) · 1.4 KB
/
adventures.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
[CmdletBinding()]
param (
[switch]$rewrite = $false
)
$adventures = (Get-Content _data/adventures.json) | ConvertFrom-Json
function Main {
Set-Players-Adventures '_adventures'
Set-Players-Adventures '_gm-adventures'
}
function Set-Players-Adventures($baseDirectory) {
Write-Host "=======================" -ForegroundColor Cyan
Write-Host "Handling $baseDirectory adventures" -ForegroundColor Cyan
Write-Host "=======================" -ForegroundColor Cyan
$adventures.PsObject.Properties | ForEach-Object {
$name = $_.Name
$title = $_.Value.name
$path = "$baseDirectory/$name.md"
$frontMatter = $_.Value.frontMatter
if (!$frontMatter) {
$frontMatter = @()
}
$content = @"
---
title: '$title'
key: $name
$([String]::Join("`n", $frontMatter))
---
"@
Set-FileContent -name $name -path $path -content $content
}
}
function Set-FileContent {
param (
[string]$name,
[string]$path,
[string]$content
)
$fileExists = Test-Path $path;
if (!$fileExists -or $rewrite) {
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