Last active
December 10, 2015 06:28
-
-
Save boykov/4394477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun gblogger-post-entry () | |
"Posts current Org entry to blogger" | |
(interactive) | |
(let ((body (org-get-entry)) | |
(name (org-get-heading t t)) | |
(tags (mapconcat 'identity (org-get-local-tags) ",")) | |
(file-name (concat | |
temporary-file-directory | |
(make-temp-name "blogger-org-export-") | |
".html"))) | |
(save-current-buffer | |
(with-temp-buffer | |
(insert body) | |
;; insert title if not provided | |
(beginning-of-buffer) | |
(if (not (search-forward-regexp | |
"^#+TITLE:" (point-max) t)) | |
(progn | |
(end-of-buffer) | |
(insert (concat "\n#+TITLE: " name)))) | |
;; insert export options if required | |
(beginning-of-buffer) | |
(if (not (search-forward-regexp | |
"^#+OPTIONS:" (point-max) t)) | |
(progn | |
(end-of-buffer) | |
(insert (concat | |
"\n" gblogger-org-export-options "\n")))) | |
;; export into temporary buffer | |
(org-mode) | |
(org-export-as-html nil nil nil "*blogger temp buffer*" t)) | |
;; before publishing we need to make some cleanup | |
(switch-to-buffer "*blogger temp buffer*") | |
(write-file file-name) | |
(kill-buffer) | |
(start-process-shell-command | |
"googlecl" nil (concat | |
"google blogger post --title=\"" name | |
"\" --tags=\"" tags "\" --src=" file-name)) | |
(delete-file file-name)))) | |
(defvar | |
gblogger-org-export-options | |
"#+OPTIONS: H:3 toc:nil @:t ::nil \\n:t |:t ^:nil *:t tags:nil" | |
"Default org export options. Will be used if no options are found in the entry") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment