Skip to content

Commit

Permalink
New config show_author & enable pagination.
Browse files Browse the repository at this point in the history
show_author determines if the author should be displayed in the article
title.  It is disabled by default.

Fixes issue guyht#5
  • Loading branch information
Guy Halford-Thompson committed Feb 16, 2012
1 parent ccdcc76 commit 5d56f01
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -90,6 +90,7 @@ These options should be placed in glog_cofig.json and should be valid JSON
base_url - (Optional) Base URL for the blog. Defaults to '/'
cache_time - (Optional) Time in seconds to cache each page
article_per_page - (Optional) Number of articles to display on a page. Defaults to 10
show_author - (Optional) Display the author name in the article title. Defaults to false

# Running the tests

Expand Down
3 changes: 2 additions & 1 deletion glog_config.sample.json
Expand Up @@ -5,5 +5,6 @@
"port" : 8080,
"base_url" : "",
"cache_time" : 28800,
"articles_per_page" : 10
"articles_per_page" : 10,
"show_author" : false
}
15 changes: 9 additions & 6 deletions lib/glog.js
Expand Up @@ -29,7 +29,8 @@ Glog.prototype.load_configs = function(cb) {
// Set defaults
var options = {
blog_title : 'Glog Blog',
articles_per_page : 10
articles_per_page : 10,
show_author : false
},
fn = this,
key;
Expand Down Expand Up @@ -174,14 +175,15 @@ Glog.prototype.render_blog = function(options, articles, cb) {

for(i = 0; i < len; i++) {
start = (per_page * i);
end = articles.length < (per_page * (i + 1)) - 1 ? articles.length : (per_page * (i + 1));
end = articles.length < (per_page * (i + 1)) ? articles.length : (per_page * (i + 1));

fn.pages['_page' + (i+1)] = ja({
'title' : options.blog_title,
'title' : options.blog_title,
'analytics_code' : options.analytics_code || null,
'base_url' : options.base_url || '',
'articles' : articles.slice(start, end),
'page_num' : end === articles.length ? -1 : (i+1) // If we are on the last page, pass -1 so we know there are no more pages
'base_url' : options.base_url || '',
'show_author' : options.show_author,
'articles' : articles.slice(start, end),
'page_num' : end === articles.length ? -1 : (i+1) // If we are on the last page, pass -1 so we know there are no more pages
});

// pages[/] === pages[_page1]
Expand All @@ -199,6 +201,7 @@ Glog.prototype.render_blog = function(options, articles, cb) {
'disqus_id' : options.disqus_id || -1,
'analytics_code' : options.analytics_code || null,
'base_url' : options.base_url || '',
'show_author' : options.show_author,
'single' : true
});
}
Expand Down

0 comments on commit 5d56f01

Please sign in to comment.