From 508e407faf18860fcfa628c454904790e889c01c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 11 Jan 2016 02:28:43 +0000 Subject: [PATCH] Minify HTML --- gulpfile.js | 6 ++++++ package.json | 1 + publish.sh | 3 +++ source/_layouts/default.html.twig | 10 +--------- source/blog.html | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d655398b..b2c620fa 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -81,6 +81,12 @@ gulp.task('clean', function () { del.sync('./output_*/assets/fonts/*'); }); +gulp.task('minify-prod-html', function() { + gulp.src('output_prod/**/*.html') + .pipe(plugins.htmlmin({ collapseWhitespace: true })) + .pipe(gulp.dest('output_prod')); +}); + gulp.task('build', ['clean', 'styles', 'scripts', 'fonts']); gulp.task('default', ['build', 'watch']); diff --git a/package.json b/package.json index 26126d87..60e360da 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "del": "^2.2.0", "gulp": "^3.9.0", "gulp-concat": "^2.6.0", + "gulp-htmlmin": "^1.3.0", "gulp-if": "^2.0.0", "gulp-imagemin": "^2.4.0", "gulp-livereload": "^3.8.1", diff --git a/publish.sh b/publish.sh index 4c56f71a..4ba50c83 100755 --- a/publish.sh +++ b/publish.sh @@ -11,5 +11,8 @@ gulp build --production ./vendor/bin/sculpin generate --env=${ENV} --clean --no-interaction if [ $? -ne 0 ]; then echo "Could not generate the site"; exit 1; fi +# Minify HTML. +gulp minify-prod-html + rsync -av --delete output_${ENV}/ ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH} if [ $? -ne 0 ]; then echo "Could not publish the site"; exit 1; fi diff --git a/source/_layouts/default.html.twig b/source/_layouts/default.html.twig index c375a6e4..f33622d8 100644 --- a/source/_layouts/default.html.twig +++ b/source/_layouts/default.html.twig @@ -99,15 +99,7 @@ {% endif %} {% if site.google_analytics_tracking_id %} - + {% endif %} diff --git a/source/blog.html b/source/blog.html index 086f49dd..926dbd35 100644 --- a/source/blog.html +++ b/source/blog.html @@ -19,7 +19,7 @@ use: {% if post.blocks.excerpt %} {{ post.blocks.excerpt|raw }} {% else %} -

{{ post.blocks.content|raw|split(' ')|slice(0,50)|join(' ')|replace({ 'h2':'h3' })|raw }} …

+

{{ post.blocks.content|raw|striptags|split(' ')|slice(0,50)|join(' ')|replace({ 'h2':'h3' }) }} …

{% endif %} Read more →