Created
July 8, 2017 05:07
-
-
Save thunderrabbit/dbda087547e49c5e92849d99c0d92a67 to your computer and use it in GitHub Desktop.
Would like to specify multiple tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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: ") | |
(read-string "Tag: ") | |
(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 | |
(downcase 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-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