-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-index.ps1
45 lines (39 loc) · 1.58 KB
/
update-index.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
$classes = @("Function", "Predicate")
$destinationFile = ".\docs\_docs\library-index.md"
Write-Host "Creating new version of $destinationFile ..."
$elapsed = Measure-Command -Expression {
foreach ($class in $classes) {
$sourceFile = ".\docs\_data\$($class.ToLower()).json"
$top += "[$($class)s](#$($class.ToLower())s) - "
########### Create an index ##########
Write-Host "`tUsing $sourceFile as reference for $($class.ToLower())s ..."
$members = Get-Content -Path $sourceFile | ConvertFrom-Json
$members = $members | Sort-Object Name
Write-Host "`t$($members.Count) $($class.ToLower())s found"
$doc += "## $($class)s`r`n`r`n"
ForEach($member in $members) {
$doc += "* [$($member.Name)]({{ site.baseurl }}/docs/$($member.Scope.ToLower())-$($class.ToLower())s/#$($member.Name))`r`n"
}
$doc += "`r`n`r`n"
}
$top = $top.Remove($top.Length-2, 2)
}
########### Update the sub-part of the docs file ##########
Write-Host "`tReplacing content in $destinationFile ..."
$text = ""
[bool] $skip = $false
foreach ($line in Get-Content -Path $destinationFile) {
if($line -eq "<!-- END AUTO-GENERATED -->") {
$skip = $false
}
if (-not $skip) {
$text += $line + "`r`n"
}
if ($line -eq "<!-- START AUTO-GENERATED -->"){
$skip = $true
$text += "$top`r`n`r`n`r`n"
$text += $doc
}
}
$text | Out-File -FilePath $destinationFile -NoNewline -Encoding ascii
Write-Host "New version of $destinationFile created in $($elapsed.TotalSeconds) seconds"