Skip to content

Instantly share code, notes, and snippets.

@spech66
Created October 1, 2022 17:52
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 spech66/d9031d299d664922b347238557bb5d4d to your computer and use it in GitHub Desktop.
Save spech66/d9031d299d664922b347238557bb5d4d to your computer and use it in GitHub Desktop.
Add YAML frontmatter to Markdown files. Obsidian Md.
$mdfiles = Get-ChildItem "." -Filter *.md
foreach($file in Get-ChildItem $mdfiles)
{
Write-Output $file.BaseName
$content = Get-Content $file.FullName -Raw
$mddate = $file.BaseName
$year = $mddate.Substring(0, 4)
$month = $mddate.Substring(5, 2)
$outtext = New-Object -TypeName System.Text.StringBuilder
$outtext.Append("---`n")
$outtext.Append("tags:`n")
$outtext.Append(" - '#journal/$year/$month'`n")
$outtext.Append("---`n")
$outtext.Append("# $mddate`n")
$outtext.Append("`n")
$outtext.Append($content.ToString())
# Set-Content -Path "$($file.FullName).bak" -value $outtext.ToString()
Set-Content -Path "$($file.FullName)" -value $outtext.ToString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment