Skip to content

Instantly share code, notes, and snippets.

@thunderrabbit
Last active July 8, 2017 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thunderrabbit/b6a3d157fd4a916d23bea75f1d10b58f to your computer and use it in GitHub Desktop.
Save thunderrabbit/b6a3d157fd4a916d23bea75f1d10b58f to your computer and use it in GitHub Desktop.
Would like to specify multiple tags
(defvar journal-site-location "~/journal/"
"The location of the journal files.")
(defun journal-new-post (title tags yyyy mm dd)
"Create a new journal post for today with TITLE and TAG."
(interactive (list
(read-string "Title: ")
(journal-read-tags)
(read-string (format "Year (%s): " (format-time-string "%Y")) nil nil (format-time-string "%Y"))
(read-string (format "Month (%s): " (format-time-string "%m")) nil nil (format-time-string "%m"))
(read-string (format "Date (%s): " (format-time-string "%d")) nil nil (format-time-string "%d"))
)
)
(let (
(file-name (journal-post-title dd title))
(file-path (journal-post-path title yyyy mm dd))
)
(set-buffer (get-buffer-create file-path))
(insert
(format "---\ntitle: %s\ntags: [ %s, \"\" ]\nauthor: Rob Nugen\ndate: %s-%s-%sT%s\n---\n\n%s\n\n"
title
(mapconcat (lambda (x) (format "\"%s\"" (downcase x)))
tags ", ")
yyyy
mm
dd
(format-time-string "%H:%M:%S+09:00")
(format-time-string "## %H:%M %A %d %B %Y %Z")
))
(write-file
(expand-file-name file-path (concat journal-site-location "")))
(switch-to-buffer file-name)
(auto-fill-mode)
)
)
(defun journal-read-tags ()
(let (tags tag done)
(while (not done)
(setq tag (read-string "Tag: "))
(if (= (length tag) 0)
(setq done t)
(push tag tags)))
(nreverse tags)))
(defun journal-post-title (dd title)
"Return a file name based on TITLE for the post."
(concat dd
(url-safe-string title)
".md"))
(defun url-safe-string (title)
"Return a URL-safe title based on TITLE."
(replace-regexp-in-string "[:!']" ""
(replace-regexp-in-string " " "-" (downcase title))
)
)
(defun journal-post-path (title yyyy mm dd)
"Return a file path based on TITLE and date."
(concat
yyyy "/" mm "/" dd
(url-safe-string title)
".md"))
(global-set-key (kbd "C-c j") 'journal-new-post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment