Commits

Anonymous committed e0a3610

full rewriting!. Also edit some files

  • Participants
  • Parent commits 70fdf9c

Comments (0)

Files changed (21)

Binary file added.

_attachments/.benoitc.html.swp

Binary file added.

_attachments/img/blog.png

Added
New image

_attachments/js/jquery.couchapp.js

   };
 
   var login;
-  
+
   function init(app) {
+
     $(function() {
-      var dbname = document.location.href.split('/')[3];
-      var dname = unescape(document.location.href).split('/')[5];
+      if ($.blog && $.blog.dbname) {
+        var dbname = $.blog.dbname;
+      } else {
+        var dbname = document.location.href.split('/')[3];
+      }
+
+      if ($.blog && $.blog.dname) {
+        var dname = $.blog.dname;
+      } else {
+        var dname = unescape(document.location.href).split('/')[5];
+      }
+
       var db = $.couch.db(dbname);
       var design = new Design(db, dname);
       
         return instance;
       }
       
-      function prettyDate(time){
-      	var date = new Date(time),
-      		diff = (((new Date()).getTime() - date.getTime()) / 1000),
-      		day_diff = Math.floor(diff / 86400);
-
-        // if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 ) return;
-
-      	return day_diff < 1 && (
-      			diff < 60 && "just now" ||
-      			diff < 120 && "1 minute ago" ||
-      			diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
-      			diff < 7200 && "1 hour ago" ||
-      			diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
-      		day_diff == 1 && "yesterday" ||
-      		day_diff < 21 && day_diff + " days ago" ||
-      		day_diff < 45 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
-      		day_diff < 730 && Math.ceil( day_diff / 31 ) + " months ago" ||
-      		Math.ceil( day_diff / 365 ) + " years ago";
-      };
-      
+            
       app({
         showPath : function(form, docid) {
           return '/'+[dbname, '_show', dname, form, docid].join('/')
         },
         db : db,
         design : design,
-        docForm : docForm,
-        prettyDate : prettyDate
+        docForm : docForm
       });
     });
   };
 {
-   "title": "Carnet d'un artisan web."
+   "title": "Carnet d'un artisan web.",
+   "env": {
+        "benoitc.local": {
+            "static_url": "static",
+            "show_url": "show",
+            "list_url": "list",
+            "dbname": "benoitc-dev",
+            "dname": "benoitc"
+        }
+    }
 }

lib/helpers/couchapp.js

   }
 };
 
+// from prototype
+Object.extend = function(destination, source) {
+  for (var property in source)
+    destination[property] = source[property];
+  return destination;
+};
+
+function getEnv() {
+    default_env = {
+        'dbname': req.path[0],
+        'dname': req.path[2]
+    };
+
+    new_env = {};
+    if (typeof blog != "undefined" && blog.env) {
+         for(var host in blog.env) {
+             if (host == req.headers.Host) {
+                 new_env = blog.env[host];
+                 break;
+             }
+         }
+    }
+    Object.extend(default_env, new_env);
+    return default_env;
+};
+
 function assetPath() {
-  var parts = ['',req.path[0], '_design', req.path[2]];
+  if (typeof blog != "undefined" && blog.env) {
+    for(var host in blog.env) {
+        if (host == req.headers.Host && blog.env[host].static_url) {
+            parts = ['', blog.env[host].static_url];
+            return makePath(concatArgs(parts, arguments));
+        }
+    }
+  }
+  parts = ['',req.path[0], '_design', req.path[2]];
   return makePath(concatArgs(parts, arguments));
 };
 
 function showPath() {
+  if (typeof blog != "undefined" && blog.env) {
+    for(var host in blog.env) {
+        if (host == req.headers.Host && blog.env[host].show_url) {
+            parts = ['', blog.env[host].show_url];
+            return makePath(concatArgs(parts, arguments));
+        }
+    }
+  }
+
   var parts = ['',req.path[0], '_show', req.path[2]];
   return makePath(concatArgs(parts, arguments));
 };
 
 function listPath() {
+  if (typeof blog != "undefined" && blog.env) {
+    for(var host in blog.env) {
+        if (host == req.headers.Host && blog.env[host].list_url) {
+            parts = ['', blog.env[host].list_url];
+            return makePath(concatArgs(parts, arguments));
+        }
+    }
+  }
+
   var parts = ['',req.path[0], '_list', req.path[2]];
   return makePath(concatArgs(parts, arguments));
 };

