-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-homepage.ps1
40 lines (35 loc) · 1.38 KB
/
update-homepage.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
param ()
$destinationFile = ".\docs\_data\navigation_boxes.yml"
########### Create a markdown table ##########
Write-Host "Creating new version of $destinationFile based on $sourceFile ..."
$elapsed = Measure-Command -Expression {
$classes = @("function", "predicate")
$counts = @{}
foreach($class in $classes) {
$sourceFile = ".\docs\_data\$($class.ToLower()).json"
$count = (Get-Content -Path $sourceFile | ConvertFrom-Json | Measure).Count
Write-Host "`t$count $($class.ToLower())s found"
$counts.Add($class, $count)
}
########### Update the sub-part of the docs file ##########
Write-Host "`tReplacing content in $destinationFile ..."
$text = ""
[string] $template = ""
foreach ($line in Get-Content -Path $destinationFile) {
if ($template -eq "") {
$text += $line
} else {
$text += $template
}
$template=""
if($line.Trim().StartsWith("#Template#")) {
$template = $line.Trim().Replace("#Template#", "")
foreach($count in $counts.keys) {
$template = $template.Replace("<$count>", "$($counts[$count])")
}
}
$text += "`r`n"
}
$text | Out-File -FilePath $destinationFile -NoNewline -Encoding ascii
}
Write-Host "New version of $destinationFile created in $($elapsed.TotalSeconds) seconds"