Simple export script to HTML

Hi, I’m trying to create a bare minimum export for all my roam notes using org-publish and I just can’t quite get it to work. Currently, it exports out all the pages, but not backlinks/cite lines and links. And yes my lisp skill lacking.

What I’m hoping for is a copy of what is displayed to the user, mainly the note content, backlinks with the single line where the link occurred and the cite link with the single line as well. No styling, just the bare minimum from org-publish.

Here is what I have so far:

  • emacs: 26.1
  • org-roam: 20210502.1936
  • org: 9.1.9 or 20210503

I launch the batch script with emacs --batch --load publish.el --funcall org-publish-all

And here is the contents of publish.el, obviously parts of this are ripped from other posts on this forum, mainly here.


(require 'package)
(package-initialize)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                          ("org" . "http://orgmode.org/elpa/")))

(package-refresh-contents)
(package-install 'htmlize)
(package-install 'org-roam)
(package-install 's)

(require 'ox-publish)
(require 'ox-html)
(require 'htmlize)
(require 'org-roam)
(require 's)
(require 'find-lisp)

(setq make-backup-files nil)

(defun my/org-roam--backlinks-list (file)
  (if (org-roam--org-roam-file-p file)
      (--reduce-from
       (concat acc (format "- [[file:%s][%s]]\n"
                           (file-relative-name (car it) org-roam-directory)
			                     (org-roam--get-title-or-slug (car it))))
       "" (org-roam-sql [:select [file-from] :from file-links :where (= file-to $s1)] file))
    ""))

(defun my/org-export-preprocessor (backend)
  (let ((links (my/org-roam--backlinks-list (buffer-file-name))))
    (unless (string= links "")
      (save-excursion
      	(goto-char (point-max))
      	(insert (concat "\n* Backlinks\n") links)))))

(add-hook 'org-export-before-processing-hook 'my/org-export-preprocessor)

(setq org-publish-project-alist
      '(("roam"
         :base-directory "~/org-roam/"
         :base-extension "org"
         :htmlized-source t
         :publishing-directory "~/build/"
         :recursive t
         :publishing-function org-html-publish-to-html
         :auto-sitemap t)
        ("all" :components ("roam"))))

Thanks so much for this project and any help.

1 Like

I’m currently facing the same problem… Have you been able to find a fix for it?