Commits

benoitc  committed 1b2aa9a

update lists to new api

  • Participants
  • Parent commits 451f22e
  • Branches couchdb010

Comments (0)

Files changed (2)

File lists/index.js

-function(head, row, req, row_info) {
+function(head, req) {
   // !json lib.templates.index
   // !json blog
   // !code lib/helpers/ejs/*.js
   registerType("sitemap", "application/x-xml");
   
   provides("html", function() {
-        if (head) {
-            return template(lib.templates.index.head, {
-                assets: assetPath(),
-                archivesPath: archivesPath,
-                feedPath: feedPath
-            });
-        } else if (row) {
-            if (!req.query.limit && row_info.row_number == 7)
-                return {stop: true};
-                
-            var fcreated_at = new Date().setRFC3339(row.value.created_at).toLocaleString();
-            return template(lib.templates.index.row, {
+    // display head
+    send(template(lib.templates.index.head, {
+          assets: assetPath(),
+          archivesPath: archivesPath,
+          feedPath: feedPath
+    }));
+    
+    // display lines
+    var row, key, first_key,
+  	i = 0;
+    while (row =getRow()) {
+      // limit number of displayed lines to 8
+      if (!req.query.limit && i > 7)
+        break;
+      
+      var fcreated_at = new Date().setRFC3339(row.value.created_at).toLocaleString();
+      send(template(lib.templates.index.row, {
                     post: row.value,
                     fcreated_at: fcreated_at,
                     link: showPath('post', row.id),
                     assets: assetPath(),
                     feedPath: feedPath
+      }));
+      if (i == 0)
+        first_key = row.key;
+      i = i + 1;
+      key = row.key;
+    }
+            
+    var nextPath = listPath('index','recent-posts', {
+      startkey: (ky || "#"), 
+      descending:true, 
+      limit:25 });
+
+    return template(lib.templates.index.tail, {
+              nextPath: nextPath,
+              assets: assetPath()
             });
-        } else {
-            var nextPath = listPath('index','recent-posts', {
-                    startkey: ((row_info &&row_info.prev_key) || "#"), 
-                    descending:true, 
-                    limit:25 });
+  });
 
-            return template(lib.templates.index.tail, {
-                nextPath: nextPath,
-                assets: assetPath()
-            });
-        }
-    });
+  provides("atom", function() {
+    // with first row in head you can do updated.
+    var f = <feed xmlns="http://www.w3.org/2005/Atom"/>;
+    f.title = blog.title;
+    f.id = makeAbsolute(req, indexPath);
+    f.link.@href = makeAbsolute(req, feedPath);
+    f.link.@rel = "self";
+    f.generator = 'benoitc.org';
+    f.updated = new Date().rfc3339();
+    send('<?xml version="1.0" encoding="UTF-8"?>\n'+
+      f.toXMLString().replace(/\<\/feed\>/,''));
+    
+    while (row=getRow()) {
+      var entry = <entry/>;
+      entry.id = makeAbsolute(req, '/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id));
+      entry.title = row.value.title;
+      entry.content = row.value.summary;
+      entry.content.@type = 'html';
+      entry.updated = row.value.created_at;
+      entry.author = <author><name>{row.value.author}</name></author>;
+      entry.link.@href = makeAbsolute(req, showPath('post', row.id));
+      entry.link.@rel = "alternate";
+      send(entry);
+    }
+    return "</feed>";
+  });
 
-    provides("atom", function() {
-      // with first row in head you can do updated.
-      if (head) {
-        var f = <feed xmlns="http://www.w3.org/2005/Atom"/>;
-        f.title = blog.title;
-        f.id = makeAbsolute(req, indexPath);
-        f.link.@href = makeAbsolute(req, feedPath);
-        f.link.@rel = "self";
-        f.generator = 'benoitc.org';
-        f.updated = new Date().rfc3339();
-        return {body:'<?xml version="1.0" encoding="UTF-8"?>\n'+
-                f.toXMLString().replace(/\<\/feed\>/,'')};
-      } else if (row) {
-        var entry = <entry/>;
-        entry.id = makeAbsolute(req, '/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id));
-        entry.title = row.value.title;
-        entry.content = row.value.summary;
-        entry.content.@type = 'html';
-        entry.updated = row.value.created_at;
-        entry.author = <author><name>{row.value.author}</name></author>;
-        entry.link.@href = makeAbsolute(req, showPath('post', row.id));
-        entry.link.@rel = "alternate";
-        return {body:entry};
-      } else {
-        return {body: "</feed>"};
-      }
-    });
+  provides("sitemap", function() {
+    //sitemap
+    send('<?xml version="1.0" encoding="UTF-8"?>\n'+
+      '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"/>');
+    while (row=getRow()) {
+      var url = <url/>;
+      url.loc = makeAbsolute(req, showPath('post', row.id));
+      url.lastmod = row.value.created_at;
+      url.changefreq = "daily";
+      url.priority = "0.5";
+      send (url);
+    }
+    return "</urlset>";
 
-    provides("sitemap", function() {
-      //sitemap
-       if (head) {
-        return {body:'<?xml version="1.0" encoding="UTF-8"?>\n'+
-            '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"/>'};
-      } else if (row) {
-        var url = <url/>;
-        url.loc = makeAbsolute(req, showPath('post', row.id));
-        url.lastmod = row.value.created_at;
-        url.changefreq = "daily";
-        url.priority = "0.5";
-        return {body:url};
-      } else {
-        return {body: "</urlset>"};
-      }
-
-    });
+  });
 
 };

File lists/search.js

-function(head, row, req, row_info) {
+function(head, req) {
   // !json lib.templates.search
   // !json blog
   // !code lib/helpers/ejs/*
   var feedPath = listPath('search','topics',{descending:true, limit:8, format:"atom"});
   var archivesPath = listPath('index','recent-posts',{descending:true, limit:25});
   provides("html", function() {
-        if (head) {
-            return template(lib.templates.search.head, {
-                assets: assetPath(),
-                archivesPath: archivesPath,
-                feedPath: feedPath
-
-            });
-        } else if (row) {
-
-            var fcreated_at = new Date().setRFC3339(row.value.created_at).toLocaleString();
-            return template(lib.templates.search.row, {
-                    post: row.value,
-                    fcreated_at: fcreated_at,
-                    link: showPath('post', row.id),
-                    assets: assetPath()
-            });
-        } else {
-            return template(lib.templates.search.tail, {
-                archivesPath: archivesPath,
+	  // send head
+  	send(template(lib.templates.search.head, {
+  		assets: assetPath(),
+  		archivesPath: archivesPath,
+  		feedPath: feedPath
+  	}));
+      
+      // send rows
+  	var row, key, first_key,
+  	i = 0;
+  	while (row = getRow()) {
+        var fcreated_at = new Date().setRFC3339(row.value.created_at).toLocaleString();
+        send(template(lib.templates.search.row, {
+                post: row.value,
+                fcreated_at: fcreated_at,
+                link: showPath('post', row.id),
                 assets: assetPath()
-            });
-        }
+        }));
+  	}
+    
+      // send footer
+    return template(lib.templates.search.tail, {
+  		archivesPath: archivesPath,
+  		assets: assetPath()
+  	});
   });
+  
   provides("atom", function() {
       // with first row in head you can do updated.
-      if (head) {
-        var f = <feed xmlns="http://www.w3.org/2005/Atom"/>;
-        f.title = blog.title;
-        f.id = makeAbsolute(req, indexPath);
-        f.link.@href = makeAbsolute(req, feedPath);
-        f.link.@rel = "self";
-        f.generator = 'benoitc.org';
-        f.updated = new Date().rfc3339();
-        return {body:'<?xml version="1.0" encoding="UTF-8"?>\n'+
-                f.toXMLString().replace(/\<\/feed\>/,'')};
-      } else if (row) {
+      var f = <feed xmlns="http://www.w3.org/2005/Atom"/>;
+	  f.title = blog.title; 
+	  f.id = makeAbsolute(req, indexPath);
+	  f.link.@href = makeAbsolute(req, feedPath);
+    f.link.@rel = "self";
+    f.generator = 'benoitc.org';
+    f.updated = new Date().rfc3339();
+    send('<?xml version="1.0" encoding="UTF-8"?>\n'+
+                f.toXMLString().replace(/\<\/feed\>/,''));
+                
+    while (row = getRow()) {
         var entry = <entry/>;
         entry.id = makeAbsolute(req, '/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id));
         entry.title = row.value.title;
         entry.author = <author><name>{row.value.author}</name></author>;
         entry.link.@href = makeAbsolute(req, showPath('post', row.id));
         entry.link.@rel = "alternate";
-        return {body:entry};
-      } else {
-        return {body: "</feed>"};
-      }
+        send(entry);
+    }
+    
+    return "</feed>";
   });
 };