From 3f2eef6a230278fc4ed3cbc71d6bbcfc80f3f13c Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 2 Sep 2019 22:56:11 +0530 Subject: Add tangle slot to post structure. * ennu.el (ennu-post): Add tangle slot. (ennu--read-post): Initialize tangle slot. --- ennu.el | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'ennu.el') diff --git a/ennu.el b/ennu.el index be81523..f8bab98 100644 --- a/ennu.el +++ b/ennu.el @@ -14,7 +14,7 @@ (cl-defstruct (ennu-post (:constructor ennu-make-post) (:copier nil)) - filename slug author date language links + filename slug author date language links tangle summary tags thumbnail title translation-group) (cl-defstruct (ennu-operation (:constructor ennu-make-operation) @@ -46,13 +46,14 @@ (unless (plist-member metadata key) (user-error "Metadata %s not specified" key))) ennu-mandatory-metadata) - (let ((links (org-element-map (org-element-parse-buffer) 'link - (lambda (link) - (pcase link - (`(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)))))))))) + (let* ((tree (org-element-parse-buffer)) + (links (org-element-map tree 'link + (lambda (link) + (pcase link + (`(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)))))))))) (ennu-make-post :filename filename :slug (file-name-base filename) @@ -60,6 +61,16 @@ :date (org-timestamp-to-time (first (plist-get metadata :date))) :language (plist-get metadata :language) :links links + ;; TODO: Deal with cases when the :tangle parameter is "yes" + :tangle (seq-uniq + (org-element-map tree 'src-block + (lambda (src-block) + (pcase (org-babel-get-src-block-info nil src-block) + (`(,_ ,_ ,arguments ,_ ,_ ,_ ,_) + (let ((tangle-output-file (map-elt arguments :tangle))) + (pcase tangle-output-file + ("no" nil) + (_ tangle-output-file)))))))) :summary (funcall export (first (plist-get metadata :summary))) :tags (plist-get metadata :filetags) :thumbnail (or (plist-get metadata :thumbnail) -- cgit v1.2.3