From 4c1edbce0195de20733336c9e4e7cfe3382d3531 Mon Sep 17 00:00:00 2001 From: Uriel Date: Wed, 26 Nov 2008 04:56:39 +0100 Subject: [PATCH] Add atom feeds, still needs some cleanup, but seems to mostly work. --- bin/werc.rc | 24 +++++++++++----- lib/feeds/atom.tpl | 68 ++++++++++++++++++++++++++++++++++++++++++++++ lib/feeds/html.tpl | 2 +- 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/bin/werc.rc b/bin/werc.rc index f0ca702..8c2a04a 100755 --- a/bin/werc.rc +++ b/bin/werc.rc @@ -184,12 +184,19 @@ fn select_handler { perm_redirect `{ echo $REQUEST_URI|sed 's/.html$//' } # Rss feeds. TODO: we should check that the request is for a real blog dir - if not if (~ $REQUEST_URI */index.rss) { - uri = `{echo $uri | sed 's/index.rss$//'} + if not if (~ $REQUEST_URI */index.rss */index.atom) { + uri = `{echo $uri | sed 's/index.(rss|atom)$//'} if (~ $#blogDirs 0) - blogDirs = $sitedir^$uri + blogDirs = $sitedir^'/'$uri uri=$baseuri$"uri - master_template=feeds/rss20.tpl + + if (~ $REQUEST_URI */index.rss) { + master_template=feeds/rss20.tpl + } + if not if (~ $REQUEST_URI */index.atom) { + master_template=feeds/atom.tpl + } + response_format=raw } @@ -198,10 +205,13 @@ fn select_handler { if (~ $#blogDirs 0) blogDirs = `{basename -d $body} - rssuri=`{basename -d $uri} - rssuri=$baseuri`{cleanname $"rssuri^/index.rss} + u=`{cleanname `{basename -d $uri}} + rssuri=$baseuri^$"u^/index.rss + atomuri=$baseuri^$"u^/index.atom extraHeaders=$"extraHeaders ^ \ ' + + ' set_handler tpl_handler lib/feeds/html.tpl } @@ -278,7 +288,7 @@ fpath=$sitedir for (i in ('' $args)) { fpath = $fpath/$i # We don't want blog settings to cascade into posts, note that we are inBlog instead - if (! ~ $#blogDirs 0 && ! ~ $req_path */index.rss */[bB]log */[bB]log/) { + if (! ~ $#blogDirs 0 && ! ~ $req_path */index.rss */index.atom */[bB]log */[bB]log/) { inBlog = $blogDirs blogDirs = () } diff --git a/lib/feeds/atom.tpl b/lib/feeds/atom.tpl index 0f36d6e..df6cea7 100644 --- a/lib/feeds/atom.tpl +++ b/lib/feeds/atom.tpl @@ -1,5 +1,73 @@ +Content-Type: application/atom+xml + + +%{ +fn statpost { + f = $1 + + updated = `{/bin/date --rfc-3339'=seconds' -r $f |sed 's/ /T/'} + post_uri = `{echo $f | sed 's,^'$sitedir',,'} + title=`{basename $f | sed 's/^[0-9\-]*_(.*)\.md$/\1/; s/_/ /g' } + date=`{/bin/date -Rd `{basename $f |sed 's/(^[0-9\-]*).*/\1/; s/-[0-9]$//'}} + # TODO: use mtime(1) and ls(1) instead of lunix's stat(1) + stat=`{stat -c '%Y %U' $f} + #mdate=`{/bin/date -Rd $stat(1)} # Not used because it is unreliable + post_uri=$baseuri^`{cleanname `{echo -n $uri | sed 's/\.(md|tpl)//g'}} + by=$stat(2) + ifs=() { summary=`{cat $f | crop_text 1024 | $formatter } } +} +updated = `{/bin/date --rfc-3339'=seconds' |sed 's/ /T/'} +%} + + + + + %($uri%) + /favicon.ico + + %($siteTitle%) + %($siteSubTitle%) + + + %($updated%) + + +%{ + for(f in `{sortedBlogPostList $blogDirs}) { + statpost $f +%} + + + %($post_uri%) + + %($title%) + + + %($by%) + + + + +
+ %($summary%) +
+ + %($updated%) +
+ + +% } + +
+ +% exit + diff --git a/lib/feeds/html.tpl b/lib/feeds/html.tpl index 384de10..85bb858 100644 --- a/lib/feeds/html.tpl +++ b/lib/feeds/html.tpl @@ -1,7 +1,7 @@ % if (! ~ $blogTitle '') % echo '

'$"blogTitle'

' -
(rss feed)
+
(RSS Feed|Atom Feed)
%{ for (f in `{ sortedBlogPostList $blogDirs }) {