diff --git a/assets/blog.js b/assets/blog.js index 76d426d..00e5a58 100644 --- a/assets/blog.js +++ b/assets/blog.js @@ -1,42 +1,52 @@ ;(function() { - if (typeof console === 'undefined') - window.console = {} - if (typeof console.log !== 'function') - window.console.log = function(){} - if (typeof console.dir !== 'function') - window.console.dir = function(){} + if (typeof console === 'undefined') + window.console = {} + if (typeof console.log !== 'function') + window.console.log = function(){} + if (typeof console.dir !== 'function') + window.console.dir = function(){} - var server = 'http://bohodev.net:8000/' - , getCommentsURL = function(post) { return server + 'comments/' + post } - , postCommentURL = function() { return server + 'comment' } - , countCommentsURL = function(post) { return server + 'count/' + post } + var server = 'http://bohodev.net:8000/' + , getCommentsURL = function(post) { return server + 'comments/' + post } + , postCommentURL = function() { return server + 'comment' } + , countCommentsURL = function(post) { return server + 'count/' + post } - function getComments() { - SJS.request({uri: getCommentsURL(SJS.filename)}, function(err, request, body) { - if (err) { - $('#comments').text('derp') - return - } - var data - , comments - , h = '' - try { - data = JSON.parse(body) - } catch (e) { - console.log('not json -> ' + body) - } - comments = data.comments - if (comments.length) { - h = data.comments.map(function(c) { - return tmpl('comment_tmpl', c) - }).join('') - } - $('#comments').html(h) + function getComments() { + SJS.request({uri: getCommentsURL(SJS.filename)}, function(err, request, body) { + if (err) { + $('#comments').text('derp') + return + } + var data + , comments + , h = '' + try { + data = JSON.parse(body) + } catch (e) { + console.log('not json -> ' + body) + } + comments = data.comments + if (comments.length) { + h = data.comments.map(function(c) { + return tmpl('comment_tmpl', c) + }).join('') + } + $('#comments').html(h) }) } + jQuery(function($) { + + var hidden = true + , index = $('#index') + + $('#index-toggle').click(function() { + index.toggle() + hidden = !hidden + $(this).html(hidden ? '↓ show posts ↓' : '↑ hide posts ↑') + }) + $('#need-js').remove() - console.dir($('#need-js')) SJS.request({uri: countCommentsURL(SJS.filename)}, function(err, request, body) { if (err) return diff --git a/blog.rb b/blog.rb index 8e0db4e..e0be674 100755 --- a/blog.rb +++ b/blog.rb @@ -66,7 +66,8 @@ class Blag page_template = File.read(File.join('templates', 'blog', 'post.html')) posts.each_with_index do |post, i| template = post[:link] ? link_template : post_template - values = { :title => post[:title], + values = { :posts => posts, + :title => post[:title], :link => post[:link], :article => Mustache.render(template, post), :previous => i < posts.length - 1 && posts[i + 1], diff --git a/templates/blog/index.html b/templates/blog/index.html index a90b7c4..b0374ce 100644 --- a/templates/blog/index.html +++ b/templates/blog/index.html @@ -79,16 +79,6 @@ _gaq.push( ['_setAccount', 'UA-214054-5'] var s = document.getElementsByTagName('script')[0] s.parentNode.insertBefore(ga, s) }()) - -jQuery(function($) { - var hidden = true - , index = $('#index') - $('#index-toggle').click(function() { - index.toggle() - hidden = !hidden - $(this).html(hidden ? '↓ show posts ↓' : '↑ hide posts ↑') - }) -}) {{#comments}}