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('rpms','rpm-to-host', {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);
81 // if the client requests an atom feed and not html,
82 // we run this function to generate the feed.
83 provides("atom", function() {
84 var path = require("vendor/couchapp/lib/path").init(req);
85 var markdown = require("vendor/couchapp/lib/markdown");
86 var textile = require("vendor/textile/textile");
88 // we load the first row to find the most recent change date
91 // generate the feed header
92 var feedHeader = Atom.header({
93 updated : (row ? new Date(row.value.created_at) : new Date()),
94 title : ddoc.blog.title,
95 feed_id : path.absolute(indexPath),
96 feed_link : path.absolute(feedPath),
99 // send the header to the client
102 // loop over all rows
105 if (row.value.format == "markdown") {
106 var html = markdown.encode(row.value.body);
107 } else if (row.value.format == "textile") {
108 var html = textile.encode(row.value.body);
110 var html = Mustache.escape(row.value.html);
112 // generate the entry for this row
113 var feedEntry = Atom.entry({
114 entry_id : path.absolute('/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id)),
115 title : row.value.title,
117 updated : new Date(row.value.created_at),
118 author : row.value.author,
119 alternate : path.absolute(path.show('post', row.id))
121 // send the entry to client
123 } while (row = getRow());
126 // close the loop after all rows are rendered