summaryrefslogtreecommitdiff
path: root/ennum.el
diff options
context:
space:
mode:
Diffstat (limited to 'ennum.el')
-rw-r--r--ennum.el108
1 files changed, 62 insertions, 46 deletions
diff --git a/ennum.el b/ennum.el
index adba985..c88a580 100644
--- a/ennum.el
+++ b/ennum.el
@@ -131,16 +131,39 @@ respectively by - and _, and the pad character = is optional."
(ennum-input items))))
(cl-defstruct (ennum-post (:constructor ennum-make-post)
- (:copier nil))
+ (:copier ennum-copy-post))
filename slug author date language links tangle
- summary tags thumbnail title translation-group video-posters)
+ summary tags thumbnail title translation-group translations
+ video-posters)
(defun ennum-posts (posts-directory)
- (sort (ennum--filter-map (lambda (file)
- (when (string= (file-name-extension file) "org")
- (ennum-read-post
- (ennum--expand-relative file (ennum-setting :posts-directory)))))
- (ennum-directory-files (ennum-setting :posts-directory)))
+ (sort (seq-mapcat
+ ;; Set translations slot of post objects.
+ (pcase-lambda (`(,_ . ,posts))
+ (let ((translations
+ (seq-map (lambda (post)
+ (cons (ennum-post-language post)
+ (ennum-post-slug post)))
+ posts)))
+ (seq-map (lambda (post)
+ (let ((post-copy (ennum-post-copy post)))
+ (setf (ennum-post-translations post-copy)
+ (seq-remove (pcase-lambda (`(,_ . ,slug))
+ (string= (ennum-post-slug post)
+ slug))
+ translations))
+ post-copy))
+ posts)))
+ ;; Read posts from org files and group them by translation
+ ;; group.
+ (seq-group-by
+ 'ennum-post-translation-group
+ (ennum--filter-map
+ (lambda (file)
+ (when (string= (file-name-extension file) "org")
+ (ennum-read-post
+ (ennum--expand-relative file (ennum-setting :posts-directory)))))
+ (ennum-directory-files (ennum-setting :posts-directory)))))
'ennum-later-post-p))
(defun ennum-later-post-p (post1 post2)
@@ -236,42 +259,37 @@ non-nil, include directories in the output."
(defun ennum--org-output-filename (filename)
(concat (file-name-sans-extension filename) ".html"))
-(defun ennum-publish-post (posts)
- (seq-mapcat (lambda (post)
- (append
- (list
- (ennum-exp
- (ennum-input (seq-map (lambda (post)
- (ennum-intern (ennum-post-filename post)))
- posts))
- (let ((input-org-file (ennum-input (ennum-intern (ennum-post-filename post))))
- (output-file
- (ennum--org-output-filename (ennum-post-filename post))))
- (ennum-mkdir-p (file-name-directory output-file))
- (let ((system-time-locale (map-elt (ennum-setting :locale-alist)
- (ennum-post-language post) nil 'string=)))
- (ennum-with-file-contents input-org-file
- ;; TODO: Centralize these with feed generation
- (org-export-to-file
- 'ennum-html output-file nil nil nil nil
- (list :ennum-translations (seq-remove (apply-partially 'equal post) posts)
- :ennum-video-posters (ennum-post-video-posters post))))))))
- (when (ennum-post-tangle post)
- (list
- (ennum-exp
- ;; TODO: Handle tangle outputs that are nested
- ;; into directories, and when each tangle output
- ;; is nested into a different directory.
- (let* ((input-org-file (ennum-input (ennum-intern (ennum-post-filename post))))
- (post-file-copy
- (expand-file-name
- (file-name-nondirectory input-org-file)
- (ennum-setting :static-directory))))
- (ennum-copy input-org-file post-file-copy)
- (org-babel-tangle-file post-file-copy)
- (delete-file post-file-copy)))))
- (seq-mapcat 'ennum-publish-link (ennum-post-links post))))
- posts))
+(defun ennum-publish-post (post)
+ (append
+ (list
+ (ennum-exp
+ (let ((input-org-file (ennum-input (ennum-intern (ennum-post-filename post))))
+ (output-file
+ (ennum--org-output-filename (ennum-post-filename post))))
+ (ennum-mkdir-p (file-name-directory output-file))
+ (let ((system-time-locale (map-elt (ennum-setting :locale-alist)
+ (ennum-post-language post) nil 'string=)))
+ (ennum-with-file-contents input-org-file
+ ;; TODO: Centralize these with feed generation
+ (org-export-to-file
+ 'ennum-html output-file nil nil nil nil
+ (list :ennum-translations (ennum-post-translations post)
+ :ennum-video-posters (ennum-post-video-posters post))))))))
+ (when (ennum-post-tangle post)
+ (list
+ (ennum-exp
+ ;; TODO: Handle tangle outputs that are nested
+ ;; into directories, and when each tangle output
+ ;; is nested into a different directory.
+ (let* ((input-org-file (ennum-input (ennum-intern (ennum-post-filename post))))
+ (post-file-copy
+ (expand-file-name
+ (file-name-nondirectory input-org-file)
+ (ennum-setting :static-directory))))
+ (ennum-copy input-org-file post-file-copy)
+ (org-babel-tangle-file post-file-copy)
+ (delete-file post-file-copy)))))
+ (seq-mapcat 'ennum-publish-link (ennum-post-links post))))
(defun ennum-publish-generic (other-files-directory file)
(ennum-exp
@@ -560,9 +578,7 @@ as keys. Keys are compared using `equal'."
(ennum-store-item-union
(append
;; Publish posts
- (seq-mapcat (pcase-lambda (`(,translation-group . ,posts))
- (ennum-publish-post posts))
- (seq-group-by 'ennum-post-translation-group posts))
+ (seq-mapcat 'ennum-publish-post posts)
;; Publish feed
(list (ennum-publish-feed (ennum-setting :atom-feed-file)
blog-title