💾 Archived View for perplexing.space › 2020 › re-emacsposting-to-gemlog-blue.gmi captured on 2022-06-03 at 23:00:47. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2020-09-24)
-=-=-=-=-=-=-
2020-09-04
A quick thought regarding acdw's recent entry⁰ about posting entries directly to gemlog.blue from emacs.
acdw mentions a stretch goal of using emacs' own URL module instead of the emacs-requests, it happens that what he has done is almost usable by the url module already. The mm-url module (originally written for gnus) provides a necessary url encoding helper function "mm-url-encode-www-form-urlencoded" (what a mouthful!), but it takes a list of pairs in much the same way as the emacs-requests format, set a Content-Type and Bob's your uncle.
(defun post-to-gemlog-blue (post-title user pass) (interactive "sTitle: \nsUsername: \nsPassword: ") (let ((url-request-method "POST") (url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded"))) (url-request-data (mm-url-encode-www-form-urlencoded `(("title" . ,post-title) ("gemloguser" . ,user) ("pw" . ,pass) ("post" . ,(buffer-string)))))) (with-current-buffer (url-retrieve-synchronously "https://gemlog.blue/post.php") (goto-char (point-min)) (re-search-forward "\\(gemini://.*\\.gmi\\)") (elpher-go (match-string 1)))))
gemlog.blue returns a full page of HTML with the gemini link embedded in it, so passing the result buffer (the output of url-retrieve-synchronously) to with-current-buffer allows some grungy text munging to carve up the text/HTML appropriately. With a single gemini URI available through the regex group, elpher can be launched. This could be a lot cleaner and more robust, emacs has a number of XML/HTML libraries that could probably parse the resulting HTML. As far as neat hacks though, this seems to work fine.
In testing the above snippet out I ended up creating and deleting a number of entries -- pardon the dust!