diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c417db1..afd8760 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,12 +11,12 @@ before_script: sandbox: script: + - hugo --quiet - node tools/pdf.js - hugo -F - node tools/minify.js - firebase use default - firebase deploy --token "$FIREBASE_SANDBOX_TOKEN" - - ls public/schedule/ artifacts: paths: - public @@ -27,6 +27,7 @@ prod: variables: HUGO_ENV: production script: + - hugo --quiet - node tools/pdf.js - hugo --baseURL https://2019.devfesttoulouse.fr/ - node tools/minify.js diff --git a/themes/devfest-theme-hugo b/themes/devfest-theme-hugo index defa281..6a8d7c8 160000 --- a/themes/devfest-theme-hugo +++ b/themes/devfest-theme-hugo @@ -1 +1 @@ -Subproject commit defa281b712030049b17f57741fba6ebc2984e83 +Subproject commit 6a8d7c8af563c5fa71e36e31fe6425ce85702f36 diff --git a/tools/minify.js b/tools/minify.js index 7201299..3268bfe 100644 --- a/tools/minify.js +++ b/tools/minify.js @@ -1,20 +1,27 @@ const {readFileSync, writeFileSync} = require('fs'); const {sync: glob} = require('glob'); const {minify} = require('html-minifier'); -const {Logger} = require('plop-logger'); +const {Logger, LogLevel} = require('plop-logger'); const {colorEmojiConfig} = require('plop-logger/lib/extra/colorEmojiConfig'); Logger.config = colorEmojiConfig; const logger = Logger.getLogger('minifier'); +logger.level = LogLevel.All; -glob(`public/**/*.html`) - .forEach(file => { - const html = readFileSync(file, 'utf8'); - const minified = minify(html, {}); - const gain = html.length - minified.length; - if (gain > 0) { - const percent = (gain / html.length) * 100; - logger.info(file, () => ['gain', percent.toFixed(2), '%'].join(" ")); - writeFileSync(file, minified, {flag: 'w'}); - } - }); +const htmlFiles = `public/**/*.html`; +logger.info('Compress HTML files', htmlFiles); + +const totalGain = glob(htmlFiles) + .map(file => { + const html = readFileSync(file, 'utf8'); + const minified = minify(html, {}); + const gain = html.length - minified.length; + if (gain > 0) { + const percent = (gain / html.length) * 100; + logger.debug(file, () => ['gain', percent.toFixed(2), '%'].join(" ")); + writeFileSync(file, minified, {flag: 'w'}); + } + return gain; + }).reduce((acc, elt) => acc + elt, 0); + +logger.info('Total gain', '' + totalGain);