Publish Webpages Using Org

Table of Contents

1 How to publish org files as a web project?

When we write a lot of notes using org mode in Emacs, we want to publish them into webpages as a project. By doing this, we can make the notes like a Wiki site. We have a lot way to do this job.

For "static html" using the built in publishing features of Org-mode is probably sufficient (or check this manual).

If we want to get more sophisticated (and complicated), we could also take a look at blorg or blorgit.

With the following Ikiwiki plugin of Manoj Srivastava, we can use org as Ikiwiki input mechanism.

#!/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

I am using the built in publishing features of Org-mode, because it is the easiest way.

2 Search my webs


comments powered by Disqus

Date: 2014-02-14T14:40+0800

Author: Water Lin

Org version 7.9.3f with Emacs version 24

Validate XHTML 1.0