Skip to content

Instantly share code, notes, and snippets.

@boykov
Last active December 10, 2015 06:28
Show Gist options
  • Save boykov/4394477 to your computer and use it in GitHub Desktop.
Save boykov/4394477 to your computer and use it in GitHub Desktop.
(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