From 24819804aa2d37dc8b0d3e8220b285f2766a9aca Mon Sep 17 00:00:00 2001 From: David Calavera Date: Thu, 1 Sep 2016 07:59:24 -0700 Subject: Add deploy preview context. So we can see content from drafts and the future in deploy previews. Signed-off-by: David Calavera --- gulpfile.babel.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'gulpfile.babel.js') diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 62e65d0..b3c942c 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -10,20 +10,13 @@ import webpackConfig from "./webpack.conf"; const browserSync = BrowserSync.create(); const hugoBin = "hugo"; +const defaultArgs = ["-d", "../dist", "-s", "site", "-v"]; -gulp.task("hugo", (cb) => { - const args = ["-d", "../dist", "-s", "site", "-v"]; - return cp.spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => { - if (code === 0) { - browserSync.reload(); - } else { - browserSync.notify("Hugo build failed :("); - } - cb(); - }); -}); +gulp.task("hugo", (cb) => buildSite(cb)); +gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"])); gulp.task("build", ["css", "js", "hugo"]); +gulp.task("build-preview", ["css", "js", "hugo-preview"]); gulp.task("css", () => ( gulp.src("./src/css/*.css") @@ -56,3 +49,12 @@ gulp.task("server", ["hugo", "css", "js"], () => { gulp.watch("./src/css/**/*.css", ["css"]); gulp.watch("./site/**/*", ["hugo"]); }); + +function buildSite(cb, options) { + const args = options ? defaultArgs.concat(options) : defaultArgs; + + return cp.spawn(hugoBin, args, {stdio: "inherit"}).on("close", () => { + browserSync.reload(); + cb(); + }); +} -- cgit v1.3