Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gulpfile and gitlab CI config to go with my Hexo based blog.
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
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