From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Barton Subject: Re: Re: Is there a good way to use org as blog system? Date: Tue, 10 Nov 2009 15:05:00 +0000 Message-ID: <4AF9811C.9080309@manor-farm.org> References: <83eipo4wd0.fsf@ymail.com> <874oqkh6cj.fsf@anzu.internal.golden-gryphon.com> Reply-To: lists@manor-farm.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N7sHO-0006eJ-FC for emacs-orgmode@gnu.org; Tue, 10 Nov 2009 10:05:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N7sHM-0006dG-Cu for emacs-orgmode@gnu.org; Tue, 10 Nov 2009 10:05:09 -0500 Received: from [199.232.76.173] (port=58600 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7sHM-0006d1-3Z for emacs-orgmode@gnu.org; Tue, 10 Nov 2009 10:05:08 -0500 Received: from li40-130.members.linode.com ([72.14.178.130]:48208) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N7sHL-0005gb-Bd for emacs-orgmode@gnu.org; Tue, 10 Nov 2009 10:05:07 -0500 Received: from localhost (mail.wilkesley.org [127.0.0.1]) by li40-130.members.linode.com (Postfix) with ESMTP id 42D7BCF0E for ; Tue, 10 Nov 2009 15:05:05 +0000 (GMT) Received: from li40-130.members.linode.com ([127.0.0.1]) by localhost (wilkesley.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XbGmMsQWi-Rh for ; Tue, 10 Nov 2009 15:05:04 +0000 (GMT) Received: from firewall.banter.local (unknown [217.146.125.41]) by li40-130.members.linode.com (Postfix) with ESMTP id B5D60CF0C for ; Tue, 10 Nov 2009 15:05:03 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by firewall.banter.local (Postfix) with ESMTP id C9150C615 for ; Tue, 10 Nov 2009 15:05:01 +0000 (GMT) Received: from firewall.banter.local ([127.0.0.1]) by localhost (firewall.banter.local [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 24ObffDztu2Z for ; Tue, 10 Nov 2009 15:05:01 +0000 (GMT) Received: from [192.168.0.55] (unknown [192.168.0.55]) by firewall.banter.local (Postfix) with ESMTPSA id 7209CC030 for ; Tue, 10 Nov 2009 15:05:01 +0000 (GMT) In-Reply-To: <874oqkh6cj.fsf@anzu.internal.golden-gryphon.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Manoj Srivastava wrote: > On Wed, Sep 30 2009, Water Lin wrote: > >> I want to mantain a local static html blog system on my local >> computer. I think org is good enough to organise the stuff. >> >> Is there any special function for me to use org as blog system? >> >> I need a reference to start...... > > With the following Ikiwiki plugin, I have been using org as my > Ikiwiki input mechanism (so I write all my blog posts as org-mode > files, and Ikiwiki transforms tehm into html and rss. > > manoj > > --8<---------------cut here---------------start------------->8--- > #!/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 = ; > close OUTPUT; > $ret=~s/(.*

){1}?//s; > $ret=~s/^(.*<\/h1>){1}?//s; > $ret=~s/
.*//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 > --8<---------------cut here---------------end--------------->8--- > Thanks for this great plugin. I had a couple of problems with UTF8 encodings not working. I have patched the plugin to fix this (code below). Warning I am not a Perl programmer, don't blame me if the patch eats your blog:) Ian. #!/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. # 2009-11-10 Patch by Ian Barton to fix some Unicode problems. 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"); binmode (INPUT, ":utf8"); 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; 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"); binmode (OUTPUT, ":utf8"); unless (defined $ret) { debug("failed find html output for $params{page}: $@"); return $params{content}; } local $/ = undef; $ret = ; close OUTPUT; $ret=~s/(.*

){1}?//s; $ret=~s/^(.*<\/h1>){1}?//s; $ret=~s/
.*//s; $ret=~s/(<\/div>\s*$)//s; open(OUTPUT, ">/tmp/contents.html"); binmode (OUTPUT, ":utf8"); print OUTPUT $ret; close OUTPUT; return $ret; } # ------------------------------------------------------------ 1; # modules have to return a true value