Created
October 1, 2022 17:52
-
-
Save spech66/d9031d299d664922b347238557bb5d4d to your computer and use it in GitHub Desktop.
Add YAML frontmatter to Markdown files. Obsidian Md.
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
$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