Skip to content
This repository was archived by the owner on Sep 15, 2020. It is now read-only.

Commit 97e7871

Browse files
committed
Switch to grunt-sri-hash.
Due to cheerio which grunt-sri-hash is using, we need to make `doctype` lowercase again ourselves hence the grunt-doctype addition.
1 parent 787d823 commit 97e7871

File tree

5 files changed

+128
-71
lines changed

5 files changed

+128
-71
lines changed

Gruntfile.js

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,30 @@ module.exports = function(grunt) {
194194
]
195195
},
196196

197+
sri_hash: {
198+
dist: {
199+
options: {
200+
algorithm: 'sha384',
201+
assetsDir: '<%= dirs.dest %>'
202+
},
203+
expand: true,
204+
cwd: '<%= dirs.dest %>',
205+
dest: '<%= dirs.dest %>',
206+
src: ['**/*.html', '**/*.php']
207+
}
208+
},
209+
210+
// This is because grunt-sri-hash is using cheerio which
211+
// makes `doctype` uppercase...
212+
doctype: {
213+
dist: {
214+
expand: true,
215+
cwd: '<%= dirs.dest %>',
216+
dest: '<%= dirs.dest %>',
217+
src: ['**/*.html', '**/*.php']
218+
}
219+
},
220+
197221
connect: {
198222
options: {
199223
hostname: 'localhost',
@@ -280,58 +304,6 @@ module.exports = function(grunt) {
280304
require('load-grunt-tasks')(grunt, { scope: 'dependencies' });
281305
require('time-grunt')(grunt);
282306

283-
grunt.registerTask('generate-sri', 'Generate SRI hashes for our assets.', function () {
284-
285-
function sriDigest(filePattern) {
286-
var sriToolbox = require('sri-toolbox');
287-
var matches = grunt.file.expand({ filter: 'isFile' }, filePattern);
288-
var match = matches[0]; // `grunt.file.expand` returns an array
289-
var matchCount = matches.length;
290-
var integrity = '';
291-
292-
if (matchCount === 0) {
293-
grunt.fail.fatal('Generating SRI failed; didn\'t find any matches!');
294-
} else if (matchCount > 1) {
295-
// shouldn't really happen since we clean the '_site' directory
296-
grunt.fail.fatal('Generating SRI failed; Found more than one matches!');
297-
}
298-
299-
try {
300-
integrity = sriToolbox.generate({ algorithms: ['sha384'] }, grunt.file.read(match));
301-
} catch (err) {
302-
grunt.log.error(err);
303-
grunt.fail.fatal('Generating SRI hash failed.');
304-
}
305-
306-
grunt.log.ok('Generated SRI hash for ' + match.cyan + '.');
307-
return integrity;
308-
309-
}
310-
311-
var packCssIntegrity = sriDigest('_site/assets/css/pack.*.css');
312-
var packJsIntegrity = sriDigest('_site/assets/js/pack.*.js');
313-
var jqueryPackJsIntegrity = sriDigest('_site/assets/js/jquery-pack.*.js');
314-
315-
grunt.config('includereplace', {
316-
dist: {
317-
options: {
318-
globals: {
319-
packCssIntegrity: packCssIntegrity,
320-
packJsIntegrity: packJsIntegrity,
321-
jqueryPackJsIntegrity: jqueryPackJsIntegrity
322-
}
323-
},
324-
files: [{
325-
src: ['**/*.html', '**/*.php'],
326-
dest: '<%= dirs.dest %>/',
327-
expand: true,
328-
cwd: '<%= dirs.dest %>/'
329-
}]
330-
}
331-
});
332-
333-
});
334-
335307
var buildTasks = [
336308
'clean',
337309
'jekyll',
@@ -343,8 +315,8 @@ module.exports = function(grunt) {
343315
'uglify',
344316
'filerev',
345317
'usemin',
346-
'generate-sri',
347-
'includereplace',
318+
'sri_hash',
319+
'doctype',
348320
'htmlmin'
349321
];
350322

@@ -366,8 +338,7 @@ module.exports = function(grunt) {
366338
'postcss',
367339
'filerev',
368340
'usemin',
369-
'generate-sri',
370-
'includereplace'
341+
'sri_hash'
371342
]);
372343

373344
grunt.registerTask('server', [

package-lock.json

Lines changed: 96 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
"grunt-contrib-htmlmin": "^3.0.0",
3131
"grunt-contrib-uglify": "^4.0.0",
3232
"grunt-contrib-watch": "^1.1.0",
33+
"grunt-doctype": "^2.0.1",
3334
"grunt-eslint": "^21.0.0",
3435
"grunt-filerev": "^2.3.1",
3536
"grunt-html": "^9.3.0",
36-
"grunt-include-replace": "^5.0.0",
3737
"grunt-jekyll": "^0.4.7",
3838
"grunt-postcss": "^0.9.0",
3939
"grunt-purgecss": "^1.0.0",
40+
"grunt-sri-hash": "^1.1.1",
4041
"grunt-usemin": "^3.1.1",
4142
"load-grunt-tasks": "^4.0.0",
4243
"postcss-combine-duplicated-selectors": "^6.0.4",
43-
"sri-toolbox": "^0.2.0",
4444
"time-grunt": "^1.4.0"
4545
},
4646
"engines": {

source/_includes/footer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ <h4><span class="fa fa-exclamation-circle" aria-hidden="true"></span> Warning!</
8080
</div>
8181
</noscript>
8282

83-
<script src="/assets/js/pack.js" integrity="@@packJsIntegrity" crossorigin="anonymous" async></script>
84-
<script src="/assets/js/jquery-pack.js" integrity="@@jqueryPackJsIntegrity" crossorigin="anonymous" async></script>
83+
<script src="/assets/js/pack.js" async></script>
84+
<script src="/assets/js/jquery-pack.js" async></script>
8585

8686
</body>
8787
</html>

source/_includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<meta name="description" content="{{ meta_description }}">
1212
<meta name="generator" content="Jekyll v{{ jekyll.version }}">
1313

14-
<link rel="stylesheet" href="/assets/css/pack.css" integrity="@@packCssIntegrity" crossorigin="anonymous">
14+
<link rel="stylesheet" href="/assets/css/pack.css">
1515

1616
<link rel="apple-touch-icon" href="/assets/img/favicons/apple-touch-icon.png" sizes="180x180">
1717
<link rel="icon" href="/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png">

0 commit comments

Comments
 (0)