aboutsummaryrefslogtreecommitdiff
path: root/haunt/jakob
diff options
context:
space:
mode:
Diffstat (limited to 'haunt/jakob')
-rw-r--r--haunt/jakob/reader/org-mode-prime.scm36
-rw-r--r--haunt/jakob/reader/org-mode.scm12
-rw-r--r--haunt/jakob/utils.scm22
3 files changed, 59 insertions, 11 deletions
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 <zerodaysfordays@sdf.org>
+;;;
+;;; 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
+;;; <http://www.gnu.org/licenses/>.
+
+;;; 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))
diff --git a/haunt/jakob/utils.scm b/haunt/jakob/utils.scm
index a104510..ad35f4c 100644
--- a/haunt/jakob/utils.scm
+++ b/haunt/jakob/utils.scm
@@ -19,7 +19,8 @@
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
- #:export (maybe-cons*
+ #:export (assq-map!
+ maybe-cons*
maybe-list
date->string*
intersperse
@@ -28,6 +29,12 @@
elide-string))
+(define (assq-map! alist key fn)
+ "Destructively apply FN to KEY in ALIST, if it exists"
+ (match (assq-ref alist key)
+ (#f alist)
+ (val (assq-set! alist key (fn val)))))
+
(define (maybe-list . args)
"Create a list of all ARGS that are neither #f nor unspecified."
(remove (lambda (element)
@@ -62,16 +69,11 @@ is of an odd length and every second element is DELIM."
content)))
(define (first-paragraph post)
- (let loop ((sxml (post-sxml post))
- (result '()))
+ (let loop ((sxml (post-sxml post)))
(match sxml
- (() (remove-footnote-references (reverse result)))
- ((or (('p ...) tail ...) (paragraph tail ...))
- (if (and (list? paragraph) (eqv? 'header (car paragraph)))
- (loop tail result) ; Ignore front-matter.
- (remove-footnote-references (reverse (cons paragraph result)))))
- ((head . tail)
- (loop tail (cons head result))))))
+ (((and ('p content ...) paragraph) . tail)
+ (remove-footnote-references paragraph))
+ ((head . tail) (loop tail)))))
(define (description-from-post post)
(define (first-elem sxml)

© 2015 - 2026 Jakob L. Kreuze