-
Notifications
You must be signed in to change notification settings - Fork 2
/
generateIndex.ps1
87 lines (59 loc) · 2.93 KB
/
generateIndex.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
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
#!/usr/bin/env pwsh
#Requires -Version 7
Write-Host "cardArchive index.md generator"
If (!(Test-Path -Path ./archiveRate.json)) {
Write-Error -Message "archiveRate.json is required to generate the file" -ErrorId "archiveRate.jsonNotFound" -ErrorAction Stop
}
Write-Verbose "Loading json as hashtable"
$jsonIndex = (Get-Content -Path ./archiveRate.json -Raw | ConvertFrom-Json).data
Write-Verbose "Generating index.md"
$header = @"
<!-- markdownlint-disable MD036 MD033 -->
# Content Index
*This file is automatically generated from [archiveRate.json](./archiveRate.json) for database and [generateIndex.ps1](./generateIndex.md) using GitHub Actions*
***__Do not modify the file__***
**Last Updated:** $(Get-Date -Format "h:mm:ss tt 'UTC'zzz, MMMM d, yyyy")
## Table of Contents
<details>
<summary>Show Table of Content</summary>
"@
$header | Out-File -FilePath ./index.md -Encoding utf8
# Generate Table of Content
ForEach ($index in $jsonIndex) {
"* [$($index.category)](#$($index.category))" | Out-File -FilePath ./index.md -Encoding utf8 -Append
}
"`n</details>" | Out-File -FilePath ./index.md -Encoding utf8 -Append
# Generate Content
ForEach ($index in $jsonIndex) {
"`n## $($index.category)`n" | Out-File -FilePath ./index.md -Encoding utf8 -Append
ForEach ($item in $index.editions) {
$itemPath = "./$($index.category)/$($item.path)"
$itemEmoji = $item.emojiVisualIdentifier
$itemSingular = $item.isNotSplit
"* [$($itemEmoji) $($item.title) ``$($item.id)``]($($itemPath))" | Out-File -FilePath ./index.md -Encoding utf8 -Append
If ($itemSingular) {
"`n Cards located on Edition folder, not on each staff. Below is the list of contributed staff:" | Out-File -FilePath ./index.md -Encoding utf8 -Append
}
New-Item -Path "./$($itemPath)/.gitkeep" -Force
ForEach ($staff in $item.contributors) {
# Add reasons
$status = $staff.status
Switch ($status) {
"invalid" { $message = " — ⚠️ No cards from this staff were archived due to the link is invalid/missing" }
"progress" { $message = " — 💳 Cards are being created by staff" }
"halted" { $message = " — 🚪 Staff left before finishing the requests" }
"unknown" { $message = " — ❓ Cards were not archived due to status is unknown" }
Default { $message = "" }
}
If (!($status -eq "archived")) {
$staffPath = "$($staff.id)"
} ElseIf ($itemSingular) {
$staffPath = "$($staff.id)"
} Else {
$staffPath = "[$($staff.id)]($($itemPath)/$($staff.id))"
}
" * $($staffPath)$($message)" | Out-File -FilePath ./index.md -Encoding utf8 -Append
If (!($itemSingular)) { New-Item -Path "./$($itemPath)/$($staff.id)/.gitkeep" -Force }
}
}
}