Skip to content

Instantly share code, notes, and snippets.

@tterb
Created December 20, 2019 07:59
Show Gist options
  • Save tterb/5cceac18fae3f2b497c5395ca9262294 to your computer and use it in GitHub Desktop.
Save tterb/5cceac18fae3f2b497c5395ca9262294 to your computer and use it in GitHub Desktop.
Jekyll build
// Run jekyll build command.
gulp.task('build:jekyll', function() {
var shellCommand = 'bundle exec jekyll build --config _config.yml';
return gulp.src('')
.pipe(run(shellCommand))
.on('error', gutil.log);
});
// Special tasks for building and reloading BrowserSync
gulp.task('build:jekyll:watch', ['build:jekyll:local'], function(callback) {
browserSync.reload();
callback();
});
gulp.task('build:scripts:watch', ['build:scripts'], function(callback) {
browserSync.reload();
callback();
});
// Serve site and watch files
gulp.task('serve', ['build'], function() {
browserSync.init({
server: paths.siteDir,
ghostMode: false, // Toggle to mirror clicks, reloads etc (performance)
logFileChanges: true,
logLevel: 'debug',
open: true // Toggle to auto-open page when starting
});
gulp.watch(['_config.yml'], ['build:jekyll:watch']);
// Watch .scss files and pipe changes to browserSync
gulp.watch('_assets/styles/**/*.scss', ['build:styles']);
// Watch .js files
gulp.watch('_assets/js/**/*.js', ['build:scripts:watch']);
// Watch image files and pipe changes to browserSync
gulp.watch('_assets/img/**/*', ['build:images']);
// Watch posts
gulp.watch('_posts/**/*.+(md|markdown|MD)', ['build:jekyll:watch']);
// Watch drafts if --drafts flag was passed
if (module.exports.drafts) {
gulp.watch('_drafts/*.+(md|markdown|MD)', ['build:jekyll:watch']);
}
// Watch html and markdown files
gulp.watch(['**/*.+(html|md|markdown|MD)', '!_site/**/*.*'], ['build:jekyll:watch']);
// Watch RSS feed
gulp.watch('feed.xml', ['build:jekyll:watch']);
// Watch data files
gulp.watch('_data/**.*+(yml|yaml|csv|json)', ['build:jekyll:watch']);
});
// Build site
gulp.task('build', function(callback) {
runSequence(['build:scripts', 'build:styles', 'build:images', 'build:fonts', 'build:downloads'], 'build:jekyll', callback);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment