💾 Archived View for epi.benthic.zone › posts › 2021-07-27_PublishingDrafts.gmi captured on 2022-03-01 at 15:25:19. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-11-30)
-=-=-=-=-=-=-
2021-07-27
One of the fun parts about putting together this Gemini capsule has been hacking together a kind of static site generator in Emacs using org-mode. Org-mode has basically everything you need through its publishing functionality, and the ox-gemini plugin turns org files into gemtext for me.
I've been writing drafts of posts in a special "drafts/" directory that is excluded from publishing. When I am ready to publish a draft, I just copy it to my "posts/" directory and change the filename so that it has the right date. This is kind of annoying to do by hand, so I thought I would try scripting it in Emacs.
The basic function that I came up with is
(defun benthic-zone-publish-draft () (interactive) (let* ((draft (buffer-file-name)) (post (benthic-zone-draft-to-post-name draft benthic-zone-posts-directory))) (write-file post) ) )
This function is meant to be called interactively from within a draft buffer. It basically takes the file name of the buffer that I am currently visiting and constructs a file name with the current date using
(defun benthic-zone-draft-to-post-name (draft dir) (let ((date (format-time-string "%F")) (filename (file-name-nondirectory draft)) ) (concat dir "/" date "_" filename) ) )
which creates an ISO 8601 date string and then appends the date in front of the draft's filename. You also pass the path of the posts directory, and the desired absolute path of the new post is returned. I added a global variable `benthic-zone-posts-directory` that holds the path to the posts directory on my local machine.
Once we have the new filename,
(write-file post)
writes the current buffer to the new file and visits it. I'm not so sure that's the best thing to do, because it means that you lose the buffer holding the draft org file, so I might change that in the future after I've used it a few times.
Pretty simple, but it works (this is the first post published from my drafts using my new function), and it was fun to figure out.