Add atom feeds, still needs some cleanup, but seems to mostly work.
This commit is contained in:
parent
d381768c8f
commit
4c1edbce01
3 changed files with 86 additions and 8 deletions
22
bin/werc.rc
22
bin/werc.rc
|
|
@ -184,12 +184,19 @@ fn select_handler {
|
||||||
perm_redirect `{ echo $REQUEST_URI|sed 's/.html$//' }
|
perm_redirect `{ echo $REQUEST_URI|sed 's/.html$//' }
|
||||||
|
|
||||||
# Rss feeds. TODO: we should check that the request is for a real blog dir
|
# Rss feeds. TODO: we should check that the request is for a real blog dir
|
||||||
if not if (~ $REQUEST_URI */index.rss) {
|
if not if (~ $REQUEST_URI */index.rss */index.atom) {
|
||||||
uri = `{echo $uri | sed 's/index.rss$//'}
|
uri = `{echo $uri | sed 's/index.(rss|atom)$//'}
|
||||||
if (~ $#blogDirs 0)
|
if (~ $#blogDirs 0)
|
||||||
blogDirs = $sitedir^$uri
|
blogDirs = $sitedir^'/'$uri
|
||||||
uri=$baseuri$"uri
|
uri=$baseuri$"uri
|
||||||
|
|
||||||
|
if (~ $REQUEST_URI */index.rss) {
|
||||||
master_template=feeds/rss20.tpl
|
master_template=feeds/rss20.tpl
|
||||||
|
}
|
||||||
|
if not if (~ $REQUEST_URI */index.atom) {
|
||||||
|
master_template=feeds/atom.tpl
|
||||||
|
}
|
||||||
|
|
||||||
response_format=raw
|
response_format=raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,10 +205,13 @@ fn select_handler {
|
||||||
if (~ $#blogDirs 0)
|
if (~ $#blogDirs 0)
|
||||||
blogDirs = `{basename -d $body}
|
blogDirs = `{basename -d $body}
|
||||||
|
|
||||||
rssuri=`{basename -d $uri}
|
u=`{cleanname `{basename -d $uri}}
|
||||||
rssuri=$baseuri`{cleanname $"rssuri^/index.rss}
|
rssuri=$baseuri^$"u^/index.rss
|
||||||
|
atomuri=$baseuri^$"u^/index.atom
|
||||||
extraHeaders=$"extraHeaders ^ \
|
extraHeaders=$"extraHeaders ^ \
|
||||||
'<link rel="alternate" type="application/rss+xml" title="RSS" href="'$rssuri'" />
|
'<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
|
set_handler tpl_handler lib/feeds/html.tpl
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +288,7 @@ fpath=$sitedir
|
||||||
for (i in ('' $args)) {
|
for (i in ('' $args)) {
|
||||||
fpath = $fpath/$i
|
fpath = $fpath/$i
|
||||||
# We don't want blog settings to cascade into posts, note that we are inBlog instead
|
# 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
|
inBlog = $blogDirs
|
||||||
blogDirs = ()
|
blogDirs = ()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,73 @@
|
||||||
|
Content-Type: application/atom+xml
|
||||||
|
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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 -->
|
<!-- 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"
|
<feed xmlns="http://www.w3.org/2005/Atom"
|
||||||
xmlns:thr="http://purl.org/syndication/thread/1.0">
|
xmlns:thr="http://purl.org/syndication/thread/1.0">
|
||||||
<link rel="self" href="http://intertwingly.net/blog/index.atom"/>
|
<link rel="self" href="http://intertwingly.net/blog/index.atom"/>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
% if (! ~ $blogTitle '')
|
% if (! ~ $blogTitle '')
|
||||||
% echo '<h1>'$"blogTitle'</h1>'
|
% 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 }) {
|
for (f in `{ sortedBlogPostList $blogDirs }) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue