Recovering my broken blog gen
As time passed by, I was left with my broken emacs configs. bnaysakya was asking me to push my configs, sadly it was not that easy, until I had this idea to re-do my configs once again from scratch. By scratch, I mean from fresh emacs setup, I used to compile it earlier, that how it all started to crash.
Today I am here, using this ubuntu:emacs from jare and able to get my configs back. No longer are the worries of stale configs and broken setup. Yes, I am composing this small post from a random container bff6ea8dc91c
If you are wondering how I got this far, here are my steps…anyone can reproduce it with ease:
- clone my configs :reiterate branch
start your container: I am heavily depending on jare’s container images here
emacs_me(){ EMACS_I_WANT_TO_USE=${EMACS_DOCKER_IMAGE:-jare/emacs} BLOG_CONTENTS_INSIDE_EMACS=/home/emacs/blog_contents/ docker run -ti --rm \ --name $(echo ${EMACS_I_WANT_TO_USE}|shasum |cut -d' ' -f1) \ -e HUGO_CONTENT_PROJECT_DIR=$BLOG_CONTENTS_INSIDE_EMACS/ \ -e DISPLAY="unix$DISPLAY"\ -e UNAME="emacser"\ -e GNAME="emacsers"\ -e UID="1000"\ -e GID="1000"\ -v /tmp/.X11-unix:/tmp/.X11-unix:ro \ -v ~/.emacs.docker:/home/emacs/.emacs.d \ -v ~/.gitconfig:/home/emacs/.gitconfig \ -v $MY_HUGO_CONTENT_PROJECT_DIR:$BLOG_CONTENTS_INSIDE_EMACS \ "$EMACS_I_WANT_TO_USE" emacs ${DEBUG_FLAG} }
export your hugo project dir, where your markdown resides
export HUGO_CONTENT_PROJECT_DIR=/path_to_my/hugo/markdown_files/content/
start your function
export EMACS_DOCKER_IMAGE=jare/emacs:latest DEBUG_FLAG='--debug-init'; emacs_me
I am assuming you have few things here:
- you have played with docker earlier, good internet bandwidth
- you know how to modify the
emacs_me
script above - you know the debug steps
- yes, you are in linux machine ;) else good luck figuring out the way to share you X resource
History of it all
my old posts, where I found hugo and learnt to glue it with org-mode.
Before hugo
i was like:
- days spent saying “I will blog soon”
- since org mode is soo adivtive, I need to find sth that floats with it
- @rhoit dai started making bekar-static-gen, but i no nothing about html/css stuffs, so i stay in shadow
- again after month, I started publishing org to html, it was ok, but I guessed I couldn’t scale, so again stopped
- again, found a emacs guy using tikerer to publish his blog; got exicited 😃 and started tinkerering myself. It was like :feelsgoodman: feeling. But static stuffs broke, and I felt 😞 again… still was pushing some orgs… reached upto 3 posts and kinda stopped.
then
HUGO
happened… Not sure, but its what I was looking for… I was having +ve intutions. #few storiesAfter few hrs, i tried this blog. And here I am, semi-ready to publish this post 😥.
few helps from hugo, making the org2blog2github workflow easier.
Thanks to all for sharing your knowledge on this thing called internet and obviously the makers of HUGO. 🤗
Rest of story on how to make emacs, a blog generator. Everything is copied blindly from Holger Schurig’s Blog. ☕ for him.
Define content dir
;; This is GPLv2. If you still don't know the details, read
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
(defvar hugo-content-dir (getenv "HUGO_CONTENT_PROJECT_DIR")
"Path to Hugo's content directory")
The next two functions care that all needed property drawers exist
;; This is GPLv2. If you still don't know the details, read
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
(defun hugo-ensure-property (property)
"Make sure that a property exists. If not, it will be created.
Returns the property name if the property has been created,
otherwise nil."
(if (org-entry-get nil property)
nil
(progn (org-entry-put nil property "")
property)))
(defun hugo-ensure-properties ()
"This ensures that several properties exists. If not, these
properties will be created in an empty form. In this case, the
drawer will also be opened and the cursor will be positioned
at the first element that needs to be filled.
Returns list of properties that still must be filled in"
(require 'dash)
(let ((current-time (format-time-string (org-time-stamp-format t t) (org-current-time)))
first)
(save-excursion
(unless (org-entry-get nil "TITLE")
(org-entry-put nil "TITLE" (nth 4 (org-heading-components))))
(setq first (--first it (mapcar #'hugo-ensure-property '("HUGO_TAGS" "HUGO_TOPICS" "HUGO_FILE"))))
(unless (org-entry-get nil "HUGO_DATE")
(org-entry-put nil "HUGO_DATE" current-time)))
(when first
(goto-char (org-entry-beginning-position))
;; The following opens the drawer
(forward-line 1)
(beginning-of-line 1)
(when (looking-at org-drawer-regexp)
(org-flag-drawer nil))
;; And now move to the drawer property
(search-forward (concat ":" first ":"))
(end-of-line))
first))
Github flavoured markdown
(use-package ox-gfm
:config
(require 'ox-gfm))
Hugo function to blog all the things
;; This is GPLv2. If you still don't know the details, read
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
(defun hugo ()
(interactive)
(unless (hugo-ensure-properties)
(let* ((title (concat "title = \"" (org-entry-get nil "TITLE") "\"\n"))
(date (concat "date = \"" (format-time-string "%Y-%m-%d" (apply 'encode-time (org-parse-time-string (org-entry-get nil "HUGO_DATE"))) t) "\"\n"))
(topics (concat "topics = [ \"" (mapconcat 'identity (split-string (org-entry-get nil "HUGO_TOPICS") "\\( *, *\\)" t) "\", \"") "\" ]\n"))
(tags (concat "tags = [ \"" (mapconcat 'identity (split-string (org-entry-get nil "HUGO_TAGS") "\\( *, *\\)" t) "\", \"") "\" ]\n"))
(fm (concat "+++\n"
title
date
tags
topics
"+++\n\n"))
(file (org-entry-get nil "HUGO_FILE"))
(coding-system-for-write buffer-file-coding-system)
(backend 'md)
(blog))
;; try to load org-mode/contrib/lisp/ox-gfm.el and use it as backend
(if (require 'ox-gfm nil t)
(setq backend 'gfm)
(require 'ox-md))
(setq blog (org-export-as backend t))
;; Normalize save file path
(unless (string-match "^[/~]" file)
(setq file (concat hugo-content-dir file))
(unless (string-match "\\.md$" file)
(setq file (concat file ".md")))
;; save markdown
(with-temp-buffer
(insert fm)
(insert blog)
(untabify (point-min) (point-max))
(write-file file)
(message "Exported to %s" file))
))))
Binding the key
(bind-key "M-g h" #'hugo)