mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
always show article list on blog pages
This commit is contained in:
parent
1e6d95d137
commit
0f3917b3df
4 changed files with 52 additions and 43 deletions
|
|
@ -1,42 +1,52 @@
|
||||||
;(function() {
|
;(function() {
|
||||||
if (typeof console === 'undefined')
|
if (typeof console === 'undefined')
|
||||||
window.console = {}
|
window.console = {}
|
||||||
if (typeof console.log !== 'function')
|
if (typeof console.log !== 'function')
|
||||||
window.console.log = function(){}
|
window.console.log = function(){}
|
||||||
if (typeof console.dir !== 'function')
|
if (typeof console.dir !== 'function')
|
||||||
window.console.dir = function(){}
|
window.console.dir = function(){}
|
||||||
|
|
||||||
var server = 'http://bohodev.net:8000/'
|
var server = 'http://bohodev.net:8000/'
|
||||||
, getCommentsURL = function(post) { return server + 'comments/' + post }
|
, getCommentsURL = function(post) { return server + 'comments/' + post }
|
||||||
, postCommentURL = function() { return server + 'comment' }
|
, postCommentURL = function() { return server + 'comment' }
|
||||||
, countCommentsURL = function(post) { return server + 'count/' + post }
|
, countCommentsURL = function(post) { return server + 'count/' + post }
|
||||||
|
|
||||||
function getComments() {
|
function getComments() {
|
||||||
SJS.request({uri: getCommentsURL(SJS.filename)}, function(err, request, body) {
|
SJS.request({uri: getCommentsURL(SJS.filename)}, function(err, request, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
$('#comments').text('derp')
|
$('#comments').text('derp')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var data
|
var data
|
||||||
, comments
|
, comments
|
||||||
, h = ''
|
, h = ''
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(body)
|
data = JSON.parse(body)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('not json -> ' + body)
|
console.log('not json -> ' + body)
|
||||||
}
|
}
|
||||||
comments = data.comments
|
comments = data.comments
|
||||||
if (comments.length) {
|
if (comments.length) {
|
||||||
h = data.comments.map(function(c) {
|
h = data.comments.map(function(c) {
|
||||||
return tmpl('comment_tmpl', c)
|
return tmpl('comment_tmpl', c)
|
||||||
}).join('')
|
}).join('')
|
||||||
}
|
}
|
||||||
$('#comments').html(h)
|
$('#comments').html(h)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery(function($) {
|
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()
|
$('#need-js').remove()
|
||||||
console.dir($('#need-js'))
|
|
||||||
|
|
||||||
SJS.request({uri: countCommentsURL(SJS.filename)}, function(err, request, body) {
|
SJS.request({uri: countCommentsURL(SJS.filename)}, function(err, request, body) {
|
||||||
if (err) return
|
if (err) return
|
||||||
|
|
|
||||||
3
blog.rb
3
blog.rb
|
|
@ -66,7 +66,8 @@ class Blag
|
||||||
page_template = File.read(File.join('templates', 'blog', 'post.html'))
|
page_template = File.read(File.join('templates', 'blog', 'post.html'))
|
||||||
posts.each_with_index do |post, i|
|
posts.each_with_index do |post, i|
|
||||||
template = post[:link] ? link_template : post_template
|
template = post[:link] ? link_template : post_template
|
||||||
values = { :title => post[:title],
|
values = { :posts => posts,
|
||||||
|
:title => post[:title],
|
||||||
:link => post[:link],
|
:link => post[:link],
|
||||||
:article => Mustache.render(template, post),
|
:article => Mustache.render(template, post),
|
||||||
:previous => i < posts.length - 1 && posts[i + 1],
|
:previous => i < posts.length - 1 && posts[i + 1],
|
||||||
|
|
|
||||||
|
|
@ -79,16 +79,6 @@ _gaq.push( ['_setAccount', 'UA-214054-5']
|
||||||
var s = document.getElementsByTagName('script')[0]
|
var s = document.getElementsByTagName('script')[0]
|
||||||
s.parentNode.insertBefore(ga, s)
|
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 ↑')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
{{#comments}}
|
{{#comments}}
|
||||||
<script>
|
<script>
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,14 @@
|
||||||
<header>
|
<header>
|
||||||
<h1><a href="index.html">sjs' blog</a></h1>
|
<h1><a href="index.html">sjs' blog</a></h1>
|
||||||
</header>
|
</header>
|
||||||
|
<div id="show-posts" class="center"><a id="index-toggle" href="#">↓ show posts ↓</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}}}
|
{{{article}}}
|
||||||
<div id="around">
|
<div id="around">
|
||||||
{{#previous}}
|
{{#previous}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue