Mercurial > blahgd
changeset 316:787b37a66fa1
rss2 feed support
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 14 Mar 2013 23:12:19 -0400 |
parents | fc3aec78b2f6 |
children | f9f6e04375ac |
files | feed.c web/templates/html/error_atom_only.tmpl web/templates/html/error_unsupported_feed_fmt.tmpl web/templates/rss2/feed.tmpl web/templates/rss2/story.tmpl web/templates/rss2/tag.tmpl |
diffstat | 6 files changed, 40 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/feed.c Thu Mar 14 23:06:36 2013 -0400 +++ b/feed.c Thu Mar 14 23:12:19 2013 -0400 @@ -46,7 +46,10 @@ static int __feed(struct req *req) { - req_head(req, "Content-Type", "application/atom+xml; charset=UTF-8"); + if (!strcmp(req->fmt, "atom")) + req_head(req, "Content-Type", "application/atom+xml; charset=UTF-8"); + else if (!strcmp(req->fmt, "rss2")) + req_head(req, "Content-Type", "application/xhtml+xml; charset=UTF-8"); vars_scope_push(&req->vars); @@ -58,14 +61,15 @@ int blahg_feed(struct req *req, char *feed, int p) { - if (strcmp(feed, "atom")) - return R404(req, "{error_atom_only}"); + if (strcmp(feed, "atom") && + strcmp(feed, "rss2")) + return R404(req, "{error_unsupported_feed_fmt}"); if (p != -1) return R404(req, "{error_comment_feed}"); - /* switch to atom */ - req->fmt = "atom"; + /* switch to to the right type */ + req->fmt = feed; return __feed(req); }
--- a/web/templates/html/error_atom_only.tmpl Thu Mar 14 23:06:36 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -{header} -<h2>Sorry, Atom only</h2> -<div class="post" id="error"> - <div class="storycontent"> - When I first decided to write my own blogging system, I made a - decision that the only feed type I'd support (at least for now) - would be the Atom format. Yes, there are a lot of RSS and RSS2 - feeds out there, but it seems to be the case that Atom is just as - supported (and a bit easier to generate). Feel free to contact me - if you cannot live without a non-Atom feed. - </div> -</div> -{sidebar} -{footer}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/templates/html/error_unsupported_feed_fmt.tmpl Thu Mar 14 23:12:19 2013 -0400 @@ -0,0 +1,10 @@ +{header} +<h2>Sorry, Atom & RSS2 only</h2> +<div class="post" id="error"> + <div class="storycontent"> + Sorry, currently I support only Atom and RSS2 feeds. Feel free to + contact me if you cannot live without some other feed format. + </div> +</div> +{sidebar} +{footer}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/templates/rss2/feed.tmpl Thu Mar 14 23:12:19 2013 -0400 @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> +<channel> + <title>Josef "Jeff" Sipek</title> + <link>{baseurl}</link> + <language>en</language> + <description>Josef "Jeff" Sipek</description> + +{posts%story} +</channel> +</rss>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/templates/rss2/story.tmpl Thu Mar 14 23:12:19 2013 -0400 @@ -0,0 +1,9 @@ +<item> + <title>{title}</title> + <guid>{baseurl}/?p={id}</guid> + <link>{baseurl}/?p={id}</link> + <comments>{baseurl/?p={id}#respond</comments> + {tags%tag} + <description><![CDATA[{body}]]></description> + <pubDate>{time|rfc822}</pubDate> +</item>