From 7f37518e4792f040a753a5d8d68d51e76cc0b2be Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Sat, 13 Jul 2024 17:55:47 -0400 Subject: Initial migration to org-reader Long-term I would like to merge the =posts-assets= and =posts= directories but currently Haunt will crash if something exists in the =posts= directory that can't be processed by a reader --- haunt/jakob/reader/org-mode-prime.scm | 36 +++++++++++++++++++++++++++++++++++ haunt/jakob/reader/org-mode.scm | 12 +++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 haunt/jakob/reader/org-mode-prime.scm (limited to 'haunt/jakob/reader') diff --git a/haunt/jakob/reader/org-mode-prime.scm b/haunt/jakob/reader/org-mode-prime.scm new file mode 100644 index 0000000..118f1a6 --- /dev/null +++ b/haunt/jakob/reader/org-mode-prime.scm @@ -0,0 +1,36 @@ +;;; Copyright © 2019 - 2024 Jakob L. Kreuze +;;; +;;; This program is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see +;;; . + +;;; Commentary: +;;; +;;; Wrapper around the `org-mode-reader' to apply rewrite rules specific to my +;;; website. +;;; +;;; Code: + +(define-module (jakob reader org-mode-prime) + #:use-module (haunt reader) + #:use-module (jakob reader org-mode) + #:use-module (jakob utils sxml) + #:use-module (srfi srfi-11) + #:export (org-mode-reader-prime)) + +(define org-mode-reader-prime + (make-reader (reader-matcher org-mode-reader) + (lambda args + (let-values (((metadata sxml) (apply (reader-proc org-mode-reader) args))) + (values metadata + (rewrite-absolute-urls-as-relative sxml)))))) diff --git a/haunt/jakob/reader/org-mode.scm b/haunt/jakob/reader/org-mode.scm index 7f064f1..b55dbf3 100644 --- a/haunt/jakob/reader/org-mode.scm +++ b/haunt/jakob/reader/org-mode.scm @@ -49,6 +49,10 @@ (or (getenv "HAUNT_ORG_READER_CACHE_DIR") "./.org-mode-reader-cache/")))) +;; File name of Elisp script to execute before anything else +(define %additional-emacs-preamble + (make-parameter (getenv "HAUNT_ORG_READER_EMACS_PREAMBLE"))) + ;; Additional Org-mode keywords to include in the extracted metadata. (define %additional-keys (make-parameter '("CROSSPOST" "SCRIPTS" "META-TAGS"))) @@ -62,7 +66,13 @@ If `%use-emacsclient' is truthy, evaluate FORM in the current running Emacs daemon. Assumes that FORM does not write to `standard-output'." - (let* (;; We need to explicitly request that Emacs write the result if using + (let* (;; If `HAUNT_ORG_READER_PREAMBLE' is specified, load that. + (form (if (%additional-emacs-preamble) + `(progn + (load-file ,(%additional-emacs-preamble)) + ,form) + form)) + ;; We need to explicitly request that Emacs write the result if using ;; Emacs batch mode (which is how we evaluate forms without ;; `emacsclient'.) (form (if (not (%use-emacsclient)) -- cgit v1.3