Posting org buffers with weblogger.el to your blog

Tagged:  
In my last post, I described how to setup weblogger.el with Drupal. Since I love to write posts like this with org (see this posting for details on how you can do this), I wrote myself a little helper function to directly export an org file to a weblogger entry:
(defun DE-org-export-weblogger ()
  (interactive)
  (let ((tmpbuffer (get-buffer-create " *org html export*"))
        title text)
    ;; export posting to HTML, but without headers
    (org-export-as-html 1 nil nil tmpbuffer t)
    (set-buffer tmpbuffer)
    (goto-char (point-min))
    ;; get the title
    (when (re-search-forward "<div id=\"outline-container-1\" class=\"outline-2\">[^\0]*\
<h2 id=\"sec-1\">\\(.*?\\)</h2>[^\0]*\
<div class=\"outline-text-2\" id=\"text-1\">"
                     nil t)
      (setq title (match-string 1))
      (replace-match ""))
    ;; get the posting
    (setq text (buffer-substring-no-properties (point) (point-max)))
    (weblogger-start-entry)
    (insert title)
    (goto-char (point-max))
    (insert text)
    (kill-buffer tmpbuffer)))

You can now simply call DE-org-export-weblogger interactively on your org file, and it will create a new weblogger entry buffer. Determining the title of the posting is a bit hacky; it assumes that your org file looks something like this:

* Title of your blog post

text of your blog post

It will then extract the title from the HTML exported output. You can still edit the produced HTML, maybe inserting your taxonomy tags, and then post it by pressing C-x C-s.

This of course assumes that your default input format for blogs is "Full HTML", otherwise most of the HTML tags will get stripped and everything will just look plain ugly. You can set the default input format in Drupal under site configuration -> Input formats.

BTW, I totally forgot to mention in my last post that you can also edit existing Drupal blog entries with weblogger. Simply press C-c C-p or C-c C-n for the previous/next entry!

Hi, I'm practically illiterate in elisp. Your function gives me a error: let: Wrong number of arguments: #[(arg &optional hidden ext-plist) I'm using Emacs 22.1.1 under Ubuntu. Could you drive me to fix it? Thanks in advantage