forked from couleur-tweak-tips/CTT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildMap.ps1
58 lines (44 loc) · 1.47 KB
/
buildMap.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
Set-Location $PSScriptRoot
if (-not(Get-Command ConvertFrom-Yaml -ErrorAction Ignore)) {
Install-Module -Name powershell-yaml -Force
}
[Hashtable[]]$nav = (Get-Content .\mkdocs.yml | ConvertFrom-Yaml).nav
function Display ([Hashtable]$Table, [int32]$Depth) {
$str = '#' * $depth + ' '
$depth++
foreach ($item in $table.GetEnumerator()) {
# Wait-Debugger
if ($item.value.keys.length -gt 1) {
$link = if (-not($item.value.index)) {
$item.value | Where-Object { $_ -is [string] }
}
else {
$item.value.index
}
write-output ("`n`n" + $str + '[' + $item.name + "](https://ctt.cx/$link)`n")
}
if ($item.value -is [string]) {
write-output ($str + '[' + $item.name + "](https://ctt.cx/$($item.value))")
}
foreach ($nesteditems in $item.value) {
if ($nesteditems -is [string]) { continue }
Display $nesteditems $depth
}
}
}
$depth = 2
$ret = foreach ($category in $nav) {
display $category $depth
}
Set-Content ./map.md -Value @'
# [CTT.cx](https://ctt.cx)
'@
$ret -replace "\.md" -replace "/index" | Add-Content ./map.md
if (-not(Test-Path ./docs/map/)) {
mkdir ./docs/map/ | out-null
}
if (-not(Get-Command markmap -ErrorAction Ignore)) {
npm install -g markmap-cli
}
markmap ./map.md --offline --no-toolbar --no-open -o ./docs/map/index.html
# remove-item ./map.md