Create a new blog post in powershell

A function to help creating a blog post
tips
powershell
quarto
Author
Published

July 4, 2023

Currently there is no straightforward way to create a blog post with Quarto. There is a feature request to add something like quarto create post.

Here is a quick powershell script that you can use to create a basic scaffolding for a blog post.

function NewBlogPost () {
  $arg = Read-Host - Prompt 'Enter title for the post'
  $title = ($arg.Replace(' ', '-')).ToLower()
  $today = Get-Date -Format "yyyy-MM-dd"
  $Folder = "$today-$title"

  $Folder = $Folder.Split([IO.Path]::GetInvalidFileNameChars()) -join ''

  $null = New-Item -ItemType Directory -Path $Folder

  # Add index.qmd file to the folder
  $metadata = @"
---
title: $arg
description: 
date: $today
categories: 
  - blog
image: 
image-alt: 
--- 
"@

  $filename = "$($Folder)\index.qmd"
  Add-Content -Value $metadata -Path $filename

  Write-Output "Created $Folder/index.qml with following metadata."
  Write-Output $metadata
}

Add the script to your powershell profile by editing the file “Microsoft.PowerShell_profile.ps1”. This file is usually located in the Documentsfolder. It will create a function called NewBlogPost. You can also add an alias Set-Alias nbp NewBlogPost. Next time you start powershell, you should be able to write nbp at the command prompt and write post title to create a new post.

Create blog post

Citation

BibTeX citation:
@online{utikar2023,
  author = {Utikar, Ranjeet},
  title = {Create a New Blog Post in Powershell},
  date = {2023-07-04},
  url = {https://smilelab.dev//blog/posts/2023-07-04-create-a-new-blog-post-in-powershell},
  langid = {en}
}
For attribution, please cite this work as:
Utikar, R. Create a new blog post in powershell. https://smilelab.dev//blog/posts/2023-07-04-create-a-new-blog-post-in-powershell (2023).