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");
9 if ( 'within' in req.query ) {
10 within = Number(req.query['within']);
11 log("within: " + within);
13 within = 60 * 60 * 24; // within the last day.
15 var ts = (new Date()).getTime()/1000 - within; // convert milliseconds to seconds
17 var indexPath = path.list('rpms','rpm-to-host',{descending:true, limit:10});
18 var feedPath = path.list('rpms','rpm-to-host',{descending:true, limit:10, format:"atom"});
19 var commentsFeed = path.list('comments','comments',{descending:true, limit:10, format:"atom"});
21 function check_field(query, field, def) {
23 if ( field in query ) {
25 log(field + ": " + ret);
30 var path_parts = req.path;
32 // The first matching format is sent, so reordering functions changes
33 // thier priority. In this case HTML is the preferred format, so it comes first.
34 provides("text", function() {
35 var row, first_row = true;
36 var more_props = true;
38 var hostname = check_field(req.query, 'hostname', false);
39 var rpm = check_field(req.query, 'rpm', false);
40 var show_hosts = check_field(req.query, 'show_hosts', false);
41 var show_rpms = check_field(req.query, 'show_rpms', false);
42 while (row = getRow()) {
43 if ( row.key[0] < ts ) { continue; }
48 provides("html", function() {
50 // render the html head using a template
54 title : 'blah blah blah',
56 blogName : ddoc.blog.title,
58 commentsFeed : commentsFeed
64 newPostPath : path.show("edit"),
65 assets : path.asset(),
66 rpmversion : check_field(req.query, 'rpmversion', 'List all'),
68 nodes : List.withRows(function(row) {
74 link : path.list('rpmlist',{rpmversion : key[1], group : true, startkey : [key[1]], endkey : [key[1],{}]}),
78 return Mustache.to_html(ddoc.templates.rpms, stash, ddoc.templates.partials, List.send);
80 // link : path.list('rpms','rpm-to-host', {rpmversion : key[1], group : true, startkey : [key[1]], endkey : [key[1],{}]}),
82 // if the client requests an atom feed and not html,
83 // we run this function to generate the feed.
84 provides("atom", function() {
85 var path = require("vendor/couchapp/lib/path").init(req);
86 var markdown = require("vendor/couchapp/lib/markdown");
87 var textile = require("vendor/textile/textile");
89 // we load the first row to find the most recent change date
92 // generate the feed header
93 var feedHeader = Atom.header({
94 updated : (row ? new Date(row.value.created_at) : new Date()),
95 title : ddoc.blog.title,
96 feed_id : path.absolute(indexPath),
97 feed_link : path.absolute(feedPath),
100 // send the header to the client
103 // loop over all rows
106 if (row.value.format == "markdown") {
107 var html = markdown.encode(row.value.body);
108 } else if (row.value.format == "textile") {
109 var html = textile.encode(row.value.body);
111 var html = Mustache.escape(row.value.html);
113 // generate the entry for this row
114 var feedEntry = Atom.entry({
115 entry_id : path.absolute('/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id)),
116 title : row.value.title,
118 updated : new Date(row.value.created_at),
119 author : row.value.author,
120 alternate : path.absolute(path.show('post', row.id))
122 // send the entry to client
124 } while (row = getRow());
127 // close the loop after all rows are rendered