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.
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:
[: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.
[:recursive](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-recursive): Recursively export all org files within the
[: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.orgwill not be published).
[: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.
[:sitemap-filename](http://www.john2x.com/blog/blogging-with-orgmode.html#coderef-sitemap-filename): Name the generated sitemap as
index.orgso it gets published as
[: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.
[: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.
[: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") (save-buffer))))
It basically takes the output from the default sitemap function and adds/removes custom content.
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:
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.
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.
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.
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.
KEYWORDSoption in a post (since Google ignores the
Copyright (c) 2016 John Louis Del Rosario
View my Emacs config in full here http://www.john2x.com/emacs.html
原文出处: John Louis Del Rosario
原文时间: 2016-04-25 10:26
整理时间: 2016-04-28 01:50
本文由 Hick 整理，转载请保留以上信息;
The 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 .