aboutsummaryrefslogtreecommitdiff
path: root/ennu.el
diff options
context:
space:
mode:
authorArun Isaac2019-08-26 01:57:22 +0530
committerArun Isaac2019-08-26 02:09:05 +0530
commitc8bb99b30e770668675128ddd3fb67e87c9376e1 (patch)
treecdab97f064a231163505deb2db0832c499e54799 /ennu.el
parente8c62b3c4261ad448c3b444b65e255e9d2525401 (diff)
downloadennum-c8bb99b30e770668675128ddd3fb67e87c9376e1.tar.gz
ennum-c8bb99b30e770668675128ddd3fb67e87c9376e1.tar.lz
ennum-c8bb99b30e770668675128ddd3fb67e87c9376e1.zip
Use grouping functions to handle multiple tags and languages.
* ennu.el (ennu-many-to-many-group-by): New function. (ennu-publish): Use grouping functions seq-group-by and ennu-many-to-many-group-by instead of seq-filter to handle multiple tags and languages.
Diffstat (limited to 'ennu.el')
-rw-r--r--ennu.el48
1 files changed, 29 insertions, 19 deletions
diff --git a/ennu.el b/ennu.el
index 76a2dbe..7169b9a 100644
--- a/ennu.el
+++ b/ennu.el
@@ -365,6 +365,22 @@ value of the last form in BODY."
(unwind-protect ,@body
(delete-directory ,temporary-directory t))))
+(defun ennu-many-to-many-group-by (function sequence)
+ "Apply FUNCTION to each element of SEQUENCE.
+Separate the elements of SEQUENCE into an alist using the results
+as keys. Keys are compared using `equal'."
+ (seq-reduce
+ (lambda (result element)
+ (seq-do
+ (lambda (key)
+ (map-put result key
+ (cons element (map-elt result key nil 'equal))
+ 'equal))
+ (funcall function element))
+ result)
+ (seq-reverse sequence)
+ nil))
+
(defun ennu-publish ()
(interactive)
(let ((make-backup-files nil)
@@ -375,9 +391,7 @@ value of the last form in BODY."
(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))))
+ (let ((posts (ennu-posts (ennu-setting :posts-directory))))
(append
;; Publish posts
(seq-map 'ennu-publish-post posts)
@@ -388,22 +402,18 @@ value of the last form in BODY."
(seq-take posts (ennu-setting :atom-feed-number-of-posts))))
;; Publish indices
(seq-map
- (lambda (tongue)
- (ennu-publish-index
- "index" tongue blog-title 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)
+ (pcase-lambda (`(,tongue . ,posts))
+ (ennu-publish-index "index" tongue blog-title posts-per-page posts))
+ (seq-group-by 'ennu-post-tongue posts))
+ (seq-mapcat
+ (pcase-lambda (`(,tag . ,posts))
+ (seq-map
+ (pcase-lambda (`(,tongue . ,posts))
+ (ennu-publish-index
+ (ennu--expand-relative tag (ennu-setting :tag-directory))
+ tongue tag posts-per-page posts))
+ (seq-group-by 'ennu-post-tongue posts)))
+ (ennu-many-to-many-group-by 'ennu-post-tags posts))
;; Publish links
(seq-map 'ennu-publish-link
(seq-uniq (seq-mapcat 'ennu-post-links posts)))