summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2020-08-01 21:42:32 +0530
committerArun Isaac2020-08-02 03:20:16 +0530
commit14d46e1aefa33f3ca2d14db6aa2e54623c7a069d (patch)
tree646784025308f86ee6e9a90ef0724e1a33dbc8c4
parent5fb7f96d886848f6d3b2401a895fb1e203190ca9 (diff)
downloadennum-14d46e1aefa33f3ca2d14db6aa2e54623c7a069d.tar.gz
ennum-14d46e1aefa33f3ca2d14db6aa2e54623c7a069d.tar.lz
ennum-14d46e1aefa33f3ca2d14db6aa2e54623c7a069d.zip
Embed post link target title in post-link object.
* ennum.el (ennum-post-set-links, ennum-post-link-set-target-title): New functions. (ennum-post-link): New type. (ennum--read-post): Create post-link object when applicable. (ennum-posts): Set target-title slot of post-link objects.
-rw-r--r--ennum.el55
1 files changed, 45 insertions, 10 deletions
diff --git a/ennum.el b/ennum.el
index 00927df..6cd5757 100644
--- a/ennum.el
+++ b/ennum.el
@@ -144,10 +144,21 @@ respectively by - and _, and the pad character = is optional."
(ennum-make-functional-setter
ennum-post-set-translations ennum-copy-post ennum-post-translations)
+(ennum-make-functional-setter
+ ennum-post-set-links ennum-copy-post ennum-post-links)
+
(cl-defstruct (ennum-link (:constructor ennum-make-link)
(:copier nil))
type path)
+(cl-defstruct (ennum-post-link (:constructor ennum-make-post-link)
+ (:copier ennum-copy-post-link)
+ (:include ennum-link (type 'post)))
+ target-title)
+
+(ennum-make-functional-setter
+ ennum-post-link-set-target-title ennum-copy-post-link ennum-post-link-target-title)
+
(cl-defstruct (ennum-video-link (:constructor ennum-make-video-link)
(:copier nil)
(:include ennum-link (type 'video)))
@@ -169,16 +180,35 @@ respectively by - and _, and the pad character = is optional."
(string= (ennum-post-slug post) slug))
translations)))
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)))))
+ (let ((posts
+ ;; Read posts from org files.
+ (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)))))
+ ;; Group posts by translation group.
+ (seq-group-by
+ 'ennum-post-translation-group
+ ;; Set target title slot of post links.
+ (seq-map
+ (lambda (post)
+ (ennum-post-set-links
+ post
+ (seq-map (lambda (link)
+ (if (and (ennum-post-link-p link)
+ (eq (ennum-post-link-target-title link) 'required))
+ (ennum-post-link-set-target-title
+ link
+ (seq-some (lambda (post)
+ (when (string= (ennum-post-slug post)
+ (ennum-link-path link))
+ (ennum-post-title post)))
+ posts))
+ link))
+ (ennum-post-links post))))
+ posts))))
'ennum-later-post-p))
(defun ennum-later-post-p (post1 post2)
@@ -206,6 +236,11 @@ respectively by - and _, and the pad character = is optional."
(let ((link-type (org-element-property :type link))
(path (org-element-property :path link)))
(pcase link-type
+ ("post"
+ (ennum-make-post-link
+ :path path
+ :target-title (if (org-element-contents link)
+ 'not-required 'required)))
("video"
(ennum-make-video-link
:path path