Emacsist RSS --- If never, make it ever: C-h C-h

Blogging with Orgmode


这里 查看更多 Emacs 相关推荐文章最新 Emacs 圈的动态. 欢迎关注微信公众账号: Emacsist

After several attempts of trying to get Orgmode working for my blog, I think I've finally settled on a workable solution using org-publish and a free static hosting service that works with Dropbox.


I tried to keep the scope limited while moving to Orgmode, to keep things simple.

  1. Use Orgmode, duh!
  2. Publish the entire site as a single Orgmode project
  3. Use the auto-generated sitemap as the index (don't want to manually add links to new blog posts)
  4. Free static hosting with custom domain

Setting up the project

Here's my website's Orgmode project defintion defined in my Emacs config1:

 1: (setq org-publish-project-alist
 2:       `(("website"
 3:          :base-directory "~/Dropbox/Apps/updog/john2x/"
 4:          :publishing-directory "~/Dropbox/Apps/updog/john2x/"
 5:          :recursive t
 6:          :exclude "level-.*\\|.*\.draft\.org"
 7:          :publishing-function org-html-publish-to-html
 8:          :auto-sitemap t
 9:          :sitemap-filename "index.org"
10:          :sitemap-title "John Louis Del Rosario"
11:          :sitemap-sort-files "chronologically"
12:          :sitemap-function my-website-sitemap-function
13:          :html-link-up "/"
14:          :html-link-home "/"
15:          :html-preamble "<p class=\"date\">Published: %d</p>"
16:          :html-postamble "<p class=\"date\">Modified: %T</p>")))

Let's go over the interesting properties:

  1. [:publishing-directory](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-publishing-directory): We use the same publishing directory since we want the generated html files to live alongside their source org files.
  2. [:recursive](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-recursive): Recursively export all org files within the :base-directory.
  3. [:exclude](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-exclude): Exclude some files from being exported and listed in the sitemap during publishing (e.g. drafts prefixed with .draft.org will not be published).
  4. [:auto-sitemap](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-auto-sitemap): Turn on automatic sitemap creation/updating when re-publishing the project.
  5. [:sitemap-filename](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-sitemap-filename): Name the generated sitemap as index.org so it gets published as index.html.
  6. [:sitemap-sort-files](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-sitemap-sort-files): Sort sitemap links based on the files' dates, useful for the blog posts.
  7. [:sitemap-function](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-sitemap-function): Use a custom function to generate the sitemap. We'll take a look at this shortly.
  8. [:html-(pre|post)amble](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-preamble): Use custom preamble. Although the docs say we could specify the pre/postamble as options (e.g. #+OPTIONS: html-preamble:"foo"), which would have been ideal, it doesn't seem to work with Orgmode 8.3.4. So we hardcode it at the project level.

I wanted my index page to have all the links needed automatically added, which the sitemap function does nicely. But since the sitemap file is re-generated on every publish, I have to insert/remove any content from it via a custom sitemap generator function.

(defun my-website-sitemap-function (project &optional sitemap-filename)
  "Custom sitemap generator that inserts additional options."
  (let ((buffer (org-publish-org-sitemap project sitemap-filename)))
    (with-current-buffer buffer
      (insert "\n#+OPTIONS: html-preamble:nil")
      (insert "\n#+SUBTITLE: a.k.a. john2x")
      (insert "\n\n#+BEGIN_EXAMPLE")
      (insert "\nCopyright (c) 2016 John Louis Del Rosario")
      (insert "\n#+END_EXAMPLE")

It basically takes the output from the default sitemap function and adds/removes custom content.

Setup files

Orgmode allows documents to reference a SETUPFILE, which is basically an "included" template. This is useful for defining common header options across documents. For example:

#+SETUPFILE: path/to/setup_file.org

For this site, I have three setup files defined:

  1. A base template, org-templates/level-0.org
  2. A template specific for blog posts, org-templates/level-0-blog.org
  3. A template specific for one-off pages (e.g. the about page), org-templates/level-0-page.org

The level-0 prefix was taken from Sebastian Rose's publishing tutorial2. It also makes excluding the templates easier.

The blog post template includes the base template, and it enables the rendering of the table of contents.

The page template includes the base template, and disables the preamble.


Previous attempts

Github Pages

The previous version of this site was using Jekyll on Github Pages. I was hoping I could continue using Github Pages, but unfortunately there was no way to disable Jekyll processing. So my exported documents all came out incorrectly.

Bitbucket static file hosting

Next I looked into Bitbucket's undocumented feature to serve static content (similar to Github Pages, but without Jekyll). It works great, but they don't allow custom domains.

What's up dog?

I finally stumbled on updog.co, a free service that serves files directly from your Dropbox folder. It also allows custom domains for each site. Since I already have a Dropbox account, I didn't have to shell out any cash. And if/when the service goes down, the owner is cool enough to provide the source3, so if I can't find an alternative, I'd just bite the bullet and probably run my own instance of the service.


So now that I have everything set up, writing a new post is a great experience. I get to write using Org, which makes writing more enjoyable. For drafts that aren't ready for publishing yet (but which I'd like to view a render of), I just need to name them *.draft.org and they won't be listed in the sitemap.

Once everything is ready, a simple C-c C-e P p publishes everything and Dropbox + updog.co does the rest!


There's still some rough edges I'd like to iron out.

  1. The index/sitemap is very bare bones. I'll probably write an improved sitemap function in the future.
  2. I'm still trying to figure out how to generate an RSS feed.
  3. I'd like to render the KEYWORDS option in a post (since Google ignores the keywords meta tag).
  4. My favicon doesn't seem to be loaded. I wanted to use the Orgmode unicorn.
  5. The style is pretty much non-existent at the moment. Mostly due to laziness, but I kind of like the aesthetic of it (especially if using the Computer Modern font4).

Copyright (c) 2016 John Louis Del Rosario



View my Emacs config in full here http://www.john2x.com/emacs.html







原文出处: John Louis Del Rosario
原文地址: http://www.john2x.com/blog/blogging-with-orgmode.html
原文时间: 2016-04-25 10:26
本文地址: http://emacsist.com/10863
整理时间: 2016-04-28 01:50

本文由 Hick 整理,转载请保留以上信息;
COPYLEFTThe articles on this site come from Internet, thanks to all the original authors.
      If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .