return @ret;
} #}}}
-sub finalize ($$$) { #{{{
+sub rsspage ($) { #{{{
+ my $page=shift;
+
+ return $page.".rss";
+} #}}}
+
+sub genpage ($$$) { #{{{
my $content=shift;
my $page=shift;
my $mtime=shift;
$u=~s/\[\[file\]\]/$pagesources{$page}/g;
$template->param(historyurl => $u);
}
+
+ if ($config{rss}) {
+ $template->param(rssurl => rsspage($page));
+ }
$template->param(
title => $title,
return $template->output;
} #}}}
+sub date_822 ($) { #{{{
+ my $time=shift;
+
+ eval q{use POSIX};
+ return POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
+} #}}}
+
+sub absolute_urls ($$) { #{{{
+ my $content=shift;
+ my $url=shift;
+
+ $url=~s/[^\/]+$//;
+
+ $content=~s{<a\s+href="([^"]+)"}{
+ "<a href=\"$url$1\""
+ }ieg;
+ $content=~s{<img\s+src="([^"]+)"}{
+ "<img src=\"$url$1\""
+ }ieg;
+ return $content;
+} #}}}
+
+sub genrss ($$$) { #{{{
+ my $content=shift;
+ my $page=shift;
+ my $mtime=shift;
+
+ my $url="$config{url}/".htmlpage($page);
+
+ my $template=HTML::Template->new(blind_cache => 1,
+ filename => "$config{templatedir}/rsspage.tmpl");
+
+ # Regular page gets a feed that is updated every time the
+ # page is changed, so the mtime is encoded in the guid.
+ my @items=(
+ {
+ itemtitle => pagetitle(basename($page)),
+ itemguid => "$url?mtime=$mtime",
+ itemurl => $url,
+ itempubdate => date_822($mtime),
+ itemcontent => absolute_urls($content, $url), # rss sucks
+ },
+ );
+
+ $template->param(
+ title => pagetitle(basename($page)),
+ pageurl => $url,
+ items => \@items,
+ );
+
+ return $template->output;
+} #}}}
+
sub check_overwrite ($$) { #{{{
# Important security check. Make sure to call this before saving
# any files to the source directory.
$content=linkify($content, $page);
$content=htmlize($type, $content);
- $content=finalize($content, $page,
- mtime("$config{srcdir}/$file"));
check_overwrite("$config{destdir}/".htmlpage($page), $page);
- writefile("$config{destdir}/".htmlpage($page), $content);
+ writefile("$config{destdir}/".htmlpage($page),
+ genpage($content, $page, mtime("$config{srcdir}/$file")));
$oldpagemtime{$page}=time;
$renderedfiles{$page}=htmlpage($page);
+
+ # TODO: should really add this to renderedfiles and call
+ # check_overwrite, as above, but currently renderedfiles
+ # only supports listing one file per page.
+ if ($config{rss}) {
+ writefile("$config{destdir}/".rsspage($page),
+ genrss($content, $page, mtime("$config{srcdir}/$file")));
+ }
}
else {
$links{$file}=[];
and is quite smart about converting it to html. The only additional markup
provided by ikiwiki aside from regular markdown is the [[WikiLink]].
+* [[RSS]]
+
+ ikiwiki supports generating RSS (2.0) feed for individual pages. These
+ feeds can be subscribed to, to get an update when a page is changed.
+
+ (Support for proper blogs is also planned.)
+
* support for other file types
ikiwiki also supports files of any other type, including raw html, text,
historyurl => '',
diffurl => '',
anonok => 0,
+ rss => 0,
rebuild => 0,
wrapper => undef,
wrappermode => undef,
"wrappermode=i" => \$config{wrappermode},
"svn!" => \$config{svn},
"anonok!" => \$config{anonok},
+ "rss!" => \$config{rss},
"cgi!" => \$config{cgi},
"url=s" => \$config{url},
"cgiurl=s" => \$config{cgiurl},
sub checkconfig () { #{{{
if ($config{cgi} && ! length $config{url}) {
- error("Must specify url to wiki with --url when using --cgi");
+ error("Must specify url to wiki with --url when using --cgi\n");
+ }
+ if ($config{rss} && ! length $config{url}) {
+ error("Must specify url to wiki with --url when using --rss\n");
}
$config{wikistatedir}="$config{srcdir}/.ikiwiki"
--- /dev/null
+<?xml version="1.0"?>
+<rss version="2.0">
+ <channel>
+ <title><TMPL_VAR TITLE ESCAPE=HTML></title>
+ <link><TMPL_VAR PAGEURL></link>
+ <description><TMPL_VAR TITLE ESCAPE=HTML></description>
+ <TMPL_LOOP NAME="ITEMS">
+ <item>
+ <title><TMPL_VAR ITEMTITLE ESCAPE=HTML></title>
+ <TMPL_IF NAME="ITEMGUID">
+ <guid isPermaLink="false"><TMPL_VAR ITEMGUID></guid>
+ <TMPL_ELSE>
+ <guid><TMPL_VAR ITEMURL></guid>
+ </TMPL_IF>
+ <link><TMPL_VAR ITEMURL></link>
+ <pubDate><TMPL_VAR ITEMPUBDATE></pubDate>
+ <description><![CDATA[<TMPL_VAR ITEMCONTENT>]]></description>
+ </item>
+ </TMPL_LOOP>
+ </channel>
+</rss>