2 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 markdown = require("vendor/couchapp/lib/markdown");
7 var textile = require("vendor/textile/textile");
9 var indexPath = path.list('index','recent-posts',{descending:true, limit:10});
10 var feedPath = path.list('index','recent-posts',{descending:true, limit:10, format:"atom"});
11 var commentsFeed = path.list('comments','comments',{descending:true, limit:10, format:"atom"});
13 provides("html", function() {
14 // get the first row and make sure it's a post
15 var post = getRow().value;
16 if (post.type != "post") {
17 throw(["error", "not_found", "not a post"]);
19 if (post.format == "markdown") {
20 var html = markdown.encode(post.body);
21 } else if (post.format == "textile") {
22 var html = textile.encode(post.body);
24 var html = Mustache.escape(post.html);
30 blogName : ddoc.blog.title,
32 commentsFeed : commentsFeed
37 date : post.created_at,
39 comments : List.withRows(function(row) {
41 if (v.type != "comment") {
44 // keep getting comments until we get to the next post...
47 name : v.commenter.nickname || v.commenter.name,
48 url : v.commenter.url,
49 avatar : v.commenter.gravatar_url || 'http://www.gravatar.com/avatar/'+v.commenter.gravatar+'.jpg?s=40&d=identicon',
50 html : markdown.encode(Mustache.escape(v.comment)),
51 created_at : v.created_at
56 return Mustache.to_html(ddoc.templates.post, stash, ddoc.templates.partials, List.send);