Skip to content

Commit

Permalink
added script that was used to clean up my current markdown files for my
Browse files Browse the repository at this point in the history
blog.
  • Loading branch information
edpanameno committed Mar 25, 2020
1 parent bb68017 commit 9556a6b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions powershell/BlogPost-Cleanup-Script.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
##
## This script will be used to format my *.md files for my blog so that
## they can live inside of a nextjs application (or any other static site
## system that supports this format)
##
$files = get-childitem -path "." -Filter *.md

## the directory where the formatted files will be copied to
$output = "c:\users\ed\Desktop\posts\output\"

foreach($file in $files) {
$fileName = $file.Name
$datePortion = $file.Name.Substring(0, 10)
$fileLength = $fileName.Length;
$fileNameWithNoDate = $file.Name.Substring(11, ($fileLength - 11))

# We need to add the following line to each file so that it can be used
# when building out the blog post:
# date: "2014-12-22"
# This date field will then be used to show the date on the post
$fileContent = Get-Content $file
$fileContent[1] += [System.Environment]::NewLine + "date: `"$($datePortion)`""
$fileContent | Set-Content $file

# Now we need to create a new file name without the date portion
# so that it's nicely formatted
copy-item $file -Destination "$($output)$($fileNameWithNoDate)"
Write-Output "Done with file $($fileName)"
}

0 comments on commit 9556a6b

Please sign in to comment.