aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2020-08-01 05:20:29 +0530
committerArun Isaac2020-08-01 20:15:52 +0530
commitd45b6e3aa3c1ffa0a37a4276dbd0e51ee44c32af (patch)
tree1e1cf417d45abeffa3bfe8bbf0a2e89f4a76cb28
parent30e1efc4051a67e6e41561f45101c9077dc41e2e (diff)
downloadennum-d45b6e3aa3c1ffa0a37a4276dbd0e51ee44c32af.tar.gz
ennum-d45b6e3aa3c1ffa0a37a4276dbd0e51ee44c32af.tar.lz
ennum-d45b6e3aa3c1ffa0a37a4276dbd0e51ee44c32af.zip
Embed list of translations into post object.
* ennum.el (ennum-post): Add ennum-copy-post copier and translations slot. (ennum-posts): Set translations slot. (ennum-publish-post): Publish a single post, not a translation group of posts. (ennum-publish): Pass posts to ennum-publish-post one by one, without grouping. * ennum-html.el (ennum-html-inner-template): Use translations alist.
-rw-r--r--ennum-html.el18
-rw-r--r--ennum.el108
2 files changed, 70 insertions, 56 deletions
diff --git a/ennum-html.el b/ennum-html.el
index f091789..bfad18f 100644
--- a/ennum-html.el
+++ b/ennum-html.el
@@ -233,16 +233,14 @@
(when-let (translations (plist-get info :ennum-translations))
(format "<p>In other languages: %s</p>"
(mapconcat
- (lambda (translation)
- (let ((lang (ennum-post-language translation))
- (slug (ennum-post-slug translation)))
- (replace-regexp-in-string
- "<a " (format "<a hreflang=\"%s\" " lang)
- (ennum-html-export-post
- slug
- (map-elt ennum-html--iso-639-1-alist lang nil 'string=)
- (org-export-backend-name
- (plist-get info :back-end))))))
+ (pcase-lambda (`(,lang . ,slug))
+ (replace-regexp-in-string
+ "<a " (format "<a hreflang=\"%s\" " lang)
+ (ennum-html-export-post
+ slug
+ (map-elt ennum-html--iso-639-1-alist lang nil 'string=)
+ (org-export-backend-name
+ (plist-get info :back-end)))))
translations
", ")))
;; Tags
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