A Productive Morning
Writing some PowerShell to make a 5 minute job take mere moments.
https://guides.18f.gov/engineering/languages-runtimes/css/
Up early for no reason, or at least no reason I want to get into, and thinking about how to update while away from my desk.
Rather than copy-and-paste a week's worth of files to save as drafts, I had the idea to write a script to create a month's worth of drafts. And, by write a script, I do, of course, mean cobble together a few Stack Overflow answers.
# Get Year and Month, defaulting to current year and month
param(
[int]$Year = [datetime]::Now.Year,
[int]$Month = [datetime]::Now.Month
)
# Frontmatter with a paramter to fill the date in later
$Template =
@"
---
draft: true
title:
description:
date: {0}
---
"@
# Create new array with numbers from 1 to DaysInMonth
1..([datetime]::DaysInMonth($Year, $Month)) |
# For each element in array
ForEach-Object {
# Generate name for new file in YYYY-MM-DD format
# To do so, we create new DateTime Object with day from pipeline and year and month from above
$Date = ([datetime]::ParseExact("$_/$Month/$Year", 'd/M/yyyy', [System.Globalization.CultureInfo]::InvariantCulture)).ToString('yyyy-MM-dd')
$FileName = $Date + ".md"
# Correctly join path with current directory and new file name
$Path = Join-Path -Path (Get-Location).Path -ChildPath "\content\blog\"$FileName
# IF the file exists, move on to the next day
if (Test-Path $Path -PathType Leaf) {
# You'd think this should be continue. I did. Since this block is
# actually an anonymous function being run on each object in the
# foreach collection separately, the correct answer is return.
return
}
$Content = $Template -f $Date
# Create new file
New-Item -ItemType File -Path $Path -Value $Content
}
About the -f
operator in PowerShell
https://ss64.com/ps/syntax-f-operator.html
Next step is to find a way to edit and push from my phone, but that's not looking like it will be a cake walk.
https://pixeljets.com/blog/poor-mans-sre/
https://japanese-creative-books.com/product/illustration/houses-with-a-story/
https://visualstudiomagazine.com/Articles/2024/03/20/autodev.aspx
Can I edit and push from the GitHub app?
Current Status:
https://learnbyexample.github.io/substitution-with-ripgrep/
https://thehtml.review/03/
- Previous: It's Too Bad She Won't Live
- Next: Busted on the Second Game