Add defaults for the data from the org buffer
This commit is contained in:
parent
7b5322b313
commit
7ce1d86c05
1 changed files with 37 additions and 21 deletions
28
tekuti.el
28
tekuti.el
|
@ -44,15 +44,24 @@
|
|||
|
||||
(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"
|
||||
(unless (null date)
|
||||
(org-timestamp-to-time
|
||||
(org-timestamp-from-string date))
|
||||
(org-timestamp-from-string date)))
|
||||
t))
|
||||
|
||||
(defun tekuti-build-data-from-org ()
|
||||
(append
|
||||
"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
|
||||
|
@ -67,7 +76,12 @@
|
|||
(list
|
||||
(list "BODY"
|
||||
(with-current-buffer (org-html-export-as-html nil nil nil t)
|
||||
(buffer-substring-no-properties (point-min) (point-max)))))))
|
||||
(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
|
||||
|
|
Loading…
Reference in a new issue