swerc

anselm's simpler werc fork
git clone git://git.suckless.org/swerc
Log | Files | Refs | README

commit 70f9b9e52b718345b98ad742895f6f21ab3f4f2a
parent bbc643c2cdc09a812c468c812355d95f8cdca4ae
Author: uriel@engel.se.cat-v.org <unknown>
Date:   Wed, 26 Nov 2008 04:56:39 +0100

Add atom feeds, still needs some cleanup, but seems to mostly work.
Diffstat:
Mbin/werc.rc | 24+++++++++++++++++-------
Mlib/feeds/atom.tpl | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlib/feeds/html.tpl | 2+-
3 files changed, 86 insertions(+), 8 deletions(-)

diff --git 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 ^ \ '<link rel="alternate" type="application/rss+xml" title="RSS" href="'$rssuri'" /> + <link rel="alternate" type="application/atom+xml" title="ATOM" href="'$atomuri'"/> + ' 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 @@ -1,5 +1,73 @@ +Content-Type: application/atom+xml + <?xml version="1.0" encoding="utf-8"?> + <!-- XXX TODO: See for more info:http://www.tbray.org/ongoing/When/200x/2005/07/27/Atomic-RSS --> +%{ +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/'} +%} + +<feed xmlns="http://www.w3.org/2005/Atom" + xmlns:thr="http://purl.org/syndication/thread/1.0"> + + <link rel="self" href="%($uri%)"/> + <id>%($uri%)</id> + <icon>/favicon.ico</icon> + + <title>%($siteTitle%)</title> + <subtitle>%($siteSubTitle%)</subtitle> + + <!-- <updated>2008-09-24T12:47:00-04:00</updated> --> + <updated>%($updated%)</updated> + <link href="."/> + +%{ + for(f in `{sortedBlogPostList $blogDirs}) { + statpost $f +%} + <entry> + <!-- <id>tag:intertwingly.net,2004:2899</id> Maybe we should be smarter, see: http://diveintomark.org/archives/2004/05/28/howto-atom-id --> + <id>%($post_uri%)</id> + <link href="%($post_uri%)"/> + <title>%($title%)</title> + <!-- <link rel="replies" href="2899.atom" thr:count="0"/> --> + <author> + <name>%($by%)</name> + <!-- + <email>rubys@intertwingly.net</email> + <uri>/blog/</uri> + --> + </author> + + + <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"> + %($summary%) + </div></content> + + <updated>%($updated%)</updated> + </entry> + + +% } + +</feed> + +% exit + <feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0"> <link rel="self" href="http://intertwingly.net/blog/index.atom"/> diff --git a/lib/feeds/html.tpl b/lib/feeds/html.tpl @@ -1,7 +1,7 @@ % if (! ~ $blogTitle '') % echo '<h1>'$"blogTitle'</h1>' -<div style="text-align:right">(<a href="index.rss">rss feed</a>)</div> +<div style="text-align:right">(<a href="index.rss">RSS Feed</a>|<a href="index.atom">Atom Feed</a>)</div> %{ for (f in `{ sortedBlogPostList $blogDirs }) {