¶ Introduction
I have a braindump that is auto generated from my Org Roam Knowledge Base. This is a short description on how it works, and some extra goodies including:
- Having only certain files be published for privacy or other use cases
- Dealing with encrypted files
- Having multiple export directories, like
/braindump
,/blog
etc.
UPDATE: I have switched to ox-hugo, therefore the exact script mentioned is obsolete. However, the newer script is very similar, and follows from the same concept.
¶ The Org Roam Knowledge Base
My Org Roam directory lives at /Files/org/roam
. It consists of:
- Normal/Unencrypted files of the format
{timestamp}-{slug}.org
- Encrypted files of the format
{timestamp}-{slug}.org.gpg
- Diary entries under
daily/
of the format{date}.org.gpg
A small preview of the root directory:
daily/
20211217171236-one_minute.org
20211217182308-exams.org
20211217185625-habits.org
20211217191703-classes.org
20211219152038-a_serious_critique_of_minecraft.org
A small preview of the daily/
directory:
2020-02-05.org.gpg
2020-02-06.org.gpg
2020-02-11.org.gpg
2020-04-06.org.gpg
2020-04-14.org.gpg
2020-04-15.org.gpg
¶ Setting What Files To Export
I use Org Mode Tags to set what files to export and where. Currently:
- Files tagged with
_public
are exported to/braindump
(This inconsistent naming is an uninteded/legacy side effect, as I hadn’t thought of also blogging from within the Org Roam Knowledge Base) - Files tagged with
_blog
are exported to/blog
Note that I prefix these with an underscore (_
), for better mental separation between normal tags and those intended to be processed using a script.
¶ The Export Script
To export the (selected) notes to my braindump and/or blog, I use the following script which uses orgparse to figure out which notes have the relevant tags:
#!/usr/bin/env python
import os
from sys import argv
import shutil
from glob import glob
from orgparse import load
roam_directory = os.path.join(os.path.expanduser("~"), "Files", "org", "roam")
roam_directory_files = glob(f'{roam_directory}/*.org')
braindump_directory = os.path.join(os.path.expanduser("~"), "Files", "org", "thecashewtrader.gitlab.io", "braindump")
blog_directory = os.path.join(os.path.expanduser("~"), "Files", "org", "thecashewtrader.gitlab.io", "blog")
for roam_directory_file in roam_directory_files:
file_path = os.path.join(roam_directory, roam_directory_file)
roam_node = load(file_path)
# You can add more tags and directories, make a single tag export to multiple directories, etc.
if "_public" in roam_node.tags:
shutil.copyfile(file_path, os.path.join(braindump_directory, os.path.basename(file_path)[15:])) # [15:] removes the timestamp
if "_blog" in roam_node.tags:
shutil.copyfile(file_path, os.path.join(blog_directory, os.path.basename(file_path)[15:])) # [15:] removes the timestamp
This script is also hosted on my scripts repository.
Note that this script won’t work out of the box for encrypted notes. You would have to first decrypt notes with filenames ending in .org.gpg
into a temporary directory, and then parse them. However, encrypting notes that you intend to publish seems futile to me, and thus I haven’t dabbled with it yet.
¶ The Website Directory
You might have noticed that the above scripts copies the notes to ~/Files/org/thecashewtrader.gitlab.io
under braindump/
and blog/
respectively. These can be customised, and will be static site generator specific. You also might want to run these files through ox-hugo
if your static site generator doesn’t support Org files. My website generation process is out of the scope of this post. You can check it out in the links section though.