+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;
+} #}}}
+