23maverick23/sublime-jekyll

Templates and timestamp

Fastidious opened this issue · 3 comments

How can I create a post template (or make both, default new draft and new post) with a date: header with the timestamp of the new post/draft creation?

@Fastidious Thanks for using the plugin!

As of now, the templates feature uses ST snippets which are simple text expanders. They do not support running custom code (which is required for generating a date/datetime). See this forum thread as it's been asked before: https://forum.sublimetext.com/t/easiest-way-to-insert-date-time-with-a-single-keypress/4134.

As a workaround, you could combine a template snippet with the "Insert current datetime" keybinding. Go into your Jekyll package settings and edit your User keybindings file:

{ "keys": ["ctrl+k", "ctrl+t"], "command": "jekyll_insert_date", "args": {"format": "datetime"} }

Then, in your template file, add a date key and add the snippet syntax $1 to make it the first field marker in your template (e.g. where your cursor lands first after creating a new post).

---
date: $1
layout: ${2:post}
---

You can then quickly type your datetime keybinding ctrl+k, ctrl+t to add the date, and then tab to your next field marker as needed to fill in the rest of your post content.

Awesome, that will work! Thank you for the plugin, it has made my Jekyll workflow a breeze.

Happy to help!