lib/templates/edit.html

 <html lang="fr">
 <head>
     <meta charset="utf-8"/>
-    <title>benoît chesneau web, artisan web.</title>
+    <title>benoît chesneau web - edit</title>
 
     <!--[if IE]>
 
     <link rel="openid.server" href="http://www.myopenid.com/server">
     <link rel="openid.delegate" href="http://bchesneau.myopenid.com/">
     <link rel="home index" href="http://benoitc.org/" type="text/html">
-    <link rel="me author" href="http://benoitc.org/benoitc.html" type="text/html">
+    <link rel="me author" href="http://benoitc.org/static/benoitc.html" type="text/html">
 
     <link rel="stylesheet" href="<%= assets %>/css/benoitc.css" type="text/css" media="screen, projection" />
     
         </div>
 
         <footer id="main-footer">
-        <p>2009 (c) <a href="<%= assets %>/apropos.html">Benoît Chesneau</a> - <a rel="license" href="http://creativecommons.org/licenses/by/2.0/fr/">Certains droits reservés</a>.</p>
+        <p>2009 (c) <a href="<%= assets %>/<%= assets %>/benoitc.html">Benoît Chesneau</a> - <a rel="license" href="http://creativecommons.org/licenses/by/2.0/fr/">Certains droits reservés</a>.</p>
         </footer> 
 
     
     <script src="/_utils/script/jquery.js"></script>
     <script src="/_utils/script/jquery.cookies.js"></script>
     <script src="/_utils/script/jquery.couch.js"></script>
+
+    <script>
+        // ugly hack for rewriting
+        $.extend({
+            blog: {
+                dbname: "<%= env.dbname %>",
+                dname: "<%= env.dname %>"
+            }
+        });    
+    </script>
+
     <script src="<%= assets %>/js/showdown.js"></script>
 
     <script src="<%= assets %>/js/textarea.jquery.js"></script>

lib/templates/index/head.html

     <link rel="openid.server" href="http://www.myopenid.com/server">
     <link rel="openid.delegate" href="http://bchesneau.myopenid.com/">
     <link rel="home index" href="http://benoitc.org/" type="text/html">
-    <link rel="me author" href="http://benoitc.org/benoitc.html" type="text/html">
+    <link rel="me author" href="http://benoitc.org/static/benoitc.html" type="text/html">
     <link type='application/atom+xml' href='<%= feedPath %>' rel='alternate' title='Writings'>
 
     <link rel="stylesheet" href="<%= assets %>/css/benoitc.css" type="text/css" media="screen, projection" />
         <header class="page">
             <nav id="mainav">
                 <ul>
+                    <li><a href="/">accueil</a></li>
                     <li><a href="<%= archivesPath %>">archives</a></li>
                     <li><a href="<%= feedPath %>" type='application/atom+xml' class="atom">suivre</a></li>
                 </ul>

lib/templates/index/row.html

     </h3>
     <p><%= post.summary %></p>
 </article>
-<p><%= test %></p>

lib/templates/index/tail.html

     <script src="/_utils/script/json2.js"></script>
     <script src="/_utils/script/jquery.js"></script>
     <script src="/_utils/script/jquery.couch.js"></script>
+    <script>
+        // ugly hack for rewriting
+        $.extend({
+            blog: {
+                dbname: "<%= env.dbname %>",
+                dname: "<%= env.dname %>"
+            }
+        });
+    </script>
     <script src="<%= assets %>/js/jquery.couchapp.js"></script>
     <script src="<%= assets %>/js/strftime.js"></script>
     <script src="<%= assets %>/js/blog.js"></script>

lib/templates/post.html

 <html lang="fr">
 <head>
     <meta charset="utf-8"/>
-    <title>benoît chesneau web, artisan web.</title>
+    <title>benoît chesneau web - <%= doc.title %></title>
 
     <!--[if IE]>
 
     <![endif]-->
     <link rel="openid.server" href="http://www.myopenid.com/server">
     <link rel="openid.delegate" href="http://bchesneau.myopenid.com/">
-    <link rel="home index" href="http://benoitc.org/" type="text/html">
-    <link rel="me author" href="http://benoitc.org/benoitc.html" type="text/html">
+    <link rel="home index" href="http://benoitc.org" type="text/html">
+    <link rel="me author" href="http://benoitc.org/static/benoitc.html" type="text/html">
 
     <link rel="stylesheet" href="<%= assets %>/css/benoitc.css" type="text/css" media="screen, projection" />
 
         </section>
 
         <footer id="main-footer">
