3 var Mustache = require("lib/mustache");
4 var List = require("vendor/couchapp/lib/list");
5 var path = require("vendor/couchapp/lib/path").init(req);
6 var Atom = require("vendor/couchapp/lib/atom");
8 var indexPath = path.list('index','recent-posts',{descending:true, limit:10});
9 var feedPath = path.list('index','recent-posts',{descending:true, limit:10, format:"atom"});
10 var commentsFeed = path.list('comments','comments',{descending:true, limit:10, format:"atom"});
12 // if the client requests an atom feed and not html,
13 // we run this function to generate the feed.
14 provides("atom", function() {
15 var path = require("vendor/couchapp/lib/path").init(req);
16 var markdown = require("vendor/couchapp/lib/markdown");
17 var textile = require("vendor/textile/textile");
19 // we load the first row to find the most recent change date
22 // generate the feed header
23 var feedHeader = Atom.header({
24 updated : (row ? new Date(row.value.created_at) : new Date()),
25 title : ddoc.blog.title + " comments",
26 feed_id : path.absolute(indexPath),
27 feed_link : path.absolute(commentsFeed)
30 // send the header to the client
38 // generate the entry for this row
39 var feedEntry = Atom.entry({
40 entry_id : path.absolute('/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id)),
41 title : "comment on "+v.post_id,
42 content : markdown.encode(Mustache.escape(v.comment)),
43 updated : new Date(v.created_at),
44 author : v.commenter.nickname || v.commenter.name,
45 alternate : path.absolute(path.list('post','post-page', {startkey:[v.post_id]}))
47 // send the entry to client
49 } while (row = getRow());
52 // close the loop after all rows are rendered