Skip to content

Instantly share code, notes, and snippets.

@rfennell
Created July 1, 2022 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfennell/40d43afff81809447d30753056a5e64f to your computer and use it in GitHub Desktop.
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
$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