From 55122180d660de9bde591912d20aac7b29f4cb2c Mon Sep 17 00:00:00 2001 From: Matt Stratton Date: Mon, 9 Jan 2017 03:53:37 -0600 Subject: [PATCH] Gulp workflow#11 (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change value of canonify URLs to false This was needed for some gulp stuff. We’ll have to see if it breaks other things. Signed-off-by: Matt Stratton * Move gulp files to root of theme project This might be weird later, but it makes sense for now. Signed-off-by: Matt Stratton * Remove useless debug from 2016-chicago Signed-off-by: Matt Stratton * Add dist and staging build directories to .gitignore for exampleSite Signed-off-by: Matt Stratton * Add netlify build stuff Signed-off-by: Matt Stratton * Create all the gulp things Signed-off-by: Matt Stratton * Fix netlify base file Signed-off-by: Matt Stratton --- bin/netlify-production.sh | 5 ++ exampleSite/.gitignore | 2 + exampleSite/config.toml | 2 +- .../content/events/2016-chicago/debug.md | 8 --- gulpfile.js | 66 +++++++++++++++++++ layouts/partials/footer_scripts.html | 2 + layouts/partials/head_includes.html | 10 +-- netlify.toml | 16 +++++ package.json | 25 +++++++ 9 files changed, 123 insertions(+), 13 deletions(-) create mode 100644 bin/netlify-production.sh delete mode 100644 exampleSite/content/events/2016-chicago/debug.md create mode 100644 gulpfile.js create mode 100644 netlify.toml create mode 100644 package.json diff --git a/bin/netlify-production.sh b/bin/netlify-production.sh new file mode 100644 index 000000000..2e5c4e63b --- /dev/null +++ b/bin/netlify-production.sh @@ -0,0 +1,5 @@ +ln -s /opt/build/repo /opt/build/devopsdays-theme +cd exampleSite +../bin/hugo version +../bin/hugo -v --theme=devopsdays-theme --buildDrafts=false --baseURL="/" +gulp --cwd . diff --git a/exampleSite/.gitignore b/exampleSite/.gitignore index 364c4c9ec..a394075d6 100644 --- a/exampleSite/.gitignore +++ b/exampleSite/.gitignore @@ -1,2 +1,4 @@ public/ themes +dist/ +staging/ diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 4b30755cf..f2ff9a11c 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -5,7 +5,7 @@ themesdir = "../.." languageCode = "en-us" GoogleAnalytics = "UA-9713393-1" title = "DevOpsDays" -canonifyurls = true +canonifyurls = false dataDir = "data" archetypedir = "archetypes" PaginatePath = "blog" diff --git a/exampleSite/content/events/2016-chicago/debug.md b/exampleSite/content/events/2016-chicago/debug.md deleted file mode 100644 index 07dc72f4d..000000000 --- a/exampleSite/content/events/2016-chicago/debug.md +++ /dev/null @@ -1,8 +0,0 @@ -+++ -Description = "" -title = "" -speaker = "" -images = [""] -aliases = ["/matt-debug"] -type = "event" -+++ diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000..6b4077aa3 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,66 @@ +var gulp = require('gulp'), + useref = require('gulp-useref'), + gulpif = require('gulp-if'), + uglify = require('gulp-uglify'), + minifyCss = require('gulp-clean-css'); + rev = require('gulp-rev'); + revReplace = require('gulp-rev-replace'); + htmlmin = require('gulp-htmlmin'); + imagemin = require('gulp-imagemin'); + cache = require('gulp-cache'); + runSequence = require('run-sequence'); + +gulp.task('useref', function(){ + return gulp.src('public/**/*.html') + .pipe(useref({ searchPath: ['public/css', 'public/font-awesome'] })) + .pipe(gulpif('*.js', uglify())) + .pipe(gulpif('*.css', minifyCss())) + .pipe(gulpif('*.html', htmlmin({collapseWhitespace: true}))) + .pipe(gulp.dest('staging')); +}); + +// The process-images task took about 6 minutes for just sponsors; for now we probably +// will just copy the images and not optimize them + +gulp.task('process-images', function(){ + return gulp.src('public/**/*.+(png|jpg|gif|svg)') + .pipe(cache(imagemin())) + .pipe(gulp.dest('staging')) +}); + +gulp.task('copy-images', function(){ + return gulp.src('public/**/*.+(png|jpg|gif|svg)') + .pipe(gulp.dest('staging')) +}); + +gulp.task('process-files', function(){ + return gulp.src(['staging/**/*.+(png|jpg|gif|svg|js|css)','!staging/favicon*', '!staging/apple-icon*', '!staging/android-icon*', '!staging/ms-icon*']) + .pipe(rev()) + .pipe(gulp.dest('dist')) + .pipe(rev.manifest()) + .pipe(gulp.dest('dist')) +}); + +gulp.task('update-files', function(){ + var manifest = gulp.src('dist/rev-manifest.json'); + + return gulp.src(['staging/**/*.html', 'staging/**/*.xml', 'staging/**/*.css']) + .pipe(revReplace({manifest: manifest, replaceInExtensions: ['.html', '.xml', '.css']})) + .pipe(gulp.dest('dist')); +}); + +gulp.task('copy-other-files', function(){ + return gulp.src(['public/sitemap.xml', 'public/tags/**/*.xml']) + .pipe(gulp.dest('dist')); +}); + +gulp.task('copy-icons', function(){ + return gulp.src(['staging/favicon*', 'staging/apple-icon*', 'staging/android-icon*', 'staging/ms-icon*', 'manifest.json', 'browserconfig.xml']) + .pipe(gulp.dest('dist')); +}); + +gulp.task('default', function (callback) { + runSequence('useref', 'copy-images', 'process-files', 'update-files', 'copy-other-files', 'copy-icons', + callback + ) +}) diff --git a/layouts/partials/footer_scripts.html b/layouts/partials/footer_scripts.html index 65cb60db3..ff6916dd9 100644 --- a/layouts/partials/footer_scripts.html +++ b/layouts/partials/footer_scripts.html @@ -1,5 +1,7 @@ +{{ "" | safeHTML }} +{{ "" | safeHTML }} diff --git a/layouts/partials/head_includes.html b/layouts/partials/head_includes.html index 08e5511e5..cbf888d69 100644 --- a/layouts/partials/head_includes.html +++ b/layouts/partials/head_includes.html @@ -1,8 +1,10 @@ - - - +{{ "" | safeHTML }} + + + - + +{{ "" | safeHTML }} diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 000000000..9557c254b --- /dev/null +++ b/netlify.toml @@ -0,0 +1,16 @@ +# Global settings applied to the whole site. +[build] + publish = "exampleSite/public/" + command = "bin/netlify.sh" + +# Production context: All deploys to the main +# repository branch will inherit these settings. +[context.production] + command = "bin/netlify-production.sh" + publish = "exampleSite/dist" + +# Deploy Preview context: All Deploy Previews +# will inherit these settings. +[context.deploy-preview] + publish = "exampleSite/public/" + command = "bin/netlify.sh" diff --git a/package.json b/package.json new file mode 100644 index 000000000..51f586cd9 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "devopsdays-examplesite", + "version": "1.0.0", + "description": "This is the example site for DevOpsDays.org", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Matt Stratton", + "license": "MIT", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-cache": "^0.4.5", + "gulp-changed": "^1.3.2", + "gulp-clean-css": "^2.3.2", + "gulp-htmlmin": "^3.0.0", + "gulp-if": "^2.0.2", + "gulp-imagemin": "^3.1.1", + "gulp-rev": "^7.1.2", + "gulp-rev-replace": "^0.4.3", + "gulp-uglify": "^2.0.0", + "gulp-useref": "^3.1.2", + "run-sequence": "^1.2.2" + } +}