shaz.io

One-click draft blog post in Github (for Eleventy)

Feb 05, 2022
1 minute

In Github, you can create new files via a url link, and thus we can create new blog posts easily in Eleventy.

For a draft post, you will need these two keys and values in the front matter:

---
eleventyExcludeFromCollections: true
permalink: false
---

Format

The format for creating a new file is thus:
https://github.com/USER_OR_ORG/REPO_NAME/new/BRANCH?value=SOME_VALUE&filename=FILE_PATH/FILE_NAME.md

Substitute the upper-case values accordingly.

To fill in SOME_VALUE with the front matter needed for a draft blog post, we have to URI encode this:

---
eleventyExcludeFromCollections: true
permalink: false
title: your title here
---

Your draft text here.

into this:
---%0AeleventyExcludeFromCollections:%20true%0Apermalink:%20false%0Atitle:%20your%20title%20here%0A---%0A%0AYour%20draft%20text%20here.

How

Use the encodeURI function to encode the text. Then take this value and substitute SOME_VALUE with it, construct the url, then save it as a bookmark.

You can even assign a hotkey for it, see this method.

Credits

  • Reuben L. Lillie - for the url formatting code for Eleventy, so the long urls above will wrap nicely in the browser.
  • Peter deHaan - for the two front-matter keys and values to make a post in “draft mode”