diff options
-rw-r--r-- | ennum.el | 116 |
1 files changed, 64 insertions, 52 deletions
@@ -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) |