diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-03-23 21:00:51 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2006-03-23 21:00:51 +0000 |
commit | ca366fc9025197a5d32034a446dc35b776101d78 (patch) | |
tree | 95e6600b4cc701d7a7f4fad76d695f6853efac76 /IkiWiki/Render.pm | |
parent | 07e68136bbc3d71c7c50b9526e13add37d8c7aee (diff) | |
download | ikiwiki-ca366fc9025197a5d32034a446dc35b776101d78.tar ikiwiki-ca366fc9025197a5d32034a446dc35b776101d78.tar.gz |
add support for generating per-page rss feeds
Diffstat (limited to 'IkiWiki/Render.pm')
-rw-r--r-- | IkiWiki/Render.pm | 78 |
1 files changed, 74 insertions, 4 deletions
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index df24fd568..646e254a5 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -79,7 +79,13 @@ sub parentlinks ($) { #{{{ return @ret; } #}}} -sub finalize ($$$) { #{{{ +sub rsspage ($) { #{{{ + my $page=shift; + + return $page.".rss"; +} #}}} + +sub genpage ($$$) { #{{{ my $content=shift; my $page=shift; my $mtime=shift; @@ -102,6 +108,10 @@ sub finalize ($$$) { #{{{ $u=~s/\[\[file\]\]/$pagesources{$page}/g; $template->param(historyurl => $u); } + + if ($config{rss}) { + $template->param(rssurl => rsspage($page)); + } $template->param( title => $title, @@ -116,6 +126,59 @@ sub finalize ($$$) { #{{{ 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. @@ -161,13 +224,20 @@ sub render ($) { #{{{ $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}=[]; |