Recently, I chose to revamp this website using Hugo, due to its relative ease of use and its native support for Org Mode files. Since I have been using Org-roam to manage my personal knowledge base, I thought it would be useful to be able to write blog posts directly as Org-roam notes.
By default, Hugo and Org-roam use incompatible tagging systems. Hugo's tag system expects a #+tags[]:
property in the front matter, while Org-roam expects a #+roam_tags:
property.
This is a relatively easy problem to solve. According to Org-roam's documentation, file tag extraction can be customized. Since #+tags[]:
and #+roam_tags:
can be used in a compatible manner (avoid using whitespace in tags), we can copy the default #+roam_tags:
handler (#+org-roam--extract-tags-prop
) and tweak it to look for #+tags[]:
instead.
;; Based on code from Org-roam, licensed under GNU GPLv3 or higher.
;; This code is distributed without any warranty.
;; https://github.com/org-roam/org-roam/blob/master/org-roam.el
(defun org-roam--extract-tags-hugo (_file)
"Extract tags from the current buffer's \"#+tags[]\" global property."
(let* ((prop (or (cdr (assoc "TAGS[]" (org-roam--extract-global-props '("TAGS[]"))))
"")))
(condition-case nil
(split-string-and-unquote prop)
(error
(progn
(lwarn '(org-roam) :error
"Failed to parse tags for buffer: %s. Skipping"
(or org-roam-file-name
(buffer-file-name)))
nil)))))
Now all we have to do is append hugo
to the org-roam-tag-sources
list.
(custom-set-variables
'(org-roam-tag-sources '(prop hugo)))
By default, Hugo ignores #+roam_tags:
properties in the front matter, which means we can use them to add tags we don't want to export. For example, I prepend blog posts with #+roam_tags: blog
so that I can filter them while using Org-roam Server.