aboutsummaryrefslogtreecommitdiffstats
path: root/tekuti.el
diff options
context:
space:
mode:
authorGravatar Tom Willemse2021-06-24 22:02:52 -0700
committerGravatar Tom Willemse2021-06-24 22:02:52 -0700
commit7ce1d86c05ac427e9ade91a4effa4302bc3cc969 (patch)
tree5443118c77954c31df13691593ff426328451cbe /tekuti.el
parent7b5322b3132d3876eb8037b7735035fb72e7342e (diff)
downloadtekuti-el-7ce1d86c05ac427e9ade91a4effa4302bc3cc969.tar.gz
tekuti-el-7ce1d86c05ac427e9ade91a4effa4302bc3cc969.zip
Add defaults for the data from the org buffer
Diffstat (limited to 'tekuti.el')
-rw-r--r--tekuti.el58
1 files changed, 37 insertions, 21 deletions
diff --git a/tekuti.el b/tekuti.el
index 5683b10..9545fcc 100644
--- a/tekuti.el
+++ b/tekuti.el
@@ -44,30 +44,44 @@
(defvar tekuti-host "http://127.0.0.1:8080")
-(defun tekuti--format-date (date)
+(defun tekuti--format-date (&optional date)
"Format DATE into a date that tekuti understands."
(format-time-string "%a, %d %b %Y %H:%M:%S %Z"
- (org-timestamp-to-time
- (org-timestamp-from-string date))
+ (unless (null date)
+ (org-timestamp-to-time
+ (org-timestamp-from-string date)))
t))
(defun tekuti-build-data-from-org ()
- (append
- (mapcar
- (lambda (pair)
- (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" "COMMENTS" "DATE" "COMMENTS_DATE")))
- (list
- (list "BODY"
- (with-current-buffer (org-html-export-as-html nil nil nil t)
- (buffer-substring-no-properties (point-min) (point-max)))))))
+ "Parse the current org buffer to collect the necessary metadata."
+ (let ((defaults `(("TITLE")
+ ("DATE" ,(tekuti--format-date))
+ ("TAGS")
+ ("STATUS")
+ ("COMMENTS")
+ ("COMMENTS-CLOSED-DATE")
+ ("BODY")))
+ (data (append
+ (mapcar
+ (lambda (pair)
+ (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" "COMMENTS" "DATE" "COMMENTS_DATE")))
+ (list
+ (list "BODY"
+ (with-current-buffer (org-html-export-as-html nil nil nil t)
+ (buffer-substring-no-properties (point-min) (point-max))))))))
+ (mapcar (lambda (item)
+ (let ((key (car item)))
+ `(,key ,@(or (alist-get key data nil nil #'string=)
+ (cdr item)))))
+ defaults)))
(defun tekuti-form-encode-pair (key value)
(concat (url-hexify-string key) "=" (url-hexify-string value)))
@@ -79,6 +93,9 @@
data
"&"))
+(defun tekuti--send-finished (status &rest _)
+ (message "Finished: %s" status))
+
;;;###autoload
(defun tekuti-send ()
(interactive)
@@ -87,8 +104,7 @@
(url-request-extra-headers
`(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data (tekuti-form-encode-data data)))
- (url-retrieve (format "%s/admin/new-post" tekuti-host)
- (lambda (status &rest _) (message "Finished: %s" status)))))
+ (url-retrieve (format "%s/admin/new-post" tekuti-host) #'tekuti--send-finished)))
(provide 'tekuti)
;;; tekuti.el ends here