aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)))