aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2020-08-01 16:58:49 +0530
committerArun Isaac2020-08-02 00:35:19 +0530
commit4e64115254237730767b8094f3c189806316d31b (patch)
tree53c0825bb8dfb96b05c94617759666a20beded17
parent8884e54061b3a1e70d71d79b6e76066d61248df7 (diff)
downloadennum-4e64115254237730767b8094f3c189806316d31b.tar.gz
ennum-4e64115254237730767b8094f3c189806316d31b.tar.lz
ennum-4e64115254237730767b8094f3c189806316d31b.zip
Introduce ennum-link type.
* ennum.el (ennum-link): New type. (ennum--read-post, ennum-publish-link): Use ennum-link type.
-rw-r--r--ennum.el41
1 files changed, 26 insertions, 15 deletions
diff --git a/ennum.el b/ennum.el
index 8d99098..14b0533 100644
--- a/ennum.el
+++ b/ennum.el
@@ -136,6 +136,10 @@ respectively by - and _, and the pad character = is optional."
summary tags thumbnail title translation-group translations
video-posters)
+(cl-defstruct (ennum-link (:constructor ennum-make-link)
+ (:copier nil))
+ type path)
+
(defun ennum-posts (posts-directory)
(sort (seq-mapcat
;; Set translations slot of post objects.
@@ -190,7 +194,9 @@ respectively by - and _, and the pad character = is optional."
(`(link ,properties . ,_)
(let ((link-type (org-element-property :type link)))
(when (member link-type (list "image" "static" "video"))
- (cons link-type (org-element-property :path link))))))))))
+ (ennum-make-link
+ :type (intern link-type)
+ :path (org-element-property :path link))))))))))
(ennum-make-post
:filename filename
:slug (file-name-base filename)
@@ -214,17 +220,19 @@ respectively by - and _, and the pad character = is optional."
:tags (plist-get metadata :filetags)
:thumbnail (or (plist-get metadata :thumbnail)
(seq-some (lambda (link)
- (pcase link
- (`("image" . ,path) path)
- (`("video" . ,path) (ennum-video-poster path))))
+ (let ((path (ennum-link-path link)))
+ (pcase (ennum-link-type link)
+ ('image path)
+ ('video (ennum-video-poster path)))))
links))
:title (funcall export (first (plist-get metadata :title)))
:translation-group (or (plist-get metadata :translation-group)
(file-name-base filename))
:video-posters (ennum--filter-map (lambda (link)
- (pcase link
- (`("video" . ,path)
- `(,path . ,(ennum-video-poster path)))))
+ (pcase (ennum-link-type link)
+ ('video
+ (let ((path (ennum-link-path link)))
+ `(,path . ,(ennum-video-poster path))))))
links))))))
(defvar ennum-mandatory-metadata
@@ -521,23 +529,26 @@ if DESTINATION already exists."
(seq-filter 'identity (seq-map function sequence)))
(defun ennum-publish-link (link)
- (pcase link
- (`("image" . ,path)
+ (pcase (ennum-link-type link)
+ ('image
(seq-map (lambda (width)
(ennum-publish-image
- (ennum--expand-relative path (ennum-setting :images-directory))
+ (ennum--expand-relative (ennum-link-path link)
+ (ennum-setting :images-directory))
width))
(list (ennum-setting :default-image-width)
(ennum-setting :image-link-width))))
- (`("static" . ,path)
+ ('static
(list
(ennum-publish-copy
- (ennum--expand-relative path (ennum-setting :static-directory)))))
- (`("video" . ,path)
+ (ennum--expand-relative (ennum-link-path link)
+ (ennum-setting :static-directory)))))
+ ('video
(seq-map 'ennum-publish-copy
(list
- (ennum--expand-relative path (ennum-setting :video-directory))
- (ennum--expand-relative (ennum-video-poster path)
+ (ennum--expand-relative (ennum-link-path link)
+ (ennum-setting :video-directory))
+ (ennum--expand-relative (ennum-video-poster (ennum-link-path link))
(ennum-setting :images-directory)))))))
(defmacro ennum-with-current-directory (directory &rest body)