Skip to content

Instantly share code, notes, and snippets.

@bellons91
Created April 28, 2022 08:46
Show Gist options
  • Save bellons91/5f6394168651dff0d807a7a840ffbcd0 to your computer and use it in GitHub Desktop.
Save bellons91/5f6394168651dff0d807a7a840ffbcd0 to your computer and use it in GitHub Desktop.
This PowerShell script automatically creates the structure for a blog article with some predefined Frontmatter fields
git checkout master
git pull
$tmpSlug = Read-Host -Prompt 'Article slug?'
$currentYear = Get-Date -Format "yyyy"
$newFolderName = $currentYear +"/" + $tmpSlug
$rootLocation = Get-Location
$placeholderImgLocation = "\assets\img_placeholder.png"
Set-Location ".\content\posts"
git checkout -b article/$tmpSlug
New-Item -Path "." -Name $newFolderName -ItemType "directory"
Get-Location
Set-Location $newFolderName
$currentLocation = Get-Location
Add-Content article.md "---"
Add-Content article.md "title: `"Placeholder title`""
Add-Content article.md "path: `'/blog/$tmpSlug`'"
Add-Content article.md "tags: [`"MainArticle`"]"
Add-Content article.md "featuredImage: `"./cover.png`""
Add-Content article.md "excerpt: `"a description for $tmpSlug`""
Add-Content article.md "created: 4219-11-20"
Add-Content article.md "updated: 4219-11-20"
Add-Content article.md "---"
Copy-Item $rootLocation$placeholderImgLocation -Destination "$currentLocation\cover.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment