summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2020-08-01 05:24:56 +0530
committerArun Isaac2020-08-02 00:35:14 +0530
commit8884e54061b3a1e70d71d79b6e76066d61248df7 (patch)
tree12692f8a43202dd332cf09e5d6c7bdecb1d3835b
parentd45b6e3aa3c1ffa0a37a4276dbd0e51ee44c32af (diff)
downloadennum-8884e54061b3a1e70d71d79b6e76066d61248df7.tar.gz
ennum-8884e54061b3a1e70d71d79b6e76066d61248df7.tar.lz
ennum-8884e54061b3a1e70d71d79b6e76066d61248df7.zip
Deduplicate ennum-html export.
* ennum.el (ennum-export-post): New function.
(ennum-publish-post, ennum--feed-entry): Invoke ennum-export-post.
-rw-r--r--ennum.el40
1 files changed, 25 insertions, 15 deletions
diff --git a/ennum.el b/ennum.el
index c88a580..8d99098 100644
--- a/ennum.el
+++ b/ennum.el
@@ -259,22 +259,34 @@ non-nil, include directories in the output."
 (defun ennum--org-output-filename (filename)
   (concat (file-name-sans-extension filename) ".html"))
 
+(defun ennum-export-post (post interned-org-file &optional output-html-file body-only)
+  "Export INTERNED-ORG-FILE of POST to OUTPUT-HTML-FILE using the
+ennum-html backend. INTERNED-ORG-FILE must be an org file
+interned into the ennum store.
+
+When optional argument BODY-ONLY is non-nil, only return body
+code, without surrounding template. See `org-export-as'.
+
+When optional argument OUTPUT-HTML-FILE is nil, return exported
+result as a string."
+  (let ((output-file (ennum--org-output-filename (ennum-post-filename post))))
+    (ennum-mkdir-p (file-name-directory output-file))
+    (let ((system-time-locale (map-elt (ennum-setting :locale-alist)
+                                       (ennum-post-language post) nil 'string=))
+          (ext-plist (list :ennum-translations (ennum-post-translations post)
+                           :ennum-video-posters (ennum-post-video-posters post))))
+      (ennum-with-file-contents interned-org-file
+        (if output-html-file
+            (org-export-to-file 'ennum-html output-file nil nil nil body-only ext-plist)
+          (org-export-as 'ennum-html nil nil body-only ext-plist))))))
+
 (defun ennum-publish-post (post)
   (append
    (list
     (ennum-exp
-     (let ((input-org-file (ennum-input (ennum-intern (ennum-post-filename post))))
-           (output-file
-            (ennum--org-output-filename (ennum-post-filename post))))
-       (ennum-mkdir-p (file-name-directory output-file))
-       (let ((system-time-locale (map-elt (ennum-setting :locale-alist)
-                                          (ennum-post-language post) nil 'string=)))
-         (ennum-with-file-contents input-org-file
-           ;; TODO: Centralize these with feed generation
-           (org-export-to-file
-               'ennum-html output-file nil nil nil nil
-               (list :ennum-translations (ennum-post-translations post)
-                     :ennum-video-posters (ennum-post-video-posters post))))))))
+     (ennum-export-post post
+                        (ennum-input (ennum-intern (ennum-post-filename post)))
+                        (ennum--org-output-filename (ennum-post-filename post)))))
    (when (ennum-post-tangle post)
      (list
       (ennum-exp
@@ -427,9 +439,7 @@ non-nil, include directories in the output."
                    (name ,(ennum-post-author post))
                    (email ,user-mail-address))))
             (content :type "html" :xml:lang ,(ennum-post-language post)
-                     ,(ennum-with-file-contents interned-post-file
-                        (org-export-as 'ennum-html nil nil t
-                                       (list :ennum-video-posters (ennum-post-video-posters post)))))
+                     ,(ennum-export-post post interned-post-file nil t))
             (link :rel "alternate" :href ,link)
             ,@(seq-map (lambda (tag) `(category :term ,tag))
                        (ennum-post-tags post)))))