Create a new Jekyll post with Script Kit

For years I've used Rake tasks to manage my Jekyll blog writing & publishing flow. I'm starting to migrate those to Kit. They were stolen from an old version of Octopress which itself hasn't had an update in five years, so it's time.

Here's the first, which creates a new Jekyll post. I figure this might be useful to others new to Kit who want to do stuff with files or using static site generators.

let {format} = await npm('date-fns')
let title = await arg('Name of post')
let file_title = title.toLowerCase().replaceAll(' ', '-')
let posts_path = '/Users/danielmiller/code/daniel-industries/_posts/'
let date = new Date()
let date_for_path = format(date, 'yyyy-MM-dd')
let date_for_yml = format(date, 'yyyy-MM-dd hh:mm:ss z')
let file_path = posts_path + date_for_path + '-' + file_title + '.markdown'
let file_contents = `---
layout: post
title: "${ title }"
excerpt:
date: ${ date_for_yml }
categories:
---
`
writeFile(file_path, file_contents)
exec(`code ${file_path} --new-window`)

The last line is a nice bonus I gave myself, opening the new file in a dedicated VS Code window.