From 9978cd58a572ee91f01b6eecbae0f805c915f20a Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 4 Jun 2019 17:08:10 +0300 Subject: [PATCH 1/3] Inline badge SVGs. Sort of hackish but if the partials have an SVG extension they are not included. Also, remove the comment from the SVG files, otherwise it results in invalid HTML. --- index.js | 1 + public/badge/badge.css | 2 +- public/badge/fail.svg | 7 ------- public/badge/pass.svg | 7 ------- templates/index.html | 4 ++-- templates/partials/fail.html | 3 +++ templates/partials/pass.html | 3 +++ 7 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 public/badge/fail.svg delete mode 100644 public/badge/pass.svg create mode 100644 templates/partials/fail.html create mode 100644 templates/partials/pass.html diff --git a/index.js b/index.js index 105c2b67..4b0037d8 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,7 @@ const REFERRER_HEADER = 'no-referrer, strict-origin-when-cross-origin'; engines: { html: handlebars }, + partialsPath: path.join(__dirname, 'templates/partials'), path: path.join(__dirname, 'templates') }); diff --git a/public/badge/badge.css b/public/badge/badge.css index 054b66a0..8bc5a4e7 100644 --- a/public/badge/badge.css +++ b/public/badge/badge.css @@ -18,7 +18,7 @@ overflow: hidden; } -.sri-test *[data-sri-status] img { +.sri-test *[data-sri-status] svg { display: block; margin-left: 16px; } diff --git a/public/badge/fail.svg b/public/badge/fail.svg deleted file mode 100644 index 34a48b8c..00000000 --- a/public/badge/fail.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/public/badge/pass.svg b/public/badge/pass.svg deleted file mode 100644 index 586ac2ea..00000000 --- a/public/badge/pass.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/templates/index.html b/templates/index.html index 1f5372b5..eb58935f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -79,11 +79,11 @@

Test your browser

- Pass Badge + {{> "pass"}}

Your browser supports SRI

- Fail Badge + {{> "fail"}}

Your browser does not support SRI

diff --git a/templates/partials/fail.html b/templates/partials/fail.html new file mode 100644 index 00000000..d798eb4b --- /dev/null +++ b/templates/partials/fail.html @@ -0,0 +1,3 @@ + + + diff --git a/templates/partials/pass.html b/templates/partials/pass.html new file mode 100644 index 00000000..5bdadb75 --- /dev/null +++ b/templates/partials/pass.html @@ -0,0 +1,3 @@ + + + From 6e7b34283c38daf55a5f144936eb19a98aa9f843 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 4 Jun 2019 17:14:12 +0300 Subject: [PATCH 2/3] Switch to handlebars-partial-file. --- index.js | 13 +++++++++---- package-lock.json | 8 ++++++++ package.json | 1 + .../partials/fail.html => public/badge/fail.svg | 1 + .../partials/pass.html => public/badge/pass.svg | 1 + templates/index.html | 4 ++-- 6 files changed, 22 insertions(+), 6 deletions(-) rename templates/partials/fail.html => public/badge/fail.svg (94%) rename templates/partials/pass.html => public/badge/pass.svg (91%) diff --git a/index.js b/index.js index 4b0037d8..81bdb731 100644 --- a/index.js +++ b/index.js @@ -8,14 +8,20 @@ const path = require('path'); const Hapi = require('@hapi/hapi'); const vision = require('@hapi/vision'); const inert = require('@hapi/inert'); - const handlebarsHelperSRI = require('handlebars-helper-sri'); +const handlebarsPartialFile = require('handlebars-partial-file'); +const generate = require('./lib/generate'); +const generateElement = require('./lib/generateElement'); + let handlebars = require('handlebars'); handlebars = handlebarsHelperSRI.register(handlebars); -const generate = require('./lib/generate'); -const generateElement = require('./lib/generateElement'); +const hbsPartialFile = handlebarsPartialFile({ + referenceDir: path.join(__dirname, 'public') +}); + +hbsPartialFile.registerDirectory('badge', 'svg'); // eslint-disable-next-line quotes const CSP_HEADER = "default-src 'none'; base-uri 'none'; form-action 'self'; frame-src 'self'; frame-ancestors 'self'; img-src 'self'; manifest-src 'self'; style-src 'self'"; @@ -43,7 +49,6 @@ const REFERRER_HEADER = 'no-referrer, strict-origin-when-cross-origin'; engines: { html: handlebars }, - partialsPath: path.join(__dirname, 'templates/partials'), path: path.join(__dirname, 'templates') }); diff --git a/package-lock.json b/package-lock.json index bfac35a1..fa56aaee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3209,6 +3209,14 @@ "subresource": "0.0.0" } }, + "handlebars-partial-file": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/handlebars-partial-file/-/handlebars-partial-file-1.0.0.tgz", + "integrity": "sha1-sBjWf3pt0scaIHYTMD4ptWWTKBQ=", + "requires": { + "handlebars": "^4.0.11" + } + }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", diff --git a/package.json b/package.json index 8cd48d1a..a4920dc1 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "cross-env": "^6.0.3", "handlebars": "^4.4.2", "handlebars-helper-sri": "0.0.0", + "handlebars-partial-file": "^1.0.0", "node-fetch": "^2.6.0", "sri-toolbox": "^0.2.0" }, diff --git a/templates/partials/fail.html b/public/badge/fail.svg similarity index 94% rename from templates/partials/fail.html rename to public/badge/fail.svg index d798eb4b..829db1a5 100644 --- a/templates/partials/fail.html +++ b/public/badge/fail.svg @@ -1,3 +1,4 @@ + Fail diff --git a/templates/partials/pass.html b/public/badge/pass.svg similarity index 91% rename from templates/partials/pass.html rename to public/badge/pass.svg index 5bdadb75..6a053503 100644 --- a/templates/partials/pass.html +++ b/public/badge/pass.svg @@ -1,3 +1,4 @@ + Pass diff --git a/templates/index.html b/templates/index.html index eb58935f..110c41cc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -79,11 +79,11 @@

Test your browser

- {{> "pass"}} + {{> pass}}

Your browser supports SRI

- {{> "fail"}} + {{> fail}}

Your browser does not support SRI

From c2489d631c38e9bae9210cc7d0a75c15dd66efa2 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 10 Oct 2019 15:37:00 +0300 Subject: [PATCH 3/3] Bump handlebars from 4.4.2 to 4.4.3 (#328) Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.4.2 to 4.4.3. - [Release notes](https://github.com/wycats/handlebars.js/releases) - [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md) - [Commits](https://github.com/wycats/handlebars.js/compare/v4.4.2...v4.4.3) Signed-off-by: dependabot-preview[bot] --- package-lock.json | 20 ++++++++++---------- package.json | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index fa56aaee..cd4749bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1393,9 +1393,9 @@ } }, "commander": { - "version": "2.20.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz", - "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==", + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", + "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", "optional": true }, "commondir": { @@ -3191,9 +3191,9 @@ "dev": true }, "handlebars": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.2.tgz", - "integrity": "sha512-cIv17+GhL8pHHnRJzGu2wwcthL5sb8uDKBHvZ2Dtu5s1YNt0ljbzKbamnc+gr69y7bzwQiBdr5+hOpRd5pnOdg==", + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.3.tgz", + "integrity": "sha512-B0W4A2U1ww3q7VVthTKfh+epHx+q4mCt6iK+zEAzbMBpWQAwxCeKxEGpj/1oQTpzPXDNSOG7hmG14TsISH50yw==", "requires": { "neo-async": "^2.6.0", "optimist": "^0.6.1", @@ -6567,12 +6567,12 @@ } }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.1.tgz", + "integrity": "sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ==", "optional": true, "requires": { - "commander": "~2.20.0", + "commander": "2.20.0", "source-map": "~0.6.1" } }, diff --git a/package.json b/package.json index a4920dc1..47bbf626 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@hapi/inert": "^5.2.2", "@hapi/vision": "^5.5.4", "cross-env": "^6.0.3", - "handlebars": "^4.4.2", + "handlebars": "^4.4.3", "handlebars-helper-sri": "0.0.0", "handlebars-partial-file": "^1.0.0", "node-fetch": "^2.6.0",