aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2021-06-03 23:26:47 -0700
committerGravatar Tom Willemse2021-06-03 23:26:47 -0700
commit80ab0599af1046eb36c7d961f4a49bb494b5d14d (patch)
tree7b8ef0392dad5ff27118cf0cdb0ab72cae12ca86
downloadtekuti-el-80ab0599af1046eb36c7d961f4a49bb494b5d14d.tar.gz
tekuti-el-80ab0599af1046eb36c7d961f4a49bb494b5d14d.zip
Initial commit
-rw-r--r--tekuti.el93
1 files changed, 93 insertions, 0 deletions
diff --git a/tekuti.el b/tekuti.el
new file mode 100644
index 0000000..55a3f63
--- /dev/null
+++ b/tekuti.el
@@ -0,0 +1,93 @@
+;;; tekuti.el --- Tekuti interaction library -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Tom Willemse
+
+;; Author: Tom Willemse <chelys@data>
+;; Keywords: comm
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; A simple module to help post things to your tekuti blog. You’ll want to
+;; customize the ‘tekuti-host’ variable to point to your own blog. You should be
+;; asked for your credentials, which should then be stored in ~/.authinfo.gpg.
+
+;; Currently you should add these headers to your org document that you want to
+;; send up:
+
+;; #+TITLE: SOME TITLE
+;; #+DATE: <2021-06-03 Thu 22:45>
+;; #+TAGS: comma,separated
+;; #+COMMENTS: open
+;; #+COMMENTS_DATE:
+;; #+STATUS: publish
+
+;; The main entry point is ‘tekuti-send’. Call this from an org-mode buffer to
+;; export the buffer to HTML and send it up to your blog.
+
+;;; Code:
+
+(defun tekuti-build-data-from-org ()
+ (append
+ (mapcar
+ (lambda (pair)
+ (pcase pair
+ (`("DATE" ,date)
+ (list "DATE"
+ (format-time-string
+ "%a, %d %b %Y %H:%M:%S %Z"
+ (org-timestamp-to-time
+ (org-timestamp-from-string date))
+ t)))
+ (`("COMMENTS_DATE" ,date)
+ (list "COMMENTS-CLOSED-DATE"
+ (and (not (string-empty-p date))
+ (format-time-string
+ "%a, %d %b %Y %H:%M:%S %Z"
+ (org-timestamp-to-time
+ (org-timestamp-from-string date))
+ t))))
+ (_ 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)))))))
+
+(defun tekuti-form-encode-pair (key value)
+ (concat (url-hexify-string key) "=" (url-hexify-string value)))
+
+(defun tekuti-form-encode-data (data)
+ (mapconcat
+ (lambda (pair)
+ (tekuti-form-encode-pair (downcase (car pair)) (cadr pair)))
+ data
+ "&"))
+
+;;;###autoload
+(defun tekuti-send ()
+ (interactive)
+ (let* ((data (tekuti-build-data-from-org))
+ (url-request-method "POST")
+ (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 args) (message "Finished: %s" status)))))
+
+(defvar tekuti-host "http://127.0.0.1:8080")
+
+(provide 'tekuti)
+;;; tekuti.el ends here