-            <p>2009 (c) <a href="<%= assets %>/apropos.html">Benoît Chesneau</a> - <a rel="license" href="http://creativecommons.org/licenses/by/2.0/fr/">Certains droits reservés</a>.</p>
+            <p>2009 (c) <a href="<%= assets %>/benoitc.html">Benoît Chesneau</a> - <a rel="license" href="http://creativecommons.org/licenses/by/2.0/fr/">Certains droits reservés</a>.</p>
         </footer> 
     </div>
 </body>
     <script src="/_utils/script/json2.js"></script>
     <script src="/_utils/script/jquery.js"></script>
     <script src="/_utils/script/jquery.couch.js"></script>
+
+    <script>
+        // ugly hack for rewriting
+        $.extend({
+            blog: {
+                dbname: "<%= env.dbname %>",
+                dname: "<%= env.dname %>"
+            }
+        });
+    </script>
+    
     <script src="<%= assets %>/js/jquery.couchapp.js"></script>
     <script src="<%= assets %>/js/strftime.js"></script>
     <script src="<%= assets %>/js/showdown.js"></script>
-    <script src="<%= assets %>/js/blog.js"></script>
+    <script src="<%= assets %>/js/blog.js"></script> 
     <script>
         $(document).ready(function() {
             localizeDates();
+
             $.CouchApp(function(app) {
                 var docid = document.location.pathname.split('/').pop();
                 var B = new Blog(app);
                     });
                 };
               
-                  displayComments();
-                  localizeDates();
+              displayComments();
+              localizeDates();
 
-                  var commentForm = app.docForm("form#new-comment", {
-                    fields : [
-                      "commenter-name", 
-                      "commenter-email", 
-                      "commenter-url", 
-                      "comment"
-                    ],
-                    template : {
-                      doc_type : "comment",
-                      post_id : docid,
-                      format : "markdown"
-                    },
-                    beforeSave : function(doc) {
-                        if (doc.comment)
-                            doc.html = B.formatBody(doc.comment);
-                      doc.created_at = new Date().rfc3339();
-                    },
-                    success : function(resp, doc) {
-                        $("#new-comment").html("<h3>votre commentaire vient d'être ajouté.</h3>");
-                      $("#comments ol").append(B.commentListing(doc));
-                      $("#comments ol li:last").hide().fadeIn(2000);
-                    }
-                  });
-                  
-                  $("#preview").click(function() {
-                    var doc = commentForm.localDoc();
-                    if (typeof doc.comment != "undefined" && doc.comment) {
-                        var html = B.formatBody(doc.comment);
-                        $('#comment-preview').html(html);
-                    }
-                  });
-                });
+              var commentForm = app.docForm("form#new-comment", {
+                fields : [
+                  "commenter-name", 
+                  "commenter-email", 
+                  "commenter-url", 
+                  "comment"
+                ],
+                template : {
+                  doc_type : "comment",
+                  post_id : docid,
+                  format : "markdown"
+                },
+                beforeSave : function(doc) {
+                    if (doc.comment)
+                        doc.html = B.formatBody(doc.comment);
+                  doc.created_at = new Date().rfc3339();
+                },
+                success : function(resp, doc) {
+                    $("#new-comment").html("<h3>votre commentaire vient d'être ajouté.</h3>");
+                  $("#comments ol").append(B.commentListing(doc));
+                  $("#comments ol li:last").hide().fadeIn(2000);
+                }
+              });
+              
+              $("#preview").click(function() {
+                var doc = commentForm.localDoc();
+                if (typeof doc.comment != "undefined" && doc.comment) {
+                    var html = B.formatBody(doc.comment);
+                    $('#comment-preview').html(html);
+                }
+              });
+            });
         });
 
     </script>

lib/templates/search/head.html

