2022-07-27

I kicked this off with a bookmarklet of my own design!

This is a stupid fun idea I’ve had through many iterations of my site. Ever since the source of truth was a GitHub repository, as best as I remember. I finally got around to building it. A bespoke bookmarklet to begin authoring quick’ish entries.

It determines the current date with rudimentary timezone awareness. It prompts for a starting title. Then the big reveal! It opens a new window pointed at GitHub’s “create new file” page to the exact path of the markdown file I want to create. With the YAML frontmatter pre-populated.

That’s pretty neat.

Here’s the source:

var date = new Date()
date.setHours(date.getHours() - date.getTimezoneOffset() / 60)
date = date.toISOString().split("T").at(0)
var title = window.prompt("What's a good starter title?")
var filename = "content/blog/" + date + ".md"
var value = "---\ntitle: " + title + "\ndate: " + date + "\n---\n\n"
var url = new URL("https://github.com/danott/www.danott.co/new/main")
url.searchParams.append("filename", filename)
url.searchParams.append("value", value)
window.open(url)

And here it is as a link I can drag-and-drop into my browser’s bookmarks bar to create a new blog entry.

I used bookmarklets.org for the “compilation”. The tool seems dated, with lack of support for some modern JavaScript features like template literals. Whatever. It works fine and I’ll rarely have to change it.