aboutsummaryrefslogtreecommitdiff
path: root/ennu.el
diff options
context:
space:
mode:
Diffstat (limited to 'ennu.el')
-rw-r--r--ennu.el122
1 files changed, 67 insertions, 55 deletions
diff --git a/ennu.el b/ennu.el
index 8e02cea..63f0073 100644
--- a/ennu.el
+++ b/ennu.el
@@ -206,7 +206,8 @@ last form in BODY."
"tag"))
((or :blog-domain :blog-license :blog-title
:images-directory :output-directory :posts-directory
- :static-directory :tag-directory :video-directory)
+ :static-directory :tag-directory :video-directory
+ :working-directory)
(or (plist-get ennu-blog property)
(user-error "Property %s not defined" property)))
((or :blog-subtitle :pages-directory :unattached-static-files)
@@ -348,6 +349,16 @@ last form in BODY."
(defun ennu-post-tongue (post)
(plist-get (ennu-post-metadata post) :language))
+(defmacro ennu-with-current-directory (directory &rest body)
+ "Change to DIRECTORY, evaluate BODY and restore the current
+working directory. The value returned is the value of the last
+form in BODY."
+ (declare (indent defun))
+ (let ((current-directory-symbol (make-symbol "current-directory")))
+ `(let ((,current-directory-symbol default-directory))
+ (unwind-protect (progn (cd ,directory) ,@body)
+ (cd ,current-directory-symbol)))))
+
(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
@@ -364,60 +375,61 @@ value of the last form in BODY."
(blog-title (ennu-setting :blog-title))
(blog-subtitle (ennu-setting :blog-subtitle))
(posts-per-page (ennu-setting :index-posts-per-page)))
- (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-with-current-directory (ennu-setting :working-directory)
+ (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
- (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)))))
+ "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)