Asgardian's Blog

Create a blog entry file.

I write my posts with Emacs and org-mode. Org-mode and Emacs are very powerfull and customizable.

I recently discovered a very complete and easy to use templating engine, tempel.

I write a template with all properties needed by Pelican.

I my template file, I add this folowing lines.

(blog "#+TITLE: " p n
      "#+DATE: " (format-time-string "%Y-%m-%d %H:%M:%S") n
      "#+CATEGORY: " p n
      "#+AUTHOR: " (format "%s" user-nickname)
      "#+PROPERTY: LANGUAGE EN" n
      "#+PROPERTY: SUMMARY " p n
      "#+PROPERTY: SLUG " n
      "#+PROPERTY: MODIFIED " n
      "#+PROPERTY: TAGS " p n
      "#+PROPERTY: STATUS draft" n n
      )

When, you execute this tempalte with Meta-+ for example. The cursor is placed just after TITLE. When you hit Meta-}, the cursor go to after CATEGORY and so on. Some fields are automatically completed :

  • DATE with the date of the day in format YYYY-MM-DD hh:mm:ss.
  • Author with the value of user-nickname.

I wrote two tiny functions :

  • capture-blog-entry-file who ask the name of the post. This name is not really the name of the file because, I will use the creation date. So for a post named blog entry, the will be named 20221110204243-blog entry-EN.org
(defun capture-blog-entry-file ()
  "Capture the full path name of th entry."
  (interactive)
  (let ((name (read-string "Name: ")))
    (expand-file-name(format "%s-%s.org"
                             (format-time-string "%Y%m%d%H%M%S")
                             name) blog-content-directory)
    )
  )
  • capture-blog-entry just call capture-blog-entry-file and the tempel command tempel-insert with the template name as parameter.
(defun capture-blog-entry ()
  "Capture a new blog entry"
  (interactive)

  (find-file (capture-blog-entry-file))
  (tempel-insert 'blog)
  )

To be more clean, I create a variable blog-content-directory to stock the path to create the post file.

(defvar blog-content-directory nil
  "The locatlization of your posts in your blog engine tree.")

(setq blog-content-directory "~/the/path/where/save/your/post")

It's not a complex development but these functions are practical and allow you to focus on writing your article.

I will create others functions like this to give me more little help.