Created
May 20, 2016 09:12
-
-
Save HoverBaum/cdec2a667a9616de374a790d39174466 to your computer and use it in GitHub Desktop.
Gulpfile and gitlab CI config to go with my Hexo based blog.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: node:4.2.2 | |
pages: | |
cache: | |
paths: | |
- node_modules/ | |
script: | |
- npm install -g gulp | |
- npm install | |
- gulp hexo | |
- gulp | |
artifacts: | |
paths: | |
- public | |
only: | |
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var ftp = require('vinyl-ftp'); | |
var cssnano = require('gulp-cssnano'); | |
var htmlmin = require('gulp-htmlmin'); | |
var minifyInline = require('gulp-minify-inline'); | |
var del = require('del'); | |
var gutil = require('gulp-util'); | |
var Hexo = require('hexo') | |
var hexo = new Hexo(process.cwd(), {}); | |
gulp.task('deploy', function() { | |
var conn = ftp.create({ | |
host: '', | |
user: '', | |
password: '', | |
parallel: 10, | |
log: gutil.log | |
}); | |
// using base = '.' will transfer everything correctly | |
// turn off buffering in gulp.src for best performance | |
return gulp.src('./public/**/*', { | |
base: './public', | |
buffer: false | |
}) | |
.pipe(conn.newer('/html/baum/')) // only upload newer files | |
.pipe(conn.dest('/html/baum/')); | |
}); | |
gulp.task('html', function() { | |
gulp.src('./public/**/*.html') | |
.pipe(minifyInline()) | |
.pipe(htmlmin({ | |
collapseWhitespace: true | |
})) | |
.pipe(gulp.dest('./public')); | |
}); | |
gulp.task('css', function() { | |
gulp.src('./public/**/*.css') | |
.pipe(cssnano()) | |
.pipe(gulp.dest('./public')); | |
}) | |
gulp.task('hexo', function() { | |
hexo.init().then(function() { | |
hexo.call('generate', {}).then(function() { | |
hexo.exit(); | |
}); | |
}); | |
}); | |
gulp.task('all', function() { | |
hexo.init().then(function() { | |
hexo.call('generate', {}).then(function() { | |
gulp.start('publish'); | |
}); | |
}); | |
}); | |
//Cleanup | |
gulp.task('clean', function() { | |
del(['public/']) | |
}); | |
gulp.task('publish', ['default'], function() { | |
gulp.start('deploy'); | |
}) | |
gulp.task('default', function() { | |
gulp.start('html', 'css'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment