Created
July 1, 2022 10:17
-
-
Save rfennell/40d43afff81809447d30753056a5e64f to your computer and use it in GitHub Desktop.
A script to update a Hugo content file to provide an alias that matches a Wordpress permalink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$basepath = "C:\tmp\bmBlog\content" | |
$files = Get-ChildItem -path $basepath -Filter "*.md" -Recurse | % { $_.FullName} | |
foreach ($file in $files) { | |
$f = get-item $file | |
$content = (Get-Content -path $f.FullName) | |
foreach ($l in $content) { | |
if ($l.StartsWith("date:") -and $l.Length -gt 6) { | |
"Updating $($f.FullName)" | |
$s = $l.Split(" ") | |
$d = get-date -date "$($s[2]) $($s[3]) $($s[4])" | |
$x = $d.ToString("yyyy/MM/dd") | |
$content -replace "draft: false","draft: false`naliases: [`"/$($f.Directory.Name)/$x/$($f.basename)/`"]" | Set-Content -path $f.FullName | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment