X-Git-Url: http://git.onelab.eu/?p=myops.git;a=blobdiff_plain;f=web%2Fquery%2Flists%2Fcomments.js;fp=web%2Fquery%2Flists%2Fcomments.js;h=dffcd4f523b5ca7c80088c5f2f3ad91225b38b3b;hp=0000000000000000000000000000000000000000;hb=85070b3d456667f238051af1a2f1f2a0c12300ab;hpb=607f0e13927eb18075c375fa9ba5527da4fcbb44 diff --git a/web/query/lists/comments.js b/web/query/lists/comments.js new file mode 100644 index 0000000..dffcd4f --- /dev/null +++ b/web/query/lists/comments.js @@ -0,0 +1,55 @@ +function(head, req) { + var ddoc = this; + var Mustache = require("lib/mustache"); + var List = require("vendor/couchapp/lib/list"); + var path = require("vendor/couchapp/lib/path").init(req); + var Atom = require("vendor/couchapp/lib/atom"); + + var indexPath = path.list('index','recent-posts',{descending:true, limit:10}); + var feedPath = path.list('index','recent-posts',{descending:true, limit:10, format:"atom"}); + var commentsFeed = path.list('comments','comments',{descending:true, limit:10, format:"atom"}); + + // if the client requests an atom feed and not html, + // we run this function to generate the feed. + provides("atom", function() { + var path = require("vendor/couchapp/lib/path").init(req); + var markdown = require("vendor/couchapp/lib/markdown"); + var textile = require("vendor/textile/textile"); + + // we load the first row to find the most recent change date + var row = getRow(); + + // generate the feed header + var feedHeader = Atom.header({ + updated : (row ? new Date(row.value.created_at) : new Date()), + title : ddoc.blog.title + " comments", + feed_id : path.absolute(indexPath), + feed_link : path.absolute(commentsFeed) + }); + + // send the header to the client + send(feedHeader); + + // loop over all rows + if (row) { + do { + var v = row.value; + + // generate the entry for this row + var feedEntry = Atom.entry({ + entry_id : path.absolute('/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id)), + title : "comment on "+v.post_id, + content : markdown.encode(Mustache.escape(v.comment)), + updated : new Date(v.created_at), + author : v.commenter.nickname || v.commenter.name, + alternate : path.absolute(path.list('post','post-page', {startkey:[v.post_id]})) + }); + // send the entry to client + send(feedEntry); + } while (row = getRow()); + } + + // close the loop after all rows are rendered + return ""; + }); +} \ No newline at end of file