diff --git a/Gruntfile.js b/Gruntfile.js index 1e977601c2..229af86eb4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -11,7 +11,6 @@ const fs = require('fs').promises; const pkg = require('./package.json'); module.exports = function(grunt) { - require('time-grunt')(grunt); require('load-grunt-tasks')(grunt); @@ -84,7 +83,7 @@ module.exports = function(grunt) { expand: true, flatten: true, assets: '<%= config.dist %>/assets', - helpers: ['<%= config.src %>/assets/js/translation.js', '<%= config.src %>/assets/js/cache-busting.js'], + helpers: ['helpers/translation.js', 'helpers/cache-busting.js'], layout: '<%= config.src %>/templates/layouts/default.hbs', data: [ '<%= config.src %>/data/**/*.{json,yml}', @@ -98,7 +97,7 @@ module.exports = function(grunt) { i18n: { languages: pkg.languages, templates: [ - "<%= config.src %>/templates/pages/**/*.hbs", + '<%= config.src %>/templates/pages/**/*.hbs', ] }, permalinks: { @@ -106,7 +105,7 @@ module.exports = function(grunt) { patterns: [ { pattern: ':lang', - replacement: function () { + replacement: function() { return this.language.toLowerCase() === 'en' ? '' : this.language; } }, @@ -114,8 +113,8 @@ module.exports = function(grunt) { pattern: ':base', replacement: function () { var check = this.basename.lastIndexOf(this.language.toLowerCase()); - if (check > -1){ - return this.basename.substring(0, check-1); + if (check > -1) { + return this.basename.substring(0, check - 1); } else return this.basename; } } diff --git a/src/assets/js/cache-busting.js b/helpers/cache-busting.js similarity index 70% rename from src/assets/js/cache-busting.js rename to helpers/cache-busting.js index a0a1b5c308..6097bad181 100644 --- a/src/assets/js/cache-busting.js +++ b/helpers/cache-busting.js @@ -7,16 +7,18 @@ module.exports.register = function(Handlebars, options) { const filePath = options.fn(this); const hash = crypto.createHash('sha256'); // creating full path from the root dir to the file - const fullPath = path.join(__dirname, "../../..", "dist", filePath); - let hashCode = ""; + const fullPath = path.join(__dirname, '..', 'dist', filePath); + let hashCode = ''; hash.on('readable', () => { const data = hash.read(); if (data) hashCode = data.toString('hex'); - }) - hash.write(fs.readFileSync(fullPath, function (err) { if (err) return 0 }).toString()); + }); + hash.write(fs.readFileSync(fullPath, { + encoding: 'utf8' + })); hash.end(); // creating a version string from first 6 hash characters - hashCode = "/" + filePath + "?v=" + hashCode.substr(0, 6); + hashCode = '/' + filePath + '?v=' + hashCode.substr(0, 6); return hashCode; }); }; \ No newline at end of file diff --git a/src/assets/js/translation.js b/helpers/translation.js similarity index 100% rename from src/assets/js/translation.js rename to helpers/translation.js