Last active
November 20, 2017 04:29
-
-
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.
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
[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