aboutsummaryrefslogtreecommitdiff
path: root/lisp/seam-export.el
diff options
context:
space:
mode:
authorSpencer Williams <spnw@plexwave.org>2025-07-11 19:18:15 -0400
committerSpencer Williams <spnw@plexwave.org>2025-07-11 19:25:03 -0400
commit0fb032562ce22e35e1dedc43845bc8c6ca73a423 (patch)
treeb30bff76c62219c66647c3ebc3f489404a444930 /lisp/seam-export.el
parentac468cb3500ac9def50359bb87ba04a7267d1249 (diff)
Add support for custom template vars
Diffstat (limited to 'lisp/seam-export.el')
-rw-r--r--lisp/seam-export.el72
1 files changed, 47 insertions, 25 deletions
diff --git a/lisp/seam-export.el b/lisp/seam-export.el
index 8cab0ab..9f99a09 100644
--- a/lisp/seam-export.el
+++ b/lisp/seam-export.el
@@ -33,6 +33,7 @@
(defvar seam-export--types nil)
(defvar seam-export--template nil)
+(defvar seam-export--template-values nil)
(defvar seam-export--root-path nil)
(defvar seam-export--include-drafts nil)
(defvar seam-export--no-extension nil)
@@ -67,6 +68,13 @@ properties:
missing, falls back to :template-file, `seam-export-template-file',
or `seam-export-template-string' in that order.
+ `:template-values'
+
+ An alist of (VAR . VALUE) pairs, where VAR is a string naming
+ a template variable, and VALUE is the value to be used when
+ interpolating that variable. See the mustache.el docs for
+ more information. Defaults to nil.
+
`:root-path'
The root path used for rendering internal links. Defaults to \"\",
@@ -166,6 +174,14 @@ See `seam-export-alist' for more information about specifying templates."
:group 'seam-export
:type '(choice string (const nil)))
+(defcustom seam-export-template-values nil
+ "An alist of (VAR . VALUE) pairs, where VAR is a string naming a
+template variable, and VALUE is the value to be used when
+interpolating that variable. See the mustache.el docs for more
+information."
+ :group 'seam-export
+ :type '(alist :key-type string :value-type sexp))
+
(defcustom seam-export-time-format "%e %B %Y"
"Human-readable format for template time strings. Passed to
`format-time-string'."
@@ -275,30 +291,34 @@ notes)."
(insert
(mustache-render
seam-export--template
- `(("title" .
- ,(seam-export--org-to-text
- (seam-get-title-from-file note-file)))
- ("raw-title" .
- ,(seam-export--org-to-html
- (seam-get-title-from-file note-file)))
- ("modified" .
- ,(format-time-string
- seam-export-time-format
- modified
- seam-export-time-zone))
- ("modified-dt" .
- ,(format-time-string
- seam-export-time-format-datetime
- modified
- seam-export-time-zone))
- ("contents" .
- ,(seam-export--export-to-html-string
- (insert-file-contents note-file)
- (re-search-forward "^\\* ")
- (org-mode) ;Needed for `org-set-property'.
- (org-set-property "seam-title-p" "t")))
- ("backlinks" .
- ,(seam-export--generate-backlinks note-file)))))
+ (append
+ seam-export--template-values
+ seam-export-template-values
+ `(("title" .
+ ,(seam-export--org-to-text
+ (seam-get-title-from-file note-file)))
+ ("raw-title" .
+ ,(seam-export--org-to-html
+ (seam-get-title-from-file note-file)))
+ ("modified" .
+ ,(format-time-string
+ seam-export-time-format
+ modified
+ seam-export-time-zone))
+ ("modified-dt" .
+ ,(format-time-string
+ seam-export-time-format-datetime
+ modified
+ seam-export-time-zone))
+ ("contents" .
+ ,(seam-export--export-to-html-string
+ (insert-file-contents note-file)
+ (re-search-forward "^\\* ")
+ (org-mode) ;Needed for `org-set-property'.
+ (org-set-property "seam-title-p" "t")))
+ ("backlinks" .
+ ,(seam-export--generate-backlinks note-file)))
+ nil)))
(write-file html-file))))
(defun seam-export--file-string (file)
@@ -313,7 +333,8 @@ notes)."
do
(let ((types (plist-get plist :types))
(template-file (plist-get plist :template-file))
- (template-string (plist-get plist :template-string)))
+ (template-string (plist-get plist :template-string))
+ (template-values (plist-get plist :template-values)))
(unless types
(error "You must specify :types for export"))
(let ((template
@@ -332,6 +353,7 @@ notes)."
(seam-export--include-drafts (plist-get plist :include-drafts))
(seam-export--no-extension (plist-get plist :no-extension))
(seam-export--template template)
+ (seam-export--template-values template-values)
(seam-export--internal-link-class
(or (plist-get plist :internal-link-class)
seam-export-internal-link-class))