From e2c475542616c33d92067b21782a441dd396bd32 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 12 Nov 2017 23:48:12 +0100 Subject: [PATCH 01/12] chore: Initial commit From 3d4aba1803930453f1942b0e1b1648309c2da88b Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 12 Nov 2017 23:48:21 +0100 Subject: [PATCH 02/12] feat(blog): Add initial elblog implementation Implements a (very) simple "blogging" software in Emacs Lisp using org-mode and elnode. Once loaded and started, elblog will serve individual blog posts at `localhost:8010/en/$post-name`, where "post-name" can be any string. Elblog will attempt to find a buffer called "$post-name.org" and render it to HTML. An index of blog posts is currently not implemented and everything is completely unthemed, but for a language this old this is ridiculously productive given the amount of code. --- blog.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 blog.el diff --git a/blog.el b/blog.el new file mode 100644 index 000000000..0407f98c6 --- /dev/null +++ b/blog.el @@ -0,0 +1,49 @@ +;;; blog.el --- A simple org-mode & elnode blog software. +;;; -*- lexical-binding: t; -*- + +(require 'elnode) +(require 'f) + +(defun render-org-buffer (buffer &optional force) + "Renders an org-mode buffer as HTML and returns the name of the output buffer." + (letrec ((input-buffer (get-buffer buffer)) + (output-buffer (concat buffer "-rendered")) + ;; Don't re-render articles unless forced. + (must-render (or force + (not (get-buffer output-buffer))))) + (if (and input-buffer must-render) + (with-current-buffer input-buffer + (org-export-to-buffer 'html output-buffer nil nil t))) + (if input-buffer output-buffer nil))) + +(defun get-buffer-string (buffer) + "Returns the contents of the specified buffer as a string." + (with-current-buffer (get-buffer buffer) + (buffer-string))) + +(defvar-local article-not-found + '(404 . "

Oh no, the article was not found.

")) + +(defvar-local text-html '("Content-Type" . "text/html")) + +(defun render-article (article) + "Renders an article, if it exists." + (let ((output-buffer (render-org-buffer (concat article ".org")))) + (if output-buffer `(200 . ,(get-buffer-string output-buffer)) + article-not-found))) + +(defun blog-post-handler (httpcon) + "This handler servers a blog post from the configured blog post directory." + (let ((response (render-article (elnode-http-mapping httpcon 1)))) + (elnode-http-start httpcon (car response) text-html) + (elnode-http-return httpcon (cdr response)))) + +(defvar-local elblog-routes + '(("^.*//en/\\(.*\\)" . blog-post-handler))) + +(defun elblog-handler (httpcon) + (elnode-hostpath-dispatcher httpcon elblog-routes)) + +(elnode-start 'elblog-handler + :port 8010 + :host "localhost") From 4902e9c26cb100719506fe241fecd718c871de0b Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 12 Nov 2017 23:56:27 +0100 Subject: [PATCH 03/12] feat(blog): Add interactive start/stop functions --- blog.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/blog.el b/blog.el index 0407f98c6..4e7cf91d8 100644 --- a/blog.el +++ b/blog.el @@ -44,6 +44,12 @@ (defun elblog-handler (httpcon) (elnode-hostpath-dispatcher httpcon elblog-routes)) -(elnode-start 'elblog-handler +(defun start-elblog () + (interactive) + (elnode-start 'elblog-handler :port 8010 - :host "localhost") + :host "localhost")) + +(defun stop-elblog () + (interactive) + (elnode-stop 8010)) From ba01528a77ad265567b93bb7ba47383cc10be483 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 12 Nov 2017 23:57:51 +0100 Subject: [PATCH 04/12] docs: Add initial README --- .gitignore | 1 + README.md | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..c531d9867 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.elc diff --git a/README.md b/README.md new file mode 100644 index 000000000..994b1138e --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +elblog +====== + +This is a simple blogging software written in Emacs Lisp. + +The idea is that it should be able to do most of the things [my actual blog][] +does at the moment. + +No documentation exists for now besides the commit messages, but it works! + +[my actual blog]: https://www.tazj.in/ From b4dad1526d7a68ca089a22bf01fffa65abc9c5d9 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 13 Nov 2017 00:16:26 +0100 Subject: [PATCH 05/12] feat(blog): Add customization group for configuring elblog settings Adds a customization group which can currently be used to configure the host and port that elblog should run on. --- blog.el | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/blog.el b/blog.el index 4e7cf91d8..20f141fe4 100644 --- a/blog.el +++ b/blog.el @@ -4,6 +4,24 @@ (require 'elnode) (require 'f) +;; Definition of customization options + +(defgroup elblog nil + "Configuration for the Emacs Lisp blog software" + :link '(url-link "https://github.com/tazjin/elblog")) + +(defcustom elblog-port 8010 + "Port to run elblog's HTTP server on" + :group 'elblog + :type 'integer) + +(defcustom elblog-host "localhost" + "Host for elblog's HTTP server to listen on" + :group 'elblog + :type 'string) + +;; Article fetching & rendering functions + (defun render-org-buffer (buffer &optional force) "Renders an org-mode buffer as HTML and returns the name of the output buffer." (letrec ((input-buffer (get-buffer buffer)) @@ -38,6 +56,8 @@ (elnode-http-start httpcon (car response) text-html) (elnode-http-return httpcon (cdr response)))) +;; Web server implementation + (defvar-local elblog-routes '(("^.*//en/\\(.*\\)" . blog-post-handler))) @@ -47,9 +67,9 @@ (defun start-elblog () (interactive) (elnode-start 'elblog-handler - :port 8010 - :host "localhost")) + :port elblog-port + :host elblog-host)) (defun stop-elblog () (interactive) - (elnode-stop 8010)) + (elnode-stop elblog-port)) From 040c3487805be38e013934fddf17ec86b5bd7a89 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 13 Nov 2017 00:57:20 +0100 Subject: [PATCH 06/12] feat(blog): Configure org-mode's HTML export to match blog theme This gets elblog close, but not quite there, to my previous blog theme. Comparison screenshot: http://i.imgur.com/UK49Fhi.png --- blog.css | 37 +++++++++++++++++++++++++++++++++++++ blog.el | 14 +++++++++++++- postamble.html | 9 +++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 blog.css create mode 100644 postamble.html diff --git a/blog.css b/blog.css new file mode 100644 index 000000000..842da656b --- /dev/null +++ b/blog.css @@ -0,0 +1,37 @@ + diff --git a/blog.el b/blog.el index 20f141fe4..accfda078 100644 --- a/blog.el +++ b/blog.el @@ -20,6 +20,17 @@ :group 'elblog :type 'string) +;; org-mode settings need to be configured a certain way for elblog's HTML +;; templating to work correctly. +(defun configure-org-html-export () + (setq org-html-postamble t) + (setq org-html-doctype "html5") + (setq org-html-head-include-scripts nil) + (setq org-html-style-default (f-read-text "blog.css")) + (setq org-html-preamble-format + '(("en" "

Tazjin's blog


"))) + (setq org-html-postamble-format `(("en" ,(f-read-text "postamble.html"))))) + ;; Article fetching & rendering functions (defun render-org-buffer (buffer &optional force) @@ -46,7 +57,7 @@ (defun render-article (article) "Renders an article, if it exists." - (let ((output-buffer (render-org-buffer (concat article ".org")))) + (let ((output-buffer (render-org-buffer (concat article ".org") t))) (if output-buffer `(200 . ,(get-buffer-string output-buffer)) article-not-found))) @@ -66,6 +77,7 @@ (defun start-elblog () (interactive) + (configure-org-html-export) (elnode-start 'elblog-handler :port elblog-port :host elblog-host)) diff --git a/postamble.html b/postamble.html new file mode 100644 index 000000000..16a26218a --- /dev/null +++ b/postamble.html @@ -0,0 +1,9 @@ +
+ From 07583c2b1946811ca5bee5f5ef45313b03a233a7 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 13 Nov 2017 16:42:09 +0100 Subject: [PATCH 07/12] style: Allow for slightly wider page bodies --- blog.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog.css b/blog.css index 842da656b..0d021f78e 100644 --- a/blog.css +++ b/blog.css @@ -1,7 +1,7 @@