Exporting content from org-roam to arbitrary org files
I adopted org-roam to collect and manage my personal notes. I also use Org for managing the pages of my personal website (this site). My notes are mostly personal, as I said, but sometimes I want to publish them on the website.
So far the process has been manual: when I had significant updates to publish I just copied text from one org file (in org-roam) to another. But I wanted something more systematic.
I therefore added this two functions in my Emacs configuration
(defun my/remove-org-roam-links (buffer-as-string)
(replace-regexp-in-string
"\\[\\[id:.*\\]\\[\\(.*\\)\\]\\]" "\\1" buffer-as-string))
(defun my/paste-org-roam-node (initial-input &key no-links)
(interactive)
(let* ((file (org-roam-node-file (org-roam-node-read initial-input)))
(raw-buffer (with-current-buffer (find-file-noselect file)
(goto-char (point-min))
(buffer-string))))
(if no-links (my/remove-org-roam-links raw-buffer)
raw-buffer)))
Then I can use a snippet like this in the destination buffer
#+begin_src emacs-lisp :results value raw append (my/paste-org-roam-node "through" :no-links t) #+end_src
And this appends to the file the contents of the original org-roam note (I happen to have a note titled "Through the Language Glass", so that 'through' is enough to identify a node), after stripping, if requested, the links to other notes.
There's still some manual work to do before one can post, but this solution is already an useful improvement.
TODO
[ ]the operation is not idempotent[ ]org-roam-node-readstill requires the user to hit return in the minibuffer to confirm the choice. I'd rather have no interaction after invoking the command byC-C C-C[ ]after the note content is appended to the file, there's some clean up to do: removing unwanted metadata from the original buffer, and so on…[ ]it seems there are problems with the management of footnotes, if present in the original note