Skip to content

Instantly share code, notes, and snippets.

@phillipsj
Last active January 18, 2017 19:13
Show Gist options
  • Save phillipsj/559eeb7d405cf9e3a5817e7e13f44eda to your computer and use it in GitHub Desktop.
Save phillipsj/559eeb7d405cf9e3a5817e7e13f44eda to your computer and use it in GitHub Desktop.
Wyam Powershell Post Creations
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
# 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
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