From bc5af186471866cd99594b3da83f23fac7d03074 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 24 Jun 2021 23:00:11 -0700 Subject: [PATCH] Update metadata in org file after sending --- tekuti.el | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tekuti.el b/tekuti.el index 9545fcc..6a2f0f5 100644 --- a/tekuti.el +++ b/tekuti.el @@ -93,8 +93,26 @@ data "&")) -(defun tekuti--send-finished (status &rest _) - (message "Finished: %s" status)) +(defun tekuti--send-finished (status buffer args) + (pcase-exhaustive status + (`(:redirect ,url) + (save-excursion + (with-current-buffer buffer + (goto-char (point-min)) + (search-forward "\n\n") + (backward-char) + (let ((data (org-collect-keywords '("TITLE" "TAGS" "STATUS" "COMMENTS" "DATE" "COMMENTS_DATE")))) + (mapc (lambda (item) + (let ((key (car item)) + (value (cadr item))) + (when (and (not (string= key "BODY")) + (null (alist-get key data nil nil #'string=)) + (not (null value))) + (insert "#+" key ": " value "\n")))) + args)))) + (message "Created new post: %s" url)) + (`(:error (error http ,code)) + (message "Failed to create post: %d" code)))) ;;;###autoload (defun tekuti-send () @@ -104,7 +122,9 @@ (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) #'tekuti--send-finished))) + (url-retrieve (format "%s/admin/new-post" tekuti-host) + #'tekuti--send-finished + (list (current-buffer) data)))) (provide 'tekuti) ;;; tekuti.el ends here