-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnew-blogPost.ps1
57 lines (48 loc) · 1.9 KB
/
new-blogPost.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$global:base = @"
---
title: "PostTitle"
date: "calculatedPostDate"
redirect_from : calculatedRedirect
coverImage: \assets\images\2021\trackingStates.webp
categories:
- "scripting"
tags:
calculatedPostTags
excerpt: "calculatedPostExcerpt"
fileName: 'calculatedFileName'
---
calculatedPostExcerpt
![Header for this post, reads 'How To Make GitHub Button'](\assets\images\2021\trackingStates.webp)
*Post Outline*
* What were WordPress Stats?
* Finding a way to satisfy my ego
* Automatically adding it below posts in Jekyll
* How does this compare to Google Analytics?
"@
function New-BlogPost{
<#
.EXAMPLES
New-BlogPost -postDate $targetDate `
-postTitle "Got messy Ifs Guard Clauses to the Rescue" `
-postExcerpt "Revisiting PowerShell after mostly writing nothing but c# for years, I'm finding lots of useful programming practices can make my code easier to read. In this post, we'll talk about guard clauses and how they can make your code easier to read!" `
-postTags ham,onionions,cheese,foxes | clip
#>
param($postTitle,$postDate, $postExcerpt,$postTags)
$postContent = $base
$calculatedPostTitle= $postTitle -replace " ","-"
$redirectformat = "$(get-date $postDate -UFormat %Y/%m/%d)/$($calculatedPostTitle)"
$calculatedPostDate = $postDate
$calculatedRedirect = "$redirectformat"
$calculatedPostTags = $postTags |% {"`n - `"$_`""}
$calculatedFileName = "$($postDate)-$($calculatedPostTitle.ToLower())"
$calculatedPostExcerpt = $postExcerpt
ForEach ($var in Get-Variable -Name calculated*){
$postContent = $postContent -replace $var.Name, $var.Value
}
$postContent -replace "postTitle", $postTitle
"would be created as $calculatedFileName.md"
$postContent
remove-item $calculatedFileName
new-item -Name $calculatedFileName -Value $postContent -ItemType File -force
}
$targetDate = get-date ([DateTime]::Now.AddDays(-1)) -UFormat %Y-%m-%d