Skip to content

Add blog functionality for easy posting of updates #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dd8f26c
initial commit with the basic working version
laktek Nov 26, 2012
7247536
reset the posts list on every request
laktek Nov 26, 2012
dada6da
show the latest posts first
laktek Dec 13, 2012
f7ed905
Merge branch 'master' of github.com:laktek/punch-blog
laktek Dec 13, 2012
901f3de
Prepare archive helpers on the relavant pages
laktek Dec 13, 2012
1c2cfed
Fix inadvertent reversal of blog post order on the index page.
thisgeek Feb 17, 2013
9a8f430
Merge pull request #10 from thisgeek/master
laktek Feb 18, 2013
5c5818d
Don't squash words together
clee Mar 20, 2013
18649ce
Set is_teaser on a per-post basis
clee Mar 20, 2013
4646080
Merge pull request #11 from clee/patch-1
laktek Mar 21, 2013
027d196
Fixing helpers to work in windows environment
May 20, 2013
9711466
Merge branch 'pr/16'
laktek May 21, 2013
ab432f6
allow for fewer posts than homepage_posts length
Jul 11, 2013
6597c78
Follow W3C standard for datetime attribute. Fixes #19
laktek Aug 31, 2013
45d8dcf
index helper should use getPosts instead of getAllPosts
laktek Oct 12, 2013
1e84a3d
update base nodejs version to match with travis and netlify.
robertsky Nov 5, 2017
6a7eab1
Merge commit 'e2c76f492044fd7e4e2971332bc1463646be3a6d' into feature/…
robertsky Nov 16, 2017
1ada816
Merge branch 'blog-master' into feature/transit_to_punch_blog_for_plenum
robertsky Nov 16, 2017
c46601c
Merge commit 'd1bd0106ce262d694af02c114a739baac10ee2b9' into feature/…
robertsky Nov 16, 2017
a56b1a3
init commit for blog functionality
robertsky Nov 17, 2017
cc930a8
fix feed
robertsky Nov 17, 2017
a268206
brand current 404 template and add gtm for 404 tracking.
robertsky Nov 18, 2017
b56a6df
basic navigation references to the feed link
robertsky Nov 18, 2017
2d1c865
update feed link references
robertsky Nov 18, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,37 @@
},

"plugins": {
"content_handler": "punch-blog-content-handler",
"helpers": {
"formatted_date": "./helpers/formatted_date_helper.js",
"archive_helper": "./helpers/archive_helper.js",

"feed_helper": "./helpers/feed_helper.js",
"current_helper": "punch-current-page-helper"
},
"generator_hooks": {
"htaccess": "./bin/htaccess.js",
"redirects": "./bin/redirects.js"
"redirects": "./bin/redirects.js",
"sitemap_generator_hook": "punch-sitemap-generator"
}
},

"blog": {
"posts_dir": "posts",
"post_format": "md",
"post_url": "/updates/{year}/{month}/{date}/{title}",
"teaser_length": 2,
"homepage_posts": 10,
"archive_urls": {
"all": "/updates",
"year": "/updates/{year}",
"year_month": "/updates/{year}/{month}",
"year_month_date": "/updates/{year}/{month}/{date}",
"tag": "/updates/tag/{tag}"
}
},

