Extract data parsing into separate function

This commit is contained in:
Tom Willemse 2023-12-07 22:21:50 -08:00
parent 8bd0ba25e4
commit cf761c40a5

View file

@ -56,6 +56,17 @@ with a /.")
(date-to-time date)) (date-to-time date))
t)) t))
(defun tekuti--parse-data-keyword (pair)
"Ensure that both the key and value in PAIR match what tekuti needs."
(pcase pair
(`("DATE" ,date)
(list "DATE" (tekuti--format-date date)))
(`("COMMENTS_DATE" ,date)
(list "COMMENTS-CLOSED-DATE"
(and (not (string-empty-p date))
(tekuti--format-date date))))
(_ pair)))
(defun tekuti-build-data-from-org () (defun tekuti-build-data-from-org ()
"Parse the current org buffer to collect the necessary metadata." "Parse the current org buffer to collect the necessary metadata."
(let ((defaults `(("TITLE") (let ((defaults `(("TITLE")
@ -67,15 +78,7 @@ with a /.")
("BODY"))) ("BODY")))
(data (append (data (append
(mapcar (mapcar
(lambda (pair) #'tekuti--parse-data-keyword
(pcase pair
(`("DATE" ,date)
(list "DATE" (tekuti--format-date date)))
(`("COMMENTS_DATE" ,date)
(list "COMMENTS-CLOSED-DATE"
(and (not (string-empty-p date))
(tekuti--format-date date))))
(_ pair)))
(org-collect-keywords '("TITLE" "TAGS" "STATUS" "COMMENT_STATUS" "DATE" "COMMENTS_DATE"))) (org-collect-keywords '("TITLE" "TAGS" "STATUS" "COMMENT_STATUS" "DATE" "COMMENTS_DATE")))
(list (list
(list "BODY" (list "BODY"