always show article list on blog pages

This commit is contained in:
Sami Samhuri 2011-11-27 20:26:42 -08:00
parent 1e6d95d137
commit 0f3917b3df
4 changed files with 52 additions and 43 deletions

View file

@ -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

View file

@ -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],

View file

@ -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 ? '&darr; show posts &darr;' : '&uarr; hide posts &uarr;')
})
})
</script>
{{#comments}}
<script>

View file

@ -13,6 +13,14 @@
<header>
<h1><a href="index.html">sjs' blog</a></h1>
</header>
<div id="show-posts" class="center"><a id="index-toggle" href="#">&darr; show posts &darr;</a></div>
<nav id="index" class="hidden">
<ul>
{{#posts}}
<li><a href="{{url}}">{{title}}</a> <span class="date">{{date}}</span></li>
{{/posts}}
</ul>
</nav>
{{{article}}}
<div id="around">
{{#previous}}