-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite.ps1
More file actions
45 lines (35 loc) · 1.39 KB
/
website.ps1
File metadata and controls
45 lines (35 loc) · 1.39 KB
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
<#
generated with CMTools 0.0.1-alpha 54daec1
.SYNOPSIS
PowerShell script for running pandoc on all Markdown docs ending in .md
#>
$project = "CMTools"
Write-Output "Building website for ${project}"
$pandoc = Get-Command pandoc | Select-Object -ExpandProperty Source
# Get all markdown files except 'nav.md'
$mdPages = Get-ChildItem -Filter *.md | Where-Object { $_.Name -ne "nav.md" }
# Generate HTML page names from markdown files
$htmlPages = $mdPages | ForEach-Object { [System.IO.Path]::ChangeExtension($_.Name, ".html") }
function Build-HtmlPage {
param($htmlPages, $mdPages)
foreach ($htmlPage in $htmlPages) {
$mdPage = [System.IO.Path]::ChangeExtension($htmlPage, ".md")
if (Test-Path $pandoc) {
& $pandoc "--metadata" "title=$($htmlPage.Replace('.html', ''))" "-s" "--to" "html5" $mdPage "-o" $htmlPage `
"--lua-filter=links-to-html.lua" `
"--template=page.tmpl"
}
if ($htmlPage -eq "README.html") {
Move-Item -Path "README.html" -Destination "index.html" -Force
}
}
}
function Invoke-PageFind {
# Run PageFind
pagefind --verbose --glob="{*.html,docs/*.html}" --force-language en-US --exclude-selectors="nav,header,footer" --output-path ./pagefind --site .
git add pagefind
}
# Build HTML page
Build-HtmlPage -htmlPages $htmlPages -mdPages $mdPages
# Invoke PageFind
Invoke-PageFind