+<!DOCTYPE html>
+<html lang="fr">
+<head>
+    <meta charset="utf-8"/>
+    <title>benoît chesneau web - search</title>
+
+    <!--[if IE]>
+
+    <script>
+        // allow IE to recognize HTMl5 elements
+        document.createElement('section');
+        document.createElement('article');
+        document.createElement('aside');
+        document.createElement('footer');
+        document.createElement('header');
+        document.createElement('nav');
+        document.createElement('time');
+
+    </script>
+    <![endif]-->
+    <link rel="openid.server" href="http://www.myopenid.com/server">
+    <link rel="openid.delegate" href="http://bchesneau.myopenid.com/">
+    <link rel="home index" href="http://benoitc.org/" type="text/html">
+    <link rel="me author" href="http://benoitc.org/static/benoitc.html" type="text/html">
+    <link type='application/atom+xml' href='<%= feedPath %>' rel='alternate' title='Writings'>
+
+    <link rel="stylesheet" href="<%= assets %>/css/benoitc.css" type="text/css" media="screen, projection" />
+</head>
+
+
+<body class="index">
+    <div id="container">
+        <header class="page">
+            <nav id="mainav">
+                <ul>
+                    <li><a href="/">accueil</a></li>
+                    <li><a href="<%= archivesPath %>">archives</a></li>
+                    <li><a href="<%= feedPath %>" type='application/atom+xml' class="atom">suivre</a></li>
+
+                </ul>
+            </nav>
+            <h1>
+                <a rel="me author" href="<%= assets %>/benoitc.html">Benoît Chesneau</a>
+            </h1>
+            <h2>artisan web</h2>
+
+            
+        </header>

lib/templates/search/row.html

+<article class="entry article">
+    <header class="meta">
+        <p><time title="GMT" datetime="<%= post.created_at %>"
+        class="caps"><%= fcreated_at %></time></p>
+    </header>
+    <h3>
+        <a href="<%= link %>"><%= post.title %></a>
+    </h3>
+    <p><%= post.summary %></p>
+</article>

lib/templates/search/tail.html

+        <footer id="main-footer">
+            <p>2009 (c) <a href="<%= assets %>/benoitc.html">Benoît Chesneau</a> - <a rel="license" href="http://creativecommons.org/licenses/by/2.0/fr/">Certains droits reservés</a>.</p>
+        </footer>
+    </div>
+</body>
+    <script src="/_utils/script/json2.js"></script>
+    <script src="/_utils/script/jquery.js"></script>
+    <script src="/_utils/script/jquery.couch.js"></script>
+
+    <script>
+        // ugly hack for rewriting
+        $.extend({
+            blog: {
+                dbname: "<%= env.dbname %>",
+                dname: "<%= env.dname %>"
+            }
+        });
+    </script
+    <script src="<%= assets %>/js/jquery.couchapp.js"></script>
+    <script src="<%= assets %>/js/strftime.js"></script>
+    <script src="<%= assets %>/js/blog.js"></script>
+    <script>
+        $(document).ready(function() {
+            localizeDates();
+        });
+
+    </script>
+</html>

lists/firehose.js

-function(head, row, req, row_info) {
-  // !json lib.templates.feeds
-  // !code lib.helpers.couchapp
-  // !code lib.helpers.ejs.ejs
-  // !code lib.helpers.ejs.view
-  // !code lib.helpers.template2
-
-    log (row_info);
-    return respondWith(req, {
-        html: function() {
-            
-            if (req.query.limit > 50) {
-                 throw({"error":"limit can't be bigger than 50"});
-            }
-
-            if (head) {
-                return template(lib.templates.feeds.head, {
-                    assets: assetPath()
-                });
-            } else if (row) {
-                var item = row.value;
-                var pd, ld = [];
-                var day_change = false;
-                
-                if (!row_info.first_key) {
-                    day_change = true;
-                    ld = row.key.split('T');
-                } else {
-                    if (!row_info.prev_key) {
-                        pd = row_info.first_key.split('T');
-                        ld = row.key.split('T');
-                    } else {
-                        pd = row_info.prev_key.split("T");
-                        ld = row.key.split("T");
-                    }
-
-                    if (ld[0] != pd[0]) {
-                        day_change = true;
-                    } else if (!pd) {
-                        day_change = true;
-                    }
-                }
-                return template(lib.templates.feeds.row, {
-                        item: item,
-                        last_day: ld[0],
-                        day_change: day_change,
-                });
-            } else {
-                return template(lib.templates.feeds.tail, {});
-            }
-        },
-        atom: function() {
-              if (head) {
-                  var f = <feed xmlns="http://www.w3.org/2005/Atom"/>;
-                  f.title = "firehose";
-                  f.id = makeAbsolute(req, "/");
-                  f.link.@href = makeAbsolute(req, "/");
-                  f.link.@rel = "self";
-                  f.generator = 'benoitc.org on CouchDB';
-                  f.updated = new Date().rfc3339();
-                  return {body:f.toXMLString().replace(/\<\/feed\>/,'')};
-              } else if (row) {
-
-                  var entry = <entry/>;
-                  entry.id = encodeURIComponent(row.id);
-                  entry.title = row.value.service.id;
-                  entry.content = row.value.title;
-                  entry.content.@type = 'html';
-                  entry.updated = new Date(row.value.published).rfc3339();
-                  entry.author = "<author><name>Benoît Chesneau</name></author>";
-                  entry.link.@href = encodeURIComponent(row.value.link);
-                  entry.link.@rel = "alternate";
-                  return {body:entry};
-              } else {
-                  return {body : "</feed>"};
-              }
-        }
-    })
-};
   var indexPath = listPath('index','recent-posts',{descending:true, limit:8});
   var feedPath = listPath('index','recent-posts',{descending:true, limit:8, format:"atom"});
   var archivesPath = listPath('index','recent-posts',{descending:true, limit:25});
