summaryrefslogtreecommitdiff
path: root/ennu-html.el
diff options
context:
space:
mode:
authorArun Isaac2019-08-20 23:17:35 +0530
committerArun Isaac2019-08-20 23:17:35 +0530
commit24cba52bfe4e92d2e7082f28d9ae7fe788ef2701 (patch)
tree18d0322c23c942f74cd4aa2ccd43b8bb481f0c8b /ennu-html.el
downloadennum-24cba52bfe4e92d2e7082f28d9ae7fe788ef2701.tar.gz
ennum-24cba52bfe4e92d2e7082f28d9ae7fe788ef2701.tar.lz
ennum-24cba52bfe4e92d2e7082f28d9ae7fe788ef2701.zip
Initial commit
Diffstat (limited to 'ennu-html.el')
-rw-r--r--ennu-html.el86
1 files changed, 86 insertions, 0 deletions
diff --git a/ennu-html.el b/ennu-html.el
new file mode 100644
index 0000000..d2c4b76
--- /dev/null
+++ b/ennu-html.el
@@ -0,0 +1,86 @@
+;; -*- lexical-binding: t -*-
+
+(require 'ox)
+(require 'subr-x)
+(require 'xmlgen)
+
+(defun expand-file-name* (name default-directory)
+ (expand-file-name name (concat "/" default-directory)))
+
+(org-export-define-derived-backend 'ennu-html 'html
+ :options-alist
+ '((:html-inline-image-rules
+ nil nil '(("image" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")) t)
+ (:summary "SUMMARY" nil nil t)
+ (:thumbnail "THUMBNAIL" nil nil t)))
+
+;; TODO: Pass title through org-export-data-with-backend or something
+;; similar in order to export org syntax in title
+(defun ennu-export-post (path desc backend)
+ (let ((post (concat (expand-file-name path (ennu-setting :posts-directory))
+ ".org")))
+ (xmlgen `(a :href ,(expand-file-name*
+ path (ennu-setting :posts-directory))
+ ,(or desc (plist-get (ennu-post-metadata post) :title))))))
+
+(org-link-set-parameters
+ "post" :export 'ennu-export-post)
+
+(defun ennu-export-image (path desc backend)
+ (let ((img `(img :src ,(expand-file-name*
+ (ennu-image-output-filename
+ path (ennu-setting :default-image-width))
+ (ennu-setting :images-directory)))))
+ (xmlgen (if (ennu-setting :image-link-width)
+ `(a :href ,(expand-file-name*
+ (ennu-image-output-filename
+ path (ennu-setting :image-link-width))
+ (ennu-setting :images-directory))
+ ,img)
+ img))))
+
+(org-link-set-parameters
+ "image" :export 'ennu-export-image)
+
+(defun ennu-export-thumbnail (path desc backend)
+ (xmlgen
+ `(img :src ,(expand-file-name*
+ (ennu-image-output-filename
+ path (ennu-setting :thumbnail-image-width))
+ (ennu-setting :images-directory)))))
+
+(org-link-set-parameters
+ "thumbnail" :export 'ennu-export-thumbnail)
+
+(defun ennu-export-video (path desc backend)
+ (let ((video-directory (ennu-setting :video-directory)))
+ (xmlgen
+ `(video :src ,(expand-file-name* path video-directory)
+ :poster ,(expand-file-name* (ennu-video-poster path) video-directory)
+ :preload "none"
+ :controls ""))))
+
+(org-link-set-parameters
+ "video" :export 'ennu-export-video)
+
+(defun ennu-export-static (path desc backend)
+ (xmlgen
+ `(a :href ,(expand-file-name* path (ennu-setting :static-directory))
+ ,desc)))
+
+(org-link-set-parameters
+ "static" :export 'ennu-export-static)
+
+(org-link-set-parameters
+ "tangle" :export 'ennu-export-static)
+
+(defun ennu-export-tag (tag desc backend)
+ (xmlgen
+ `(a :href ,(expand-file-name* (concat tag ".html")
+ (ennu-setting :tag-directory))
+ ,(or desc tag))))
+
+(org-link-set-parameters
+ "tag" :export 'ennu-export-tag)
+
+(provide 'ennu-html)