-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_post.ps1
More file actions
58 lines (43 loc) · 1.87 KB
/
create_post.ps1
File metadata and controls
58 lines (43 loc) · 1.87 KB
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
57
58
# GitHub Copilot prompt I used to generate this script:
# Write a Powershell script to create a starting point for a blog post.
# The post is stored in folder "docs/posts/{year}/{month}/{day}" .
# Create the folder, then in that folder create a markdown file called "index.md".
# At the top of the file create a yaml block with title and date.
# I needed to unquote the date, and add the Out-Null to the New-Item command.
# update... use the current date to get the next Tuesday, and create the folder for that date.
# Get the current date
$currentDate = Get-Date
# Calculate days to Tuesday (Tuesday is 2 in DayOfWeek enum, 0-6 for Sunday-Saturday)
$daysToTuesday = (2 - [int]$currentDate.DayOfWeek + 7) % 7
# If today is Tuesday, we want same day, so adjust if result is 7
if ($daysToTuesday -eq 7) { $daysToTuesday = 0 }
# Get Tuesday's date
$tuesdayDate = $currentDate.AddDays($daysToTuesday)
$year = $tuesdayDate.Year
$month = $tuesdayDate.Month.ToString("D2")
$day = $tuesdayDate.Day.ToString("D2")
# Define the folder path
$folderPath = "docs/posts/$year/$month/$day"
# Create the folder if it doesn't exist
if (-Not (Test-Path -Path $folderPath)) {
New-Item -ItemType Directory -Path $folderPath -Force | Out-Null
}
# Define the file path
$filePath = "$folderPath/index.md"
# Create the markdown file with YAML front matter
$title = "Your Blog Post Title"
$date = $tuesdayDate.ToString("yyyy-MM-dd")
$yamlContent = @"
---
title: "$title"
date: $date
authors:
- chris | norm | omar
---
TOPIC_INTRODUCTION_HERE
Everyone and anyone are welcome to [join](https://weeklydevchat.com/join/) as long as you are kind, supportive, and respectful of others. Zoom link will be posted at 12pm MDT.

"@
# Write the content to the file
Set-Content -Path $filePath -Value $yamlContent
Write-Output "Blog post template created at $filePath"