Publishing Emacs News as plain text, HTML, and attached Org file

Posted: - Modified: | emacs, org

Update 2016-02-05: Since @ThierryStoehr linked to this post about Emacs News-related code, I figured I'd add a link to the other support functions I've been using to help me with Emacs News summarization. There's also this bit:

(let ((date (org-read-date nil nil "-mon")))
    (concat
     (my/org-list-from-rss "http://planet.emacsen.org/atom.xml" date) "\n"
     (shell-command-to-string (concat "~/bin/list-reddit-links.coffee emacs " date)) "\n"
     (shell-command-to-string (concat "~/bin/list-reddit-links.coffee org-mode " date)) "\n"
     "- New packages:\n"
     (my/list-new-packages) 
     "\n"))

Handy little things!

——

I've been publishing these weekly summaries of Emacs-related links on my blog and to the emacs-tangents mailing list / newsgroup. I started by posting plain text from Org Mode's ASCII export, and people asked for Org Mode and HTML formats. So here's some code that prepares things for pasting into a Gnus message buffer.

It turns out that order matters for multipart/alternative – start with plain text, then include richer alternatives. First time around, I put the HTML version first, so people didn't end up seeing it. Anyway, here's something that shows up properly now: text/plain, then text/html, with text/x-org attached. The heavy lifting is done with org-export-string-as, which exports into different formats.

  (defun my/share-emacs-news ()
    "Prepare current subtree for yanking into post."
    (interactive)
    ;; Draft Gnus article
    (save-restriction
      (org-narrow-to-subtree)
      (let ((org-export-html-preamble nil)
            (org-html-toplevel-hlevel 3)
            output)
        (setq output
              (apply
               'format
               "<#multipart type=alternative>
<#part type=\"text/plain\" disposition=inline>
%s
<#/part>
<#part type=\"text/html\" disposition=inline>
%s
<#/part>
<#/multipart>
<#part type=\"text/x-org\" disposition=attachment name=\"emacs-news.org\">
%s
<#/part>
"
               (mapcar
                (lambda (format)
                  (org-export-string-as (buffer-substring (point-min) (point-max)) format t))
                '(ascii html org))))
        (kill-new output))))

Howard Abrams showed me something like this in June 2015's Emacs Hangout (~1:18:26) using org-mime-org-buffer-htmlize, which probably does the job in a much cooler way. =) I thought he had a blog post about it, but I can't seem to find it. Anyway, there's my little hack above!

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.