-  var streamPath = listPath('firehose','stream',{descending:true, limit:25});
   return respondWith(req, {
     html: function() {
         if (head) {
             return template(lib.templates.index.head, {
                 assets: assetPath(),
                 archivesPath: archivesPath,
-                streamPath: streamPath,
-                feedParg: feedPath
+                feedPath: feedPath
             });
         } else if (row) {
             if (!req.query.limit && row_info.row_number == 7)
                     fcreated_at: fcreated_at,
                     link: showPath('post', row.id),
                     assets: assetPath(),
-                    feedPath: feedPath,
-                    streamPath: streamPath,
-                    test: req.rawpath,
+                    feedPath: feedPath
             });
         } else {
             var nextPath = listPath('index','recent-posts', {
 
             return template(lib.templates.index.tail, {
                 nextPath: nextPath,
-                assets: assetPath()
+                assets: assetPath(),
+                env: getEnv()
             });
         }
     },
+function(head, row, req, row_info) {
+  // !json lib.templates.search
+  // !json blog
+  // !json locales
+  // !code lib.helpers.couchapp
+  // !code lib.helpers.ejs.ejs
+  // !code lib.helpers.ejs.view
+  // !code lib.helpers.template2
+    
+  var indexPath = listPath('index','recent-posts',{descending:true, limit:8});
+  var feedPath = listPath('search','topics',{descending:true, limit:8, format:"atom"});
+  var archivesPath = listPath('index','recent-posts',{descending:true, limit:25});
+  return respondWith(req, {
+    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,
+                assets: assetPath(),
+                env: getEnv()
+            });
+        }
+    },
+    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: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>"};
+      }
+    }
+  })
+};
 function(doc, req) {  
   // !json lib.templates.edit
+  // !json blog
   // !code lib.helpers.ejs.ejs
   // !code lib.helpers.ejs.view
   // !code lib.helpers.template2
     doc : doc,
     docid : toJSON((doc && doc._id) || null), 
     assets : assetPath(),
-    index : listPath('index','recent-posts',{descending:true,limit:8})
+    index : listPath('index','recent-posts',{descending:true,limit:8}),
+    env: getEnv()
   });
 }
 function(doc, req) {  
   // !json lib.templates.post
+  // !json blog
   // !code lib.helpers.ejs.ejs
   // !code lib.helpers.ejs.view
   // !code lib.helpers.template2
     assets : assetPath(),
     editPostPath : showPath('edit', doc._id),
     labels: labels.join(', '),
-    index : listPath('index','recent-posts',{descending:true, limit:8})
+    index : listPath('index','recent-posts',{descending:true, limit:8}),
+    env: getEnv()
   });
 }

views/topics/.map.js.swp

Binary file added.

views/topics/map.js

+function(doc) {
+    // only posts have slugs, dates, and html
+    if (doc.doc_type == "post" && doc.labels && doc.labels.length) {
+        var summary = '';
+        if (doc.html.length <= 350) {
+            summary = doc.html;
+        } else {
+            summary = (doc.html.replace(/<(.|\n)*?>/g, '').substring(0,350) + '...');
+        }
+        for(var idx in doc.labels) {
+            emit(doc.labels[idx], {
+                summary : summary,
+                title : doc.title,
+                author : doc.author,
+                created_at : doc.created_at
+            }); 
+        }
+    }
+};