Comments and org-static-blog
I'm using org-static-blog to generate the contents of this site. So far I'm very happy with it, but I've gotten a few emails from readers who've wanted to comment on something I've written and they always point out that it's not easy to do. It's actually not a coincidence that it's a bit difficult!
Yesterday I came up with a way that might make is slightly easier without involving JavaScript from a 3rd party. By making use of the built-in support for adding HTML code for comments. One slight limitation is that it's a single variable holding the code, and I'd really like to allow for both
- using a link to a discussion site, e.g. reddit, as well as
- my email address
As the comment support in org-static-blog comes in the form of a single variable
this seems a bit difficult to accomplish. However, it isn't difficult at all to
do in elisp due to the power of advice-add
.
By using the following advice on org-static-blog-publish-file
(advice-add 'org-static-blog-publish-file :around (lambda (orig-fn filename &rest args) (let* ((comments-url (with-temp-buffer (insert-file-contents filename) (or (cadar (org-collect-keywords '("commentsurl"))) my-blog-default-comments-url))) (org-static-blog-post-comments (concat "Comment <a href=" comments-url ">here</a>."))) (apply orig-fn filename args))))
and defining my-blog-default-comments-url
to a mailto:...
URL I get a link
to use for commenting by either
- set
commentsurl
to point to discussion about the post on reddit, or - not set
commentsurl
at all and get themailto:...
URL.
If you look at my previous post you see the result of the former, and if you look below you see the result of the latter.