Integerating Jekyll and Octopress in Emacs
Saturday 31 December 2022

#ruby #elisp

Since I wrote this note my workflow changed drastically now I’m using Xlog a program I wrote myself

I started using emacs couple weeks ago and i have to say that i’m amazed by how this editor is working, Emacs VS VIM war isn’t coming from nowhere after all.

one thing that annoys me is that i stopped blogging for a long time, if you checked the last blog post, it’s been a year since the last one.

so I had an idea, what if i made blogging more comforting for me? maybe integerating my blogging platform (jekyll + octopress + git) to Emacs, aaaand there was a problem, the current jekyll (hyde.el) looks weired to me that i couldn’t even try to use it.

I started writing my own integeration, to create a post and publish it I can write simple functions to execute these command from Emacs into my blog directory, that’s not so hard right?

nooooo, for a ELisp noob like me it’s like hell, i had to Google how to define a variable, see? it’s hell, and i was stuck for a while untill i knew that C-x X-e doesn’t evaulate the whole buffer, yeah, I’m a total noob.

after a lot of sweat, blood and WTF moments i implemented 3 methods:

  1. the first one octopress-post is to create new post interactively and open the generated file in Emacs.
  2. octopress-dir to open _posts directory, for fast access to posts and so.
  3. octopress-build-and-deploy to build the blog with jekyll then deploy it with octopress to github pages

the 3 functions are simple implementation, you should not expect much from my Elisp code, it’s a simple straight forward implementation and there is a lot of room for enhancements.

This post is the my first post from Emacs, Hope it works, wish me luck,

Oh I forgot, here is my code, I just pasted it to my ~/.emacs and execute it
with M-x RET <function-name>

 1(defvar octopress-path "/Users/emad/bitbucket/blazeeboy")
 2(defun octopress-post (post-name)
 3  (interactive "sNew post name: ")
 4  (message "Creating new post: %s" post-name)
 5  (defvar post-path
 6    (shell-command-to-string
 7     (concat "cd " octopress-path "; octopress new post " post-name)))
 8  (find-file-existing (trim-string post-path)))
 9
10(defun octopress-dir ()
11  (interactive)
12  (find-file-existing
13   (concat octopress-path "/_posts")))
14
15(defun octopress-build-and-deploy ()
16  (interactive)
17  (async-shell-command (concat "cd " octopress-path "; jekyll build; octopress deploy")))
18
19;;; third party code
20;;; http://ergoemacs.org/emacs/modernization_elisp_lib_problem.html
21(defun trim-string (string)
22  "Remove white spaces in beginning and ending of STRING.
23White space here is any of: space, tab, emacs newline (line feed, ASCII 10)."
24  (replace-regexp-in-string "\\`[ \t\n]*" "" (replace-regexp-in-string "[ \t\n]*\\'" "" string)))

Backlinks

See Also