From 23a91cae672fb9f8b208b474efbfa01bf5d66f26 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 1 Aug 2015 02:11:52 +1000 Subject: Get blog posts on there --- gulpfile.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index f6334a3..974d3fd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -30,6 +30,7 @@ 'css': dir.src + '/css/**/*.css', 'js': dir.src + '/js/**/*.js', 'talks': dir.src + '/talks', + 'posts': dir.src + '/posts', 'images': [ dir.src + '/**/*.png', dir.src + '/**/*.gif', @@ -71,7 +72,6 @@ var $ = cheerio.load(fs.readFileSync(file)); presentations.push({ 'title': $("head title").text(), - 'author': $('head meta[name="author"]').attr('content'), 'mtime': stat.mtime, 'path': files[i] + '/index.html' }); @@ -85,6 +85,34 @@ return presentations; } + /** + * This method parses through discovered posts, reads their + * html metadata, and returns an array of that metadata. + */ + function buildPostManifest () { + var posts = []; + var files = fs.readdirSync(paths.posts); + + for (var i = 0; i < files.length; i++) { + var file = paths.posts + '/' + files[i]; + try { + var stat = fs.statSync(file); + var $ = cheerio.load(fs.readFileSync(file)); + posts.push({ + 'title': $("head title").text(), + 'mtime': stat.mtime, + 'path': 'posts/' + files[i] + }); + } catch (e) { + // Do nothing + } + } + posts.sort(function (a, b) { + return a.mtime >= b.mtime ? 1 : -1; + }); + return posts; + } + /** * Clean the output directory. * @@ -179,6 +207,25 @@ .pipe(gulp.dest(dir.dist)); }); + /** + * Package the handlebars files. + */ + gulp.task('package:posts', function () { + + var templateData = { + 'posts': buildPostManifest(), + 'author': packageJson.author + }; + + // Automatically build the site list. + return gulp.src(dir.src + '/index.hbs', {'base': dir.src}) + .pipe(handlebars(templateData, handlebarsConfig)) + .pipe(rename(function (path) { + path.extname = ".html"; + })) + .pipe(gulp.dest(dir.dist)); + }); + /** * Copy the HTML files into the dist folder. */ @@ -247,7 +294,8 @@ /** * Package the entire site into the dist folder. */ - gulp.task('package', ['package:html', 'package:talks', 'package:libs', + gulp.task('package', ['package:html', 'package:talks', 'package:posts', + 'package:libs', 'package:images', 'package:css', 'package:js']); gulp.task('rsync', function () { @@ -275,6 +323,8 @@ gulp.watch(paths.hbs, ['package:talks']); gulp.watch(paths.css, ['package:css']); gulp.watch(paths.js, ['package:js']); + gulp.watch(paths.posts, ['package:posts']); + gulp.watch(paths.index, ['package:posts']); return gulp.src(dir.dist) .pipe(webserver({ -- cgit v1.2.3