diff --git a/Gruntfile.js b/Gruntfile.js index b7e89251..f7efbfd3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -194,6 +194,30 @@ module.exports = function(grunt) { ] }, + sri_hash: { + dist: { + options: { + algorithm: 'sha384', + assetsDir: '<%= dirs.dest %>' + }, + expand: true, + cwd: '<%= dirs.dest %>', + dest: '<%= dirs.dest %>', + src: ['**/*.html', '**/*.php'] + } + }, + + // This is because grunt-sri-hash is using cheerio which + // makes `doctype` uppercase... + doctype: { + dist: { + expand: true, + cwd: '<%= dirs.dest %>', + dest: '<%= dirs.dest %>', + src: ['**/*.html', '**/*.php'] + } + }, + connect: { options: { hostname: 'localhost', @@ -280,58 +304,6 @@ module.exports = function(grunt) { require('load-grunt-tasks')(grunt, { scope: 'dependencies' }); require('time-grunt')(grunt); - grunt.registerTask('generate-sri', 'Generate SRI hashes for our assets.', function () { - - function sriDigest(filePattern) { - var sriToolbox = require('sri-toolbox'); - var matches = grunt.file.expand({ filter: 'isFile' }, filePattern); - var match = matches[0]; // `grunt.file.expand` returns an array - var matchCount = matches.length; - var integrity = ''; - - if (matchCount === 0) { - grunt.fail.fatal('Generating SRI failed; didn\'t find any matches!'); - } else if (matchCount > 1) { - // shouldn't really happen since we clean the '_site' directory - grunt.fail.fatal('Generating SRI failed; Found more than one matches!'); - } - - try { - integrity = sriToolbox.generate({ algorithms: ['sha384'] }, grunt.file.read(match)); - } catch (err) { - grunt.log.error(err); - grunt.fail.fatal('Generating SRI hash failed.'); - } - - grunt.log.ok('Generated SRI hash for ' + match.cyan + '.'); - return integrity; - - } - - var packCssIntegrity = sriDigest('_site/assets/css/pack.*.css'); - var packJsIntegrity = sriDigest('_site/assets/js/pack.*.js'); - var jqueryPackJsIntegrity = sriDigest('_site/assets/js/jquery-pack.*.js'); - - grunt.config('includereplace', { - dist: { - options: { - globals: { - packCssIntegrity: packCssIntegrity, - packJsIntegrity: packJsIntegrity, - jqueryPackJsIntegrity: jqueryPackJsIntegrity - } - }, - files: [{ - src: ['**/*.html', '**/*.php'], - dest: '<%= dirs.dest %>/', - expand: true, - cwd: '<%= dirs.dest %>/' - }] - } - }); - - }); - var buildTasks = [ 'clean', 'jekyll', @@ -343,8 +315,8 @@ module.exports = function(grunt) { 'uglify', 'filerev', 'usemin', - 'generate-sri', - 'includereplace', + 'sri_hash', + 'doctype', 'htmlmin' ]; @@ -366,8 +338,7 @@ module.exports = function(grunt) { 'postcss', 'filerev', 'usemin', - 'generate-sri', - 'includereplace' + 'sri_hash' ]); grunt.registerTask('server', [ diff --git a/package-lock.json b/package-lock.json index ba6f24fa..eb7572e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2685,6 +2685,11 @@ } } }, + "grunt-doctype": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/grunt-doctype/-/grunt-doctype-2.0.1.tgz", + "integrity": "sha512-sXW5D2xxbiXaGlql3q50vM6k6yWYE+58Rh8CYb+V6vBiTgHRqKgYXX4c7z4OjbQttKJ++KkOzX89PnlWZeGPtA==" + }, "grunt-eslint": { "version": "21.0.0", "resolved": "https://registry.npmjs.org/grunt-eslint/-/grunt-eslint-21.0.0.tgz", @@ -2748,11 +2753,6 @@ } } }, - "grunt-include-replace": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/grunt-include-replace/-/grunt-include-replace-5.0.0.tgz", - "integrity": "sha1-CVORY7FoGmxWCRBpVFBOHBpm4Hc=" - }, "grunt-jekyll": { "version": "0.4.7", "resolved": "https://registry.npmjs.org/grunt-jekyll/-/grunt-jekyll-0.4.7.tgz", @@ -2830,6 +2830,84 @@ "purgecss": "^1.0.0" } }, + "grunt-sri-hash": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/grunt-sri-hash/-/grunt-sri-hash-1.1.1.tgz", + "integrity": "sha512-Zh6nQPQyEBycJnPkcfJKMjpQ+Xgm9WR0z30f4wOHw7go1LzQmcrA0RNUBNrqyRlRpykh4ZV8ErMcpjLy+jPKOA==", + "requires": { + "jsdom": "^12.0.0" + }, + "dependencies": { + "acorn": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.2.tgz", + "integrity": "sha512-GXmKIvbrN3TV7aVqAzVFaMW8F8wzVX7voEBRO3bDA64+EX37YSayggRJP5Xig6HYHBkWKpFg9W5gg6orklubhg==" + }, + "jsdom": { + "version": "12.2.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-12.2.0.tgz", + "integrity": "sha512-QPOggIJ8fquWPLaYYMoh+zqUmdphDtu1ju0QGTitZT1Yd8I5qenPpXM1etzUegu3MjVp8XPzgZxdn8Yj7e40ig==", + "requires": { + "abab": "^2.0.0", + "acorn": "^6.0.2", + "acorn-globals": "^4.3.0", + "array-equal": "^1.0.0", + "cssom": "^0.3.4", + "cssstyle": "^1.1.1", + "data-urls": "^1.0.1", + "domexception": "^1.0.1", + "escodegen": "^1.11.0", + "html-encoding-sniffer": "^1.0.2", + "nwsapi": "^2.0.9", + "parse5": "5.1.0", + "pn": "^1.1.0", + "request": "^2.88.0", + "request-promise-native": "^1.0.5", + "saxes": "^3.1.3", + "symbol-tree": "^3.2.2", + "tough-cookie": "^2.4.3", + "w3c-hr-time": "^1.0.1", + "webidl-conversions": "^4.0.2", + "whatwg-encoding": "^1.0.5", + "whatwg-mimetype": "^2.2.0", + "whatwg-url": "^7.0.0", + "ws": "^6.1.0", + "xml-name-validator": "^3.0.0" + } + }, + "parse5": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.0.tgz", + "integrity": "sha512-fxNG2sQjHvlVAYmzBZS9YlDp6PTSSDwa98vkD4QgVDDCAo84z5X1t5XyJQ62ImdLXx5NdIIfihey6xpum9/gRQ==" + }, + "whatwg-encoding": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz", + "integrity": "sha512-b5lim54JOPN9HtzvK9HFXvBma/rnfFeqsic0hSpjtDbVxR3dJKLc+KB4V6GgiGOvl7CY/KNh8rxSo9DKQrnUEw==", + "requires": { + "iconv-lite": "0.4.24" + } + }, + "whatwg-url": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.0.0.tgz", + "integrity": "sha512-37GeVSIJ3kn1JgKyjiYNmSLP1yzbpb29jdmwBSgkD9h40/hyrR/OifpVUndji3tmwGgD8qpw7iQu3RSbCrBpsQ==", + "requires": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + }, + "ws": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.1.0.tgz", + "integrity": "sha512-H3dGVdGvW2H8bnYpIDc3u3LH8Wue3Qh+Zto6aXXFzvESkTVT6rAfKR6tR/+coaUvxs8yHtmNV0uioBF62ZGSTg==", + "requires": { + "async-limiter": "~1.0.0" + } + } + } + }, "grunt-usemin": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/grunt-usemin/-/grunt-usemin-3.1.1.tgz", @@ -4849,6 +4927,14 @@ "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" }, + "saxes": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-3.1.3.tgz", + "integrity": "sha512-Nc5DXc5A+m3rUDtkS+vHlBWKT7mCKjJPyia7f8YMW773hsXVv2wEHQZGE0zs4+5PLwz9U5Sbl/94Cnd9vHV7Bg==", + "requires": { + "xmlchars": "^1.3.1" + } + }, "semver": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", @@ -5173,11 +5259,6 @@ "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.1.tgz", "integrity": "sha1-Nr54Mgr+WAH2zqPueLblqrlA6gw=" }, - "sri-toolbox": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/sri-toolbox/-/sri-toolbox-0.2.0.tgz", - "integrity": "sha1-p/6lw/3lXmdc8cjAbz67XCk1g14=" - }, "sshpk": { "version": "1.15.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.15.1.tgz", @@ -6045,6 +6126,11 @@ "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", "integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==" }, + "xmlchars": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-1.3.1.tgz", + "integrity": "sha512-tGkGJkN8XqCod7OT+EvGYK5Z4SfDQGD30zAa58OcnAa0RRWgzUEK72tkXhsX1FZd+rgnhRxFtmO+ihkp8LHSkw==" + }, "xregexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.0.0.tgz", diff --git a/package.json b/package.json index c69da464..82fdcafc 100644 --- a/package.json +++ b/package.json @@ -30,17 +30,17 @@ "grunt-contrib-htmlmin": "^3.0.0", "grunt-contrib-uglify": "^4.0.0", "grunt-contrib-watch": "^1.1.0", + "grunt-doctype": "^2.0.1", "grunt-eslint": "^21.0.0", "grunt-filerev": "^2.3.1", "grunt-html": "^9.3.0", - "grunt-include-replace": "^5.0.0", "grunt-jekyll": "^0.4.7", "grunt-postcss": "^0.9.0", "grunt-purgecss": "^1.0.0", + "grunt-sri-hash": "^1.1.1", "grunt-usemin": "^3.1.1", "load-grunt-tasks": "^4.0.0", "postcss-combine-duplicated-selectors": "^6.0.4", - "sri-toolbox": "^0.2.0", "time-grunt": "^1.4.0" }, "engines": { diff --git a/source/_includes/footer.html b/source/_includes/footer.html index 5f8dccfd..23570522 100644 --- a/source/_includes/footer.html +++ b/source/_includes/footer.html @@ -80,8 +80,8 @@