Publishing portions of my org-roam database

Related blog post: Publishing portions of my Org-roam database – Jack Baty

I keep all of the Org-roam notes I’d like to share in a public/ subdirectory of my main Org-roam directory. To make creating these files easier, I have the following capture template for Org-roam:

1
2
3
4
5
6
    ("P"                                               ;; Key
     "Public (published in /public)"                   ;; Description
     plain                                             ;; Type
     (file "~/org/roam/templates/PublicTemplate.org")  ;; Template
    :target (file "public/${slug}.org")                ;; Target
    :unnarrowed t)

This does a few things. First, it tells Org-roam to put the new file in the public/ folder. Second, it sets the filename to a simpler version with only the “slug” rather than including the long datestamp I use for “normal” Org-roam files. Third, it uses a template file to use as the initial content.

Here’s the PublicTemplate.org file:

1
2
3
4
5
6
7
8
#+title: ${title}
#+filetags:
#+index:
#+setupfile: ~/org/_SETUP/org-roam-publish-fancy.setup
#+date: %u
#+options: toc:nil

%?

To make setting the default ox-hugo variables easier, I created a file named .dir-locals.el in the public/ folder.

1
2
3
4
5
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

((org-mode . ((org-hugo-section . "post")
              (org-hugo-base-dir . "~/sites/org-roam/"))))

This sets up the required variables for publishing using ox-hugo . Now, whenever I want to publish a file from my Org-roam database, I export the file using ox-hugo via Org’s built-in org-export-dispatch

The exported file is put into org-hugo-base-dir in the org-hugo-section folder. From there it’s just another Markdown post in the Hugo site’s content directory. Hugo takes it from there. I have a Makefile that runs hugo and rsyncs the resulting website up to the server, where you’re reading it right now.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
SERVER_HOST=server01.baty.net
SERVER_DIR=/home/jbaty/apps/notes.baty.net/public_html
PUBLIC_DIR=/Users/jbaty/sites/org-roam/public/
TARGET=server01.baty.net

.POSIX:
.PHONY: build checkpoint deploy



build:
	hugo

checkpoint:
	git add .
	git diff-index --quiet HEAD || git commit -m "Publish checkpoint"

deploy: build checkpoint
	#git push
	@echo "\033[0;32mDeploying updates to $(TARGET)...\033[0m"
	rsync -v -rz --checksum --delete --no-perms $(PUBLIC_DIR) $(SERVER_HOST):$(SERVER_DIR)

One caveat I’m running into is that internal (Org-roam) links are not exported, leaving gaps in the text. It may be possible to write an export filter function but I have no idea how to do that.