summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2019-08-26 01:14:12 +0530
committerArun Isaac2019-08-26 02:09:05 +0530
commit4b373b2e209feb60670f44be77d87a8bc4afe6d7 (patch)
tree127d37b7425aa47214afd75d6c7670cd7c54dc9d
parent6cd56699a52aa3e8f6be4f79f54f38dad2786de2 (diff)
downloadennum-4b373b2e209feb60670f44be77d87a8bc4afe6d7.tar.gz
ennum-4b373b2e209feb60670f44be77d87a8bc4afe6d7.tar.lz
ennum-4b373b2e209feb60670f44be77d87a8bc4afe6d7.zip
Abstract out temporary directory creation.
* ennu.el (ennu-with-temporary-directory): New macro. (ennu-publish): Use ennu-with-temporary-directory to create temporary directory.
-rw-r--r--ennu.el123
1 files changed, 65 insertions, 58 deletions
diff --git a/ennu.el b/ennu.el
index d373d8c..8e02cea 100644
--- a/ennu.el
+++ b/ennu.el
@@ -348,69 +348,76 @@ last form in BODY."
(defun ennu-post-tongue (post)
(plist-get (ennu-post-metadata post) :language))
+(defmacro ennu-with-temporary-directory (temporary-directory &rest body)
+ "Create temporary directory, evaluate BODY with the absolute
+path of that directory assigned to TEMPORARY-DIRECTORY and
+finally delete the temporary directory. The value returned is the
+value of the last form in BODY."
+ (declare (indent defun))
+ `(let ((,temporary-directory (make-temp-file "ennu" t)))
+ (unwind-protect ,@body
+ (delete-directory ,temporary-directory t))))
+
(defun ennu-publish ()
(interactive)
(let ((make-backup-files nil)
(blog-title (ennu-setting :blog-title))
(blog-subtitle (ennu-setting :blog-subtitle))
(posts-per-page (ennu-setting :index-posts-per-page)))
- (let ((temporary-directory (make-temp-file "ennu" t)))
- (unwind-protect
- (progn
- (seq-do
- (apply-partially 'ennu--do-operation temporary-directory)
- (append
- (let* ((posts (ennu-posts (ennu-setting :posts-directory)))
- (tags (seq-uniq (seq-mapcat 'ennu-post-tags posts)))
- (tongues (seq-uniq (seq-map 'ennu-post-tongue posts))))
- (append
- ;; Publish posts
- (seq-map 'ennu-publish-post posts)
- ;; Publish feed
- (list (ennu-publish-feed (ennu-setting :atom-feed-file)
- blog-title blog-subtitle
- (ennu-setting :blog-license)
- (seq-take posts (ennu-setting :atom-feed-number-of-posts))))
- ;; Publish indices
- (seq-map
- (lambda (tongue)
- (ennu-publish-index
- "index" tongue blog-title blog-subtitle posts-per-page
- (seq-filter (lambda (post)
- (string= tongue (ennu-post-tongue post)))
- posts)))
- tongues)
- (seq-map
- (lambda (tag)
- (let ((posts (seq-filter (lambda (post)
- (member tag (ennu-post-tags post)))
- posts)))
- (ennu-publish-index
- (ennu--expand-relative tag (ennu-setting :tag-directory))
- (ennu-post-tongue (first posts)) tag "" posts-per-page posts)))
- tags)
- ;; Publish links
- (seq-map 'ennu-publish-link
- (seq-uniq (seq-mapcat 'ennu-post-links posts)))
- ;; Publish thumbnails
- (seq-map
- (apply-partially 'ennu-publish-image (list (ennu-setting :thumbnail-image-width)))
- (seq-map (lambda (image)
- (ennu--expand-relative image (ennu-setting :images-directory)))
- (seq-uniq (seq-filter 'identity (seq-map 'ennu-post-thumbnail posts)))))))
- ;; Publish pages
- (when-let ((pages-directory (ennu-setting :pages-directory)))
- (seq-map (apply-partially 'ennu-publish-page pages-directory)
- (seq-map (apply-partially 'string-remove-prefix
- (file-name-as-directory (expand-file-name default-directory)))
- (directory-files-recursively pages-directory "\\.org$"))))
- ;; Publish unattached static files
- (seq-map 'ennu-publish-static-file
- (ennu-setting :unattached-static-files))))
- ;; Replace old output directory
- (let ((output (ennu-setting :output-directory)))
- (delete-directory output t)
- (rename-file temporary-directory output t)))
- (delete-directory temporary-directory t)))))
+ (ennu-with-temporary-directory temporary-directory
+ (seq-do
+ (apply-partially 'ennu--do-operation temporary-directory)
+ (append
+ (let* ((posts (ennu-posts (ennu-setting :posts-directory)))
+ (tags (seq-uniq (seq-mapcat 'ennu-post-tags posts)))
+ (tongues (seq-uniq (seq-map 'ennu-post-tongue posts))))
+ (append
+ ;; Publish posts
+ (seq-map 'ennu-publish-post posts)
+ ;; Publish feed
+ (list (ennu-publish-feed (ennu-setting :atom-feed-file)
+ blog-title blog-subtitle
+ (ennu-setting :blog-license)
+ (seq-take posts (ennu-setting :atom-feed-number-of-posts))))
+ ;; Publish indices
+ (seq-map
+ (lambda (tongue)
+ (ennu-publish-index
+ "index" tongue blog-title blog-subtitle posts-per-page
+ (seq-filter (lambda (post)
+ (string= tongue (ennu-post-tongue post)))
+ posts)))
+ tongues)
+ (seq-map
+ (lambda (tag)
+ (let ((posts (seq-filter (lambda (post)
+ (member tag (ennu-post-tags post)))
+ posts)))
+ (ennu-publish-index
+ (ennu--expand-relative tag (ennu-setting :tag-directory))
+ (ennu-post-tongue (first posts)) tag "" posts-per-page posts)))
+ tags)
+ ;; Publish links
+ (seq-map 'ennu-publish-link
+ (seq-uniq (seq-mapcat 'ennu-post-links posts)))
+ ;; Publish thumbnails
+ (seq-map
+ (apply-partially 'ennu-publish-image (list (ennu-setting :thumbnail-image-width)))
+ (seq-map (lambda (image)
+ (ennu--expand-relative image (ennu-setting :images-directory)))
+ (seq-uniq (seq-filter 'identity (seq-map 'ennu-post-thumbnail posts)))))))
+ ;; Publish pages
+ (when-let ((pages-directory (ennu-setting :pages-directory)))
+ (seq-map (apply-partially 'ennu-publish-page pages-directory)
+ (seq-map (apply-partially 'string-remove-prefix
+ (file-name-as-directory (expand-file-name default-directory)))
+ (directory-files-recursively pages-directory "\\.org$"))))
+ ;; Publish unattached static files
+ (seq-map 'ennu-publish-static-file
+ (ennu-setting :unattached-static-files))))
+ ;; Replace old output directory
+ (let ((output (ennu-setting :output-directory)))
+ (delete-directory output t)
+ (rename-file temporary-directory output t)))))
(provide 'ennu)