当我们用 Emacs org 记了大量的笔记、写了大量的经验总结,我们当然会想着把它们发布成网站。通过把笔记发布成网页,我们可以方便地与他人分享我们的经验。总的来说,比较常用的方法有下面三类:

第一,如果只是发布成静态网页,使用 org 内置的页面发布功能就足够了(或查看这个文档)。

第二,如果我们需要更加复杂、抽象的功能,可以使用 blorg 或是 blorgit 工具。

第三,通过使用下面 Manoj Srivastav 提供的 Ikiwiki 插件,我们可以让 org 作为我们的 Ikiwiki 输入引擎。

#!/usr/bin/perl
# File: org.pm
# Time-stamp: <2009-02-06 12:10:28 srivasta>
#
# Copyright (C) 2008 by Manoj Srivastava
#
# Author: Manoj Srivastava
#
# Description:
# This allows people to write Ikiwiki content using Emacs and org-mode
# (requires Emacs 23), and uses the html export facility of org-mode to
# create the output. Some bits based on otl.pm.

package IkiWiki::Plugin::org;
use warnings;
use strict;
use Carp;
use IkiWiki 3.00;

use File::Temp qw/ tempfile tempdir /;

# ------------------------------------------------------------

sub import {
  hook(type => "getsetup", id => "org", call => \&getsetup);
  hook(type => "htmlize",  id => "org", call => \&htmlize);
} #

sub getsetup () {
  return
    plugin => {
               safe => 0,
               rebuild => undef,
               advanced => 1,
              },
    emacs_binary => {
                     type => "string",
                     example => "/usr/bin/emacs-snapshot",
                     description => "location of an emacs binary with org-mode",
                     advanced => 1,
                     safe => 0,
                     rebuild => undef,
                    },
}



sub htmlize (@) {
  my %params  = @_;
  my $dir     = File::Temp->newdir();



  my $ret = open(INPUT, ">$dir/contents.org");
  unless (defined $ret) {
    debug("failed to open $dir/contents.org: $@");
    return $params{content};
  }
  my $emacs = '/usr/bin/emacs-snapshot';
  if (exists $config{emacs_binary} && -x $config{emacs_binary}) {
    $emacs = $config{emacs_binary};
  }
  print INPUT $params{content};
  close INPUT;
  $ret = open(INPUT, ">/tmp/contents.org");
  print INPUT $params{content};
  close INPUT;
  my $args = "$emacs --batch -l org " .
              "--eval '(setq org-export-headline-levels 3 org-export-with-toc nil org-export-author-info nil )' " .
              "--visit=$dir/contents.org " .
              '--funcall org-export-as-html-batch >/dev/null 2>&1';
  if (system($args)) {
    debug("failed to convert $params{page}: $@");
    return $params{content};
  }
  $ret = open(OUTPUT, "$dir/contents.html");
  unless (defined $ret) {
    debug("failed find html output for $params{page}: $@");
    return $params{content};
  }
  local $/ = undef;
  $ret = <OUTPUT>;
  close OUTPUT;
  $ret=~s/(.*<h1 class="title">){1}?//s;
  $ret=~s/^(.*<\/h1>){1}?//s;
  $ret=~s/<div id="postamble">.*//s;
  $ret=~s/(<\/div>\s*$)//s;
  open(OUTPUT, ">/tmp/contents.html");
  print OUTPUT $ret;
  close OUTPUT;

  return $ret;
}

# ------------------------------------------------------------
1; # modules have to return a true value

我使用第一种方法,比较简单,缺点是与读者的互动性比较差。

原创文章,如转载请注明:转载自细节之锤 [ http://blog.waterlin.org/ ]

Copyright © WaterLin.org. All rights reserved.