Skip to content

Instantly share code, notes, and snippets.

@dealingwith
Last active April 18, 2021 22:53
Show Gist options
  • Save dealingwith/baed8abe1ce1413cb7b897c32c4aa74d to your computer and use it in GitHub Desktop.
Save dealingwith/baed8abe1ce1413cb7b897c32c4aa74d to your computer and use it in GitHub Desktop.
Create a new Jekyll post with Script Kit
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`)
@dealingwith
Copy link
Author

Replaces my old new_post Rake task, with the added benefit of opening the post in a dedicated VS Code window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment