Last active
January 18, 2017 19:13
-
-
Save phillipsj/559eeb7d405cf9e3a5817e7e13f44eda to your computer and use it in GitHub Desktop.
Wyam Powershell Post Creations
This file contains hidden or 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
param( | |
[string] | |
$Title, | |
[string[]] | |
$Tags | |
) | |
$name = $Title -replace "\s+","-" | |
$name = $name.ToLower() | |
$invalid = [System.IO.Path]::GetInvalidFileNameChars() | |
$regex = "[$([Regex]::Escape($invalid))]" | |
$name = $name -replace $regex,"" | |
$name = Join-Path $PSScriptRoot "drafts/${name}.md" | |
if (Test-Path $name) { | |
throw "${name} already exists" | |
} | |
$tagText = "" | |
if ($Tags) { | |
$Tags = $Tags | % { """$_""" } | |
$tagText = "[$($Tags -join ", ")]" | |
} | |
$content = @" | |
--- | |
Title: "${Title}" | |
Published: $(Get-Date) | |
Tags: ${tagText} | |
--- | |
# ${Title} | |
"@ | |
Set-Content -Path $name -Value $content |
This file contains hidden or 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
# Borrowed From https://github.com/wekempf/wekempf.github.io/blob/develop/New-Post.ps1 | |
param( | |
[string] | |
$Title, | |
[string[]] | |
$Tags | |
) | |
$name = $Title -replace "\s+","-" | |
$name = $name.ToLower() | |
$invalid = [System.IO.Path]::GetInvalidFileNameChars() | |
$regex = "[$([Regex]::Escape($invalid))]" | |
$name = $name -replace $regex,"" | |
$name = Join-Path $PSScriptRoot "input/posts/${name}.md" | |
if (Test-Path $name) { | |
throw "${name} already exists" | |
} | |
$tagText = "" | |
if ($Tags) { | |
$Tags = $Tags | % { """$_""" } | |
$tagText = "[$($Tags -join ", ")]" | |
} | |
$content = @" | |
--- | |
Title: "${Title}" | |
Published: $(Get-Date) | |
Tags: ${tagText} | |
--- | |
# ${Title} | |
"@ | |
Set-Content -Path $name -Value $content |
This file contains hidden or 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
param( | |
[string] | |
$Title | |
) | |
# Get the draft by title. | |
$name = $Title -replace "\s+","-" | |
$name = $name.ToLower() | |
$invalid = [System.IO.Path]::GetInvalidFileNameChars() | |
$regex = "[$([Regex]::Escape($invalid))]" | |
$name = $name -replace $regex,"" | |
$fullPath = Join-Path $PSScriptRoot "drafts/${name}.md" | |
$publishedPath = Join-Path $PSScriptRoot "input/posts/${name}.md" | |
$content = Get-Content -Path $fullPath | |
$content[2]= $content[2] -replace "(Published:).*", "Published: $(Get-Date)" | |
$content | Set-Content $publishedPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment