36 lines
1.2 KiB
PowerShell
36 lines
1.2 KiB
PowerShell
$src = Resolve-Path "$PSScriptRoot\..\..\docs\Notes"
|
|
$dst = "$PSScriptRoot\wwwroot\docs\notes"
|
|
if (Test-Path $dst) { Remove-Item "$dst\*" -Force -ErrorAction SilentlyContinue }
|
|
New-Item -ItemType Directory -Path $dst -Force | Out-Null
|
|
|
|
$entries = @()
|
|
Get-ChildItem -Path $src -Filter "*.md" | ForEach-Object {
|
|
$base = $_.BaseName
|
|
$slug = $base.ToLowerInvariant()
|
|
$slug = $slug -replace "'", ""
|
|
$slug = $slug -replace "\.", ""
|
|
$slug = $slug -replace "[^a-z0-9 -]", ""
|
|
$slug = $slug -replace "\s+", "-"
|
|
$slug = $slug -replace "-+", "-"
|
|
$slug = $slug.Trim('-')
|
|
|
|
Copy-Item $_.FullName (Join-Path $dst "$slug.md")
|
|
|
|
$category = $null
|
|
$content = Get-Content $_.FullName -Raw
|
|
if ($content -match '(?s)^---\s*\n(.*?)\n---') {
|
|
$frontmatter = $Matches[1]
|
|
if ($frontmatter -match '(?m)^category:\s*(.+)$') {
|
|
$category = $Matches[1].Trim().Trim('"')
|
|
}
|
|
}
|
|
|
|
$entry = @{ slug = $slug; title = $base }
|
|
if ($category) { $entry.category = $category }
|
|
$entries += $entry
|
|
}
|
|
|
|
$indexPath = "$PSScriptRoot\wwwroot\docs\notes-index.json"
|
|
$index = @{ notes = $entries } | ConvertTo-Json
|
|
Set-Content -Path $indexPath -Value $index -Encoding UTF8
|