aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2020-08-02 04:41:56 +0530
committerArun Isaac2020-08-03 01:24:12 +0530
commitd88427a30a52314e7c99282bd556ac35cfed6ddb (patch)
treeca56139def1b79db09e7ed3db3ea389fa9fb6e11
parent117d9519a14e3224390167c7b078061ff2b5f567 (diff)
downloadennum-d88427a30a52314e7c99282bd556ac35cfed6ddb.tar.gz
ennum-d88427a30a52314e7c99282bd556ac35cfed6ddb.tar.lz
ennum-d88427a30a52314e7c99282bd556ac35cfed6ddb.zip
Disentangle index page generation expressions.
* ennum.el (ennum-publish-index): Publish each page as a separate ennum expression. Make them separate functions to avoid closure capture. (ennum-publish-index-page, ennum-publish-index-home): New functions. (ennum-publish): Concatenate return value of ennum-publish-index.
-rw-r--r--ennum.el116
1 files changed, 64 insertions, 52 deletions
diff --git a/ennum.el b/ennum.el
index c9d78a9..86295f8 100644
--- a/ennum.el
+++ b/ennum.el
@@ -395,59 +395,71 @@ result as a string."
(concat filename-prefix extension))
tongue)))
+(defun ennum-publish-index-page (filename-prefix title last-page posts page-number output-file)
+ (ennum-exp
+ (let* ((tongue (ennum-post-language (first posts)))
+ (system-time-locale
+ (map-elt (ennum-setting :locale-alist)
+ tongue nil 'string=)))
+ (when (file-name-directory output-file)
+ (ennum-mkdir-p (file-name-directory output-file)))
+ (with-temp-buffer
+ (insert (format "#+TITLE: %s\n" title))
+ (insert (format "#+LANGUAGE: %s\n" tongue))
+ (insert "#+OPTIONS: num:nil toc:nil\n\n")
+ (seq-do (lambda (post)
+ (insert (format "* [[post:%s][%s]]\n"
+ (ennum-post-slug post)
+ (ennum-post-title post)))
+ (insert (format-time-string "/%b %e, %Y/\n\n" (ennum-post-date post)))
+ (when-let ((thumbnail (ennum-post-thumbnail post)))
+ (insert (format "[[thumbnail:%s]]\n\n" thumbnail)))
+ (when-let ((summary (ennum-post-summary post)))
+ (insert summary)
+ (insert "\n\n"))
+ (when-let ((tags (ennum-post-tags post)))
+ (insert "Tags: ")
+ (insert
+ (string-join
+ (seq-map (lambda (tag)
+ (format "[[tag:%s][%s]]" (ennum-add-tongue-suffix tag tongue) tag))
+ tags)
+ ", "))
+ (insert "\n\n")))
+ posts)
+ (unless (= page-number 1)
+ (insert (format "[[./%s][Newer posts]]\n\n"
+ (ennum-index-filename (file-name-nondirectory filename-prefix)
+ tongue nil (1- page-number)))))
+ (unless last-page
+ (insert (format "[[./%s][Older posts]]\n"
+ (ennum-index-filename (file-name-nondirectory filename-prefix)
+ tongue nil (1+ page-number)))))
+ (org-export-to-file 'html output-file)))))
+
+(defun ennum-publish-index-home (first-index-page-output filename-prefix tongue)
+ (ennum-exp
+ (ennum-copy (ennum--file-join first-index-page-output
+ (ennum-index-filename filename-prefix tongue "html" 1))
+ (ennum-add-tongue-suffix (format "%s.html" filename-prefix) tongue))))
+
(defun ennum-publish-index (filename-prefix title posts-per-page posts)
(let* ((tongue (ennum-post-language (first posts)))
(number-of-pages (ceiling (length posts) posts-per-page))
- (page-numbers (number-sequence 1 number-of-pages)))
- (ennum-exp
- (ennum-input (seq-map (lambda (post)
- (ennum-intern (ennum-post-filename post)))
- posts))
- (let ((output-files (seq-map (apply-partially 'ennum-index-filename filename-prefix tongue "html")
- page-numbers))
- (system-time-locale (map-elt (ennum-setting :locale-alist) tongue nil 'string=)))
- (seq-mapn
- (lambda (posts page-number output-file)
- (when (file-name-directory output-file)
- (ennum-mkdir-p (file-name-directory output-file)))
- (with-temp-buffer
- (insert (format "#+TITLE: %s\n" title))
- (insert (format "#+LANGUAGE: %s\n" tongue))
- (insert "#+OPTIONS: num:nil toc:nil\n\n")
- (seq-do (lambda (post)
- (insert (format "* [[post:%s][%s]]\n"
- (ennum-post-slug post)
- (ennum-post-title post)))
- (insert (format-time-string "/%b %e, %Y/\n\n" (ennum-post-date post)))
- (when-let ((thumbnail (ennum-post-thumbnail post)))
- (insert (format "[[thumbnail:%s]]\n\n" thumbnail)))
- (when-let ((summary (ennum-post-summary post)))
- (insert summary)
- (insert "\n\n"))
- (when-let ((tags (ennum-post-tags post)))
- (insert "Tags: ")
- (insert
- (string-join
- (seq-map (lambda (tag)
- (format "[[tag:%s][%s]]" (ennum-add-tongue-suffix tag tongue) tag))
- tags)
- ", "))
- (insert "\n\n")))
- posts)
- (unless (= page-number 1)
- (insert (format "[[./%s][Newer posts]]\n\n"
- (ennum-index-filename (file-name-nondirectory filename-prefix)
- tongue nil (1- page-number)))))
- (unless (= page-number number-of-pages)
- (insert (format "[[./%s][Older posts]]\n"
- (ennum-index-filename (file-name-nondirectory filename-prefix)
- tongue nil (1+ page-number)))))
- (org-export-to-file 'html output-file)))
- (seq-partition posts posts-per-page)
- page-numbers
- output-files)
- (copy-file (first output-files)
- (ennum-add-tongue-suffix (format "%s.html" filename-prefix) tongue))))))
+ (page-numbers (number-sequence 1 number-of-pages))
+ (output-files (seq-map (apply-partially
+ 'ennum-index-filename filename-prefix tongue "html")
+ page-numbers))
+ (outputs (seq-mapn (lambda (post page-number output-file)
+ (ennum-publish-index-page
+ filename-prefix title
+ (= page-number number-of-pages)
+ post page-number output-file))
+ (seq-partition posts posts-per-page)
+ page-numbers
+ output-files)))
+ (cons (ennum-publish-index-home (first outputs) filename-prefix tongue)
+ outputs)))
(defun ennum--absolute-uri (path)
(format "%s://%s/%s"
@@ -656,14 +668,14 @@ as keys. Keys are compared using `equal'."
(ennum-setting :blog-license)
(seq-take posts (ennum-setting :atom-feed-number-of-posts))))
;; Publish indices
- (seq-map
+ (seq-mapcat
(pcase-lambda (`(,tongue . ,posts))
(ennum-publish-index "index" blog-title posts-per-page posts))
(seq-group-by 'ennum-post-language posts))
;; Publish tag indices
(seq-mapcat
(pcase-lambda (`(,tag . ,posts))
- (seq-map
+ (seq-mapcat
(pcase-lambda (`(,tongue . ,posts))
(ennum-publish-index
(ennum--file-join (ennum-setting :tag-directory) tag)