thomblr

convrt yr tumblr <3 to bookmrks
git clone https://wehaveforgeathome.hates.computer/thomblr.git
Log | Files | Refs | LICENSE

commit 17434ad1b4978f99424beba4d08b4689e809e904
parent 93cac1f1047a73bb7df036c8c2b634a51ef31a95
Author: Ryan Wolf <rwolf@borderstylo.com>
Date:   Thu, 24 Mar 2011 21:57:34 +0000

renamed to thomblr

Diffstat:
Mrouter.js | 3++-
Mserver.js | 21++++++++++++---------
Mstatic/index.html | 8++++----
Mtumblr.js | 13++++++++-----
4 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/router.js b/router.js @@ -32,7 +32,8 @@ exports.server = http.createServer(function (request, response) { var method = request.method.toLowerCase(); var path = url_parse(request.url).pathname.replace(/\/$/, ''); console.log(method + ': ' + path); - var matchingRoutes = routes[method].filter(function (route) { + var matchingRoutes = routes[method] || []; + matchingRoutes = matchingRoutes.filter(function (route) { return route.regex.test(path); }); if (path == '' && exports.index) { diff --git a/server.js b/server.js @@ -4,7 +4,6 @@ var sys = require('sys'), path = require('path'), urlParse = require('url').parse, paperboy = require('paperboy'), - mustache = require('../Mu/lib/mu'), xml2js = require('xml2js'), webroot = path.join(path.dirname(__filename), 'static'), router = require('./router'), @@ -31,15 +30,13 @@ var sendStatic = function (request, response) { * static assets **/ -router.get('thoms/index.html', sendStatic); -router.get('thoms/fav.png', sendStatic); +router.get('thomblr/index.html', sendStatic); +router.get('thomblr/fav.png', sendStatic); /** * the one and only interesting call **/ -var template = mustache.compileText('<<DT><A HREF="{{url}}">{{title}}</A>\n'); - -router.get('thoms/likes', function (request, response) { +router.get('thomblr/bookmarks.html', function (request, response) { var url = urlParse(request.url, true); if (!url.query) { response.writeHead(400); @@ -87,12 +84,18 @@ router.get('thoms/likes', function (request, response) { response.write(header.join('\n') + '\n'); if (!result.posts.post) { return response.end(''); } result.posts.post.forEach(function (post) { - response.write(tumblr.serialize(post)); + var link = tumblr.serialize(post); + var html = [ + '<DT><A HREF="', + link.url.replace('"', '\\"'), + '">', + link.title.replace('<', '&lt;').replace('>', '&gt;'), + '</A>\n' + ].join(''); + response.write(html); }); response.end('</DL><p>\n'); }); }); crequest.end(); }); - - diff --git a/static/index.html b/static/index.html @@ -1,6 +1,6 @@ <html> <head> - <title>thoms | convert yr tumblr &hearts; to bookmrks</title> + <title>thomblr | convert yr tumblr &hearts; to bookmrks</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { @@ -10,7 +10,7 @@ var handleChange = function () { var email = encodeURIComponent(e.val() || ''), password = encodeURIComponent(p.val() || ''); - l.attr('href', 'likes?email=' + email + '&password=' + password); + l.attr('href', 'bookmarks.html?email=' + email + '&password=' + password); }; $.each(['focus', 'blur', 'keyup', 'change', 'click'], function (i, e) { $('#email, #password')[e](handleChange); @@ -19,12 +19,12 @@ </script> </head> <body> - <h1>thoms</h1> + <h1>thomblr</h1> <h2>convrt yr tumblr <img src="fav.png" /> to bookmrks</h2> <ol> <li><input id="email" size="30" type="text" placeholder="enter your tumblr email address" /></li> <li><input id="password" size="30" type="password" placeholder="enter your tumblr password" /></li> - <li>save <a id="likes" href="likes?email=foo&password=bar" target="_blank">this tab</a> as "bookmarks.html"</li> + <li>save <a id="likes" href="bookmarks.html?email=foo&password=bar" target="_blank">this tab</a> as "bookmarks.html"</li> <li>follow the instructions on <a href="http://www.google.com/support/chrome/bin/answer.py?hl=en&answer=96816" target="_blank">this tab</a> to import "bookmarks.html"</li> </ol> </body> diff --git a/tumblr.js b/tumblr.js @@ -43,24 +43,27 @@ var title = { conversation: function (post) { var t = post['conversation-title']; return (t) ? t : title.none(post); + }, + video: function (post) { + var t = post['video-title']; + return (t) ? t : title.none(post); } }; var getTitle = function (post) { switch (post['@'].type) { - case 'quote': - case 'photo': - return title.none(post); case 'regular': return title.regular(post); case 'link': return title.link(post); case 'conversation': return title.conversation(post); + case 'video': + return title.video(post); } - return sys.inspect(post); + return title.none(post); }; exports.serialize = function (post) { - return sys.inspect({ url: getUrl(post), title: getTitle(post) }) + '\n'; + return { url: getUrl(post), title: getTitle(post) }; };