"sitemap_generator": {
"url_root": "https://hackerspace.sg"
}
}
26 changes: 6 additions & 20 deletions contents/_index/events.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
[
{
"Name": "Python Meetup September",
"When": 1409830200000,
"URL": "https://www.facebook.com/events/685781994823718/685781998157051/?comment_id=687726351295949"
"Name": "SG Futurist - Life Extension Now",
"When": "2017-11-18T06:30:00.000Z",
"URL": "https://www.meetup.com/Singapore-Futurists/events/244400372/<br>Host:"
},
{
"Name": "SG WordPress Meetup (Sept 2014)",
"When": 1410348600000,
"URL": "https://www.facebook.com/events/492930457509067/492930467509066/"
},
{
"Name": "Papers We Love SG #002",
"When": 1410778800000
},
{
"Name": "Postgres User Group (PUGs) Meetup",
"When": 1410949800000,
"URL": "http://www.meetup.com/PUGS-Postgres-Users-Group-Singapore/"
},
{
"Name": "The Ukulele Assemble",
"When": 1411279200000,
"URL": "http://www.meetup.com/The-Ukulele-Assemble/events/204272602/"
"Name": "Super Sunday Photography Walk",
"When": "2017-11-26T00:30:00.000Z",
"URL": "https://www.google.com/url?q=https%3A%2F%2Fwww.facebook.com%2Fevents%2F1890104491256160%2F&amp;sa=D&amp;usd=2&amp;usg=AFQjCNGv8CO48HJPrrh8Xf_6NA2g2hk24A"
}
]
1 change: 1 addition & 0 deletions contents/feed.rss.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
10 changes: 7 additions & 3 deletions contents/shared.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"site-title": "HackerspaceSG: the Singapore tech scene's community centre",
"site-title": "HackerspaceSG",
"tagline": "the Singapore tech scene's community centre",
"host": "hackerspace.sg",
"creator": "HackerspaceSG",
"footer-text": "Built with <a href=\"http://laktek.github.com/punch\">Punch</a>",
"navbar": [
{ "label": "Home", "href": "/" },
{ "label": "Calendar", "href": "/calendar" },
{ "label": "Connect", "href": "/connect" },
{ "label": "Location", "href": "/location" },
{ "label": "Membership", "href": "/membership" },
{ "label": "About", "href": "/about" },
{ "label": "FAQ", "href": "/faq" }
{ "label": "About", "href": "/about" },
{ "label": "FAQ", "href": "/faq" },
{ "label": "Updates", "href": "/updates"}
]
}
62 changes: 62 additions & 0 deletions helpers/archive_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var _ = require("underscore");
var helper_utils = require("punch").Utils.Helper;
var path_utils = require("punch").Utils.Path;
var blog_content_handler = require("punch-blog-content-handler");

var all_posts = [];
var last_modified = null;

var fetch_all_posts = function(callback) {
//reset posts list
blog_content_handler.allPosts = {};

blog_content_handler.getAllPosts(function(err, posts_obj, posts_last_modified) {
if (!err) {
all_posts = _.values(posts_obj);
last_modified = posts_last_modified;
}

return callback();
});
}

var tag_helpers = {

years: function() {
return _.keys(blog_content_handler.postDates).reverse();
},

top_tags: function() {
var tag_counts = blog_content_handler.tagCounts;
return _.sortBy(_.keys(tag_counts), function(tag) {
return tag_counts[tag];
}).reverse();
}

};


module.exports = {

directAccess: function() {
return { "block_helpers": {}, "tag_helpers": {}, "options": {} };
},

get: function(basepath, file_extension, options, callback) {
var self = this;

var archive_url_regexs = _.map(blog_content_handler.archiveUrls, function(url) {
return new RegExp("^" + url.pattern + "\\/index$", "g");
});

if (path_utils.matchPath(basepath, archive_url_regexs)) {
fetch_all_posts(function() {
return callback(null, { "tag": tag_helpers }, {}, last_modified);
});
} else {
return callback(null, {}, {}, null);
}
}

}

70 changes: 70 additions & 0 deletions helpers/feed_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var _ = require("underscore");
var path = require("path");

var helper_utils = require("punch").Utils.Helper;
var path_utils = require("punch").Utils.Path;
var blog_content_handler = require("punch-blog-content-handler");

var all_posts = [];
var last_modified;

var fetch_content = function(callback) {
var all_post_permalinks = [];

blog_content_handler.getAllPosts(function(err, posts_obj, posts_last_modified) {
if (!err) {
all_post_permalinks = _.map(posts_obj, function(post){ return post.permalink; });
last_modified = posts_last_modified;
}

// fetch the content for each post
var fetch_full_post = function() {
if (all_post_permalinks.length) {
blog_content_handler.getPost(path.join(all_post_permalinks.shift(), "index"), function(err, post_contents, modified_date) {
if (!err) {
all_posts.push(post_contents);
}

return fetch_full_post();
});
} else {
return callback();
}
};

return fetch_full_post();

});
}

var tag_helpers = {

all_posts: function() {
return all_posts.reverse();
},

last_modified: function() {
return last_modified;
}

};

module.exports = {

directAccess: function(){
return { "block_helpers": {}, "tag_helpers": {}, "options": {} };
},

get: function(basepath, file_extension, options, callback){
var self = this;

if (!path_utils.matchPath(basepath, "^/feed$")) {
return callback(null, {}, {}, null);
}

fetch_content(function() {
return callback(null, { "tag": tag_helpers }, {}, last_modified);
});
}

}
56 changes: 56 additions & 0 deletions helpers/formatted_date_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var helper_utils = require("punch").Utils.Helper;

var getDateValue = function(text){
return String(text).match(/^\d+$/) ? parseInt(text, 10) : text;
};

var block_helpers = {
long_date: function() {
return helper_utils.checkArgs(arguments, function(text) {
if(!text) {
return "";
}

var published_date = new Date( getDateValue(text) );
var month_names = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];

var f_date = (published_date.getDate() < 10) ? ("0" + published_date.getDate()) : published_date.getDate();
var f_month = month_names[published_date.getMonth()];
var f_year = published_date.getFullYear();

return f_date + " " + f_month + " " + f_year;
});
},

short_date: function() {
return helper_utils.checkArgs(arguments, function(text) {
if(!text) {
return "";
}

var published_date = new Date( getDateValue(text) );
var month_names = [ "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ];

var f_date = (published_date.getDate() < 10) ? ("0" + published_date.getDate()) : published_date.getDate();
var f_month = month_names[published_date.getMonth()];
var f_year = published_date.getFullYear();

return f_date + " " + f_month + " " + f_year;
});
}

};

module.exports = {

directAccess: function(){
return { "block_helpers": block_helpers, "options": {} };
},

get: function(basepath, file_extension, options, callback){
var self = this;

return callback(null, { "block": block_helpers }, {});
}

};
95 changes: 95 additions & 0 deletions helpers/index_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
var _ = require("underscore");
var path = require("path");

var helper_utils = require("punch").Utils.Helper;
var path_utils = require("punch").Utils.Path;
var blog_content_handler = require("punch-blog-content-handler");

var homepage_posts = 10;
var teaser_length = 2;
var recent_posts = [];
var last_modified = null;

var fetch_content = function(callback) {
recent_posts = [];

//reset posts list
blog_content_handler.allPosts = {};

blog_content_handler.getPosts('', function(err, posts_obj, posts_last_modified) {
if (!err) {
var all_posts = posts_obj.posts;

last_modified = posts_last_modified;

var recent_posts_list = all_posts.length > homepage_posts ? all_posts.slice(all_posts.length - homepage_posts) : all_posts;

var fetch_full_posts = function() {
if (recent_posts_list.length) {
blog_content_handler.getPost(path.join(recent_posts_list.shift().permalink, "index"), function(err, post_contents, modified_date) {
var post_paras = post_contents.content.replace(/\n/g, " ").match(/(<p[^>]*>.*?<\/p>)/g);

if (teaser_length < 1) {
paras_to_show = post_paras.length;
} else {
paras_to_show = teaser_length;
}

post_contents.is_teaser = (paras_to_show < post_paras.length);
post_contents.content = post_paras.slice(0, paras_to_show).join("");

if (!err) {
recent_posts.push(post_contents);
}

return fetch_full_posts()

});
} else {
return callback();
}
}

return fetch_full_posts();

} else {
console.log(err);
return callback();
}
});
}

var tag_helpers = {

recent_posts: function() {
return recent_posts;
}

};

module.exports = {

setup: function(config) {
if (config.blog) {
teaser_length = config.blog.teaser_length;
homepage_posts = config.blog.homepage_posts;
}
},

directAccess: function(){
return { "block_helpers": {}, "tag_helpers": {}, "options": {} };
},

get: function(basepath, file_extension, options, callback){
var self = this;

if (!path_utils.matchPath(basepath, "^/index$")) {
return callback(null, {}, {}, null);
}

fetch_content(function() {
return callback(null, { "tag": tag_helpers }, {}, last_modified);
});
}

}
Loading