summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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