Skip to content

Instantly share code, notes, and snippets.

@Pome-ro
Last active November 20, 2017 04:29
Show Gist options
  • Save Pome-ro/e7893ac5ae2b793946199778953d0149 to your computer and use it in GitHub Desktop.
Save Pome-ro/e7893ac5ae2b793946199778953d0149 to your computer and use it in GitHub Desktop.
Script to generate a new blog post for your github pages jekyll site.
[CmdletBinding()]
param (
# Name
[Parameter(Mandatory)]
[string]
$Name,
# Date
[Parameter()]
[String]
$Date = (Get-Date -Format yyyy-M-d),
# content
[Parameter()]
[string]
$Content,
# Path
[Parameter()]
[string]
$Path = ".\_posts",
# OpenInCode
[Parameter()]
[switch]
$OpenWithCode
)
begin {
if ((Test-Path -Path $Path) -eq $false) {
Write-Error -Message "Can not find $path"
break
}
}
process {
$Date = $Date | Get-Date -Format "yyyy-M-d"
$FileName = "$($date.ToString())-$($name.Replace(" ","-")).md"
$Blog = New-Object -TypeName "System.Text.StringBuilder"
[void]$Blog.Append("---`n")
[void]$Blog.Append("layout: Post`n")
[void]$Blog.Append("title: $Name`n")
[void]$Blog.Append("date: $Date`n")
[void]$Blog.Append("---`n")
[void]$Blog.Append($Content)
$Blog = $Blog.toString()
$NewBlogPath = Join-Path -ChildPath $FileName -Path $Path
Set-Content -Value $Blog -Path $NewBlogPath
Write-Output (Get-ChildItem $NewBlogPath)
if ($OpenWithCode) {
code $NewBlogPath
}
}
end {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment