summaryrefslogtreecommitdiff
path: root/gulpfile.js
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-08-01 02:11:52 +1000
committerMonty Taylor <mordred@inaugust.com>2015-08-01 02:11:52 +1000
commit23a91cae672fb9f8b208b474efbfa01bf5d66f26 (patch)
tree33ed93ea03dfdfd0875ea712b615d1522cbd5aca /gulpfile.js
parent69d66321015064c63ef6377ccff5f6d35560fb19 (diff)
Get blog posts on there
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js54
1 files changed, 52 insertions, 2 deletions
diff --git a/gulpfile.js b/gulpfile.js
index f6334a3..974d3fd 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -30,6 +30,7 @@
30 'css': dir.src + '/css/**/*.css', 30 'css': dir.src + '/css/**/*.css',
31 'js': dir.src + '/js/**/*.js', 31 'js': dir.src + '/js/**/*.js',
32 'talks': dir.src + '/talks', 32 'talks': dir.src + '/talks',
33 'posts': dir.src + '/posts',
33 'images': [ 34 'images': [
34 dir.src + '/**/*.png', 35 dir.src + '/**/*.png',
35 dir.src + '/**/*.gif', 36 dir.src + '/**/*.gif',
@@ -71,7 +72,6 @@
71 var $ = cheerio.load(fs.readFileSync(file)); 72 var $ = cheerio.load(fs.readFileSync(file));
72 presentations.push({ 73 presentations.push({
73 'title': $("head title").text(), 74 'title': $("head title").text(),
74 'author': $('head meta[name="author"]').attr('content'),
75 'mtime': stat.mtime, 75 'mtime': stat.mtime,
76 'path': files[i] + '/index.html' 76 'path': files[i] + '/index.html'
77 }); 77 });
@@ -86,6 +86,34 @@
86 } 86 }
87 87
88 /** 88 /**
89 * This method parses through discovered posts, reads their
90 * html metadata, and returns an array of that metadata.
91 */
92 function buildPostManifest () {
93 var posts = [];
94 var files = fs.readdirSync(paths.posts);
95
96 for (var i = 0; i < files.length; i++) {
97 var file = paths.posts + '/' + files[i];
98 try {
99 var stat = fs.statSync(file);
100 var $ = cheerio.load(fs.readFileSync(file));
101 posts.push({
102 'title': $("head title").text(),
103 'mtime': stat.mtime,
104 'path': 'posts/' + files[i]
105 });
106 } catch (e) {
107 // Do nothing
108 }
109 }
110 posts.sort(function (a, b) {
111 return a.mtime >= b.mtime ? 1 : -1;
112 });
113 return posts;
114 }
115
116 /**
89 * Clean the output directory. 117 * Clean the output directory.
90 * 118 *
91 * @param {Function} cb callback. 119 * @param {Function} cb callback.
@@ -180,6 +208,25 @@
180 }); 208 });
181 209
182 /** 210 /**
211 * Package the handlebars files.
212 */
213 gulp.task('package:posts', function () {
214
215 var templateData = {
216 'posts': buildPostManifest(),
217 'author': packageJson.author
218 };
219
220 // Automatically build the site list.
221 return gulp.src(dir.src + '/index.hbs', {'base': dir.src})
222 .pipe(handlebars(templateData, handlebarsConfig))
223 .pipe(rename(function (path) {
224 path.extname = ".html";
225 }))
226 .pipe(gulp.dest(dir.dist));
227 });
228
229 /**
183 * Copy the HTML files into the dist folder. 230 * Copy the HTML files into the dist folder.
184 */ 231 */
185 gulp.task('package:html', function () { 232 gulp.task('package:html', function () {
@@ -247,7 +294,8 @@
247 /** 294 /**
248 * Package the entire site into the dist folder. 295 * Package the entire site into the dist folder.
249 */ 296 */
250 gulp.task('package', ['package:html', 'package:talks', 'package:libs', 297 gulp.task('package', ['package:html', 'package:talks', 'package:posts',
298 'package:libs',
251 'package:images', 'package:css', 'package:js']); 299 'package:images', 'package:css', 'package:js']);
252 300
253 gulp.task('rsync', function () { 301 gulp.task('rsync', function () {
@@ -275,6 +323,8 @@
275 gulp.watch(paths.hbs, ['package:talks']); 323 gulp.watch(paths.hbs, ['package:talks']);
276 gulp.watch(paths.css, ['package:css']); 324 gulp.watch(paths.css, ['package:css']);
277 gulp.watch(paths.js, ['package:js']); 325 gulp.watch(paths.js, ['package:js']);
326 gulp.watch(paths.posts, ['package:posts']);
327 gulp.watch(paths.index, ['package:posts']);
278 328
279 return gulp.src(dir.dist) 329 return gulp.src(dir.dist)
280 .pipe(webserver({ 330 .pipe(webserver({