about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-09-07 01:44:48 +0100
committerArun Isaac2026-09-07 01:44:59 +0100
commitbc16c6424ebe124d1826bd06a6d4e65464d51b2b (patch)
treea59aca4479aa99b3cc3c164386df311b01392ce7
parent5a682c030a07fc869dc05c6497e09a5136964f52 (diff)
downloadennum-bc16c6424ebe124d1826bd06a6d4e65464d51b2b.tar.gz
ennum-bc16c6424ebe124d1826bd06a6d4e65464d51b2b.tar.lz
ennum-bc16c6424ebe124d1826bd06a6d4e65464d51b2b.zip
Add ennum-gemini backend.
-rw-r--r--ennum-gemini.el89
1 files changed, 89 insertions, 0 deletions
diff --git a/ennum-gemini.el b/ennum-gemini.el
new file mode 100644
index 0000000..80ea836
--- /dev/null
+++ b/ennum-gemini.el
@@ -0,0 +1,89 @@
+;; -*- lexical-binding: t -*-
+
+(require 'ox)
+(require 'ox-gemini)
+(require 'subr-x)
+(require 'xmlgen)
+(require 'ennum-lang)
+
+(defun expand-file-name* (name base-directory)
+  (expand-file-name name (concat "/" base-directory)))
+
+(org-export-define-derived-backend 'ennum-gemini 'gemini
+  :translate-alist
+  '((inner-template . ennum-gemini-inner-template)
+    (section . ennum-gemini-section)
+    (paragraph . ennum-gemini-paragraph)
+    (link . ennum-gemini-link))
+  :options-alist
+  '((:summary "SUMMARY" nil nil parse)
+    (:thumbnail "THUMBNAIL" nil nil t)
+    (:translation-group "TRANSLATION_GROUP" nil nil t)))
+
+(defun ennum-gemini-inner-template (contents info)
+  (concat
+   ;; Date
+   (org-export-get-date info "%B %d, %Y\n\n")
+   ;; Interlanguage language links
+   (mapconcat (pcase-lambda (`(,lang . ,slug))
+                (ennum-link-export-post
+                 slug
+                 (map-elt ennum--iso-639-1-alist lang)
+                 (org-export-backend-name (plist-get info :back-end))
+                 info))
+              (ennum-post-translations (plist-get info :ennum-post))
+              "\n")
+   "\n\n"
+   ;; Body
+   contents
+   ;; Tags
+   "\nTags:\n"
+   (mapconcat (lambda (tag)
+                (ennum-link-export-tag
+                 (ennum-add-tongue-suffix tag (plist-get info :language))
+                 tag
+                 (org-export-backend-name (plist-get info :back-end))
+                 info))
+              (plist-get info :filetags)
+              "\n")))
+
+(defun ennum-gemini-section (section contents info)
+  ;; Render links at the end of the section, but only if they are not
+  ;; image, video or pdf links.
+  (pcase (seq-remove (lambda (link)
+                       (member (org-element-property :type link)
+                               (list "image" "video" "pdf")))
+                     (org-ascii--unique-links section info))
+    ('()
+     contents)
+    (links
+     (org-remove-indentation
+      (concat (org-element-normalize-string contents)
+              "\n\n"
+              (org-gemini--describe-links
+               links
+               (org-ascii--current-text-width section info)
+               info))))))
+
+(defun ennum-gemini-paragraph (paragraph contents info)
+  ;; If the paragraph contains an image or video link, then it is an
+  ;; image paragraph; tag on the caption.
+  (if (= (length (org-element-map paragraph '(link)
+                   (lambda (link)
+                     (and (member (org-element-property :type link)
+                                  (list "image" "video"))
+                          link))))
+         1)
+      (concat (string-trim contents)
+              " "
+              (org-export-data (org-export-get-caption paragraph)
+                               info))
+    ;; Else, fall back to the gemini backend.
+    (org-gemini-paragraph paragraph contents info)))
+
+(defun ennum-gemini-link (link desc info)
+  ;; Try a custom link type before falling back to the gemini backend.
+  (or (org-export-custom-protocol-maybe link desc 'ennum-gemini info)
+      (org-gemini-link link desc info)))
+
+(provide 'ennum-gemini)