From 7a36f12cb84b4a27ab733e9c384991cea6c4e844 Mon Sep 17 00:00:00 2001 From: Heydon Pickering Date: Tue, 11 Jul 2017 16:24:52 +0100 Subject: [PATCH] service worker with sw-precache --- .../patterns/coding/writing-inline-demos.md | 12 + docs/css/styles.css | 7 +- docs/index.html | 7 +- docs/js/service-worker-registration.js | 62 ++++ docs/patterns/coding/code-blocks/index.html | 5 +- .../coding/codepen-embedding/index.html | 5 +- .../patterns/coding/color-palettes/index.html | 5 +- docs/patterns/coding/index.html | 5 +- docs/patterns/coding/tested/index.html | 5 +- .../coding/writing-inline-demos/index.html | 26 +- docs/patterns/index.html | 5 +- docs/patterns/installation/index.html | 5 +- docs/patterns/library-setup/index.html | 5 +- docs/patterns/serving/index.html | 5 +- .../writing/expandable-sections/index.html | 5 +- .../writing/including-images/index.html | 5 +- docs/patterns/writing/index.html | 5 +- .../writing/library-structure/index.html | 5 +- .../writing/markdown-and-metadata/index.html | 5 +- .../writing/notes-and-warnings/index.html | 5 +- docs/patterns/writing/references/index.html | 5 +- docs/service-worker.js | 268 ++++++++++++++++++ package.json | 5 +- themes/infusion/layouts/_default/baseof.html | 7 +- themes/infusion/static/css/styles.css | 7 +- .../static/js/service-worker-registration.js | 62 ++++ 26 files changed, 490 insertions(+), 53 deletions(-) create mode 100644 docs/js/service-worker-registration.js create mode 100644 docs/service-worker.js create mode 100644 themes/infusion/static/js/service-worker-registration.js diff --git a/content/patterns/coding/writing-inline-demos.md b/content/patterns/coding/writing-inline-demos.md index 2818d13..67345de 100644 --- a/content/patterns/coding/writing-inline-demos.md +++ b/content/patterns/coding/writing-inline-demos.md @@ -76,3 +76,15 @@ toggle.addEventListener('click', (e) => { {{% note %}} Firefox does not currently support Shadow DOM and **Infusion** does not include a polyfill. Firefox will output an error message. These demos function correctly in Chrome, Safari, and Opera. {{% /note %}} + +## Captioned demos + +It's possible to give your demo a caption using an accessible `
` and `
` structure. All _you_ need to do is supply a `caption` attribute. For example: + +{{}} +{{<demo caption="A basic button element">}} +<!-- demo code here --> +{{</demo>}} +{{}} + +Along with the standard `figure` shortcodes (described in {{% pattern "Including images" %}}), demo figures are numbered automatically according to their order in the page. You can use markdown syntax in the caption text value. diff --git a/docs/css/styles.css b/docs/css/styles.css index c8e284c..05bb883 100644 --- a/docs/css/styles.css +++ b/docs/css/styles.css @@ -471,7 +471,7 @@ main { figcaption::before { counter-increment: fig; - content: 'Figure ' counter(fig) ':'; + content: 'Figure ' counter(fig) ':\0020'; font-weight: bold; } @@ -708,10 +708,7 @@ h1 svg { [id^="demo-"] { all: initial; -} - -[id^="demo-"] * { - all: initial; + display: block; } @media (max-width: 45em) { diff --git a/docs/index.html b/docs/index.html index a6eec44..5c918b9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -247,13 +247,16 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
+ + + diff --git a/docs/js/service-worker-registration.js b/docs/js/service-worker-registration.js new file mode 100644 index 0000000..bbcc757 --- /dev/null +++ b/docs/js/service-worker-registration.js @@ -0,0 +1,62 @@ +/** + * Copyright 2015 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* eslint-env browser */ +'use strict'; + +if ('serviceWorker' in navigator) { + // Delay registration until after the page has loaded, to ensure that our + // precaching requests don't degrade the first visit experience. + // See https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/registration + window.addEventListener('load', function() { + // Your service-worker.js *must* be located at the top-level directory relative to your site. + // It won't be able to control pages unless it's located at the same level or higher than them. + // *Don't* register service worker file in, e.g., a scripts/ sub-directory! + // See https://github.com/slightlyoff/ServiceWorker/issues/468 + navigator.serviceWorker.register('service-worker.js').then(function(reg) { + // updatefound is fired if service-worker.js changes. + reg.onupdatefound = function() { + // The updatefound event implies that reg.installing is set; see + // https://w3c.github.io/ServiceWorker/#service-worker-registration-updatefound-event + var installingWorker = reg.installing; + + installingWorker.onstatechange = function() { + switch (installingWorker.state) { + case 'installed': + if (navigator.serviceWorker.controller) { + // At this point, the old content will have been purged and the fresh content will + // have been added to the cache. + // It's the perfect time to display a "New content is available; please refresh." + // message in the page's interface. + console.log('New or updated content is available.'); + } else { + // At this point, everything has been precached. + // It's the perfect time to display a "Content is cached for offline use." message. + console.log('Content is now available offline!'); + } + break; + + case 'redundant': + console.error('The installing service worker became redundant.'); + break; + } + }; + }; + }).catch(function(e) { + console.error('Error during service worker registration:', e); + }); + }); +} diff --git a/docs/patterns/coding/code-blocks/index.html b/docs/patterns/coding/code-blocks/index.html index 77d1bc2..b2aa406 100644 --- a/docs/patterns/coding/code-blocks/index.html +++ b/docs/patterns/coding/code-blocks/index.html @@ -278,8 +278,8 @@ toggle.addEventListener('click', (e) => {
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -288,5 +288,6 @@ toggle.addEventListener('click', (e) => { + diff --git a/docs/patterns/coding/codepen-embedding/index.html b/docs/patterns/coding/codepen-embedding/index.html index 4351956..604d60e 100644 --- a/docs/patterns/coding/codepen-embedding/index.html +++ b/docs/patterns/coding/codepen-embedding/index.html @@ -263,8 +263,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -273,5 +273,6 @@ + diff --git a/docs/patterns/coding/color-palettes/index.html b/docs/patterns/coding/color-palettes/index.html index 62435f0..8c13930 100644 --- a/docs/patterns/coding/color-palettes/index.html +++ b/docs/patterns/coding/color-palettes/index.html @@ -271,8 +271,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -281,5 +281,6 @@ + diff --git a/docs/patterns/coding/index.html b/docs/patterns/coding/index.html index 83329e5..abc7e87 100644 --- a/docs/patterns/coding/index.html +++ b/docs/patterns/coding/index.html @@ -284,8 +284,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -294,5 +294,6 @@ + diff --git a/docs/patterns/coding/tested/index.html b/docs/patterns/coding/tested/index.html index ca7429c..a90e349 100644 --- a/docs/patterns/coding/tested/index.html +++ b/docs/patterns/coding/tested/index.html @@ -306,8 +306,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -316,5 +316,6 @@ + diff --git a/docs/patterns/coding/writing-inline-demos/index.html b/docs/patterns/coding/writing-inline-demos/index.html index 96a0a78..812228f 100644 --- a/docs/patterns/coding/writing-inline-demos/index.html +++ b/docs/patterns/coding/writing-inline-demos/index.html @@ -227,7 +227,9 @@

Writing inline demos

-

There are some issues with CodePen embedding, like them not working offline. They also come with CodePen branding, which will clash with the pattern you’re trying to illustrate.

+ + +

There are some issues with CodePen embedding, like them not working offline. They also come with CodePen branding, which will clash with the pattern you’re trying to illustrate.

Infusion offers another option: a special demo shortcode that allows you to write HTML, CSS, and JavaScript directly into the markdown file. The outputted demo is encapsulated using Shadow DOM, so you don’t have to worry about broken styles and global JS.

@@ -269,7 +271,7 @@ toggle.addEventListener('click', (e) => {

Here’s a live demo of… the demo:

-

+

@@ -322,7 +324,7 @@ toggle.addEventListener('click', (e) => { })();
-

+

+

Captioned demos

+ +

It’s possible to give your demo a caption using an accessible <figure> and <figcaption> structure. All you need to do is supply a caption attribute. For example:

+ +

+{{<demo caption="A basic button element">}}
+<!-- demo code here -->
+{{</demo>}}
+
+ + +

Along with the standard figure shortcodes (described in Including images), demo figures are numbered automatically according to their order in the page. You can use markdown syntax in the caption text value.

+
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -348,5 +363,6 @@ toggle.addEventListener('click', (e) => { + diff --git a/docs/patterns/index.html b/docs/patterns/index.html index 549db65..926dfd7 100644 --- a/docs/patterns/index.html +++ b/docs/patterns/index.html @@ -264,8 +264,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -274,5 +274,6 @@ + diff --git a/docs/patterns/installation/index.html b/docs/patterns/installation/index.html index fec7c2f..5186095 100644 --- a/docs/patterns/installation/index.html +++ b/docs/patterns/installation/index.html @@ -295,8 +295,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -305,5 +305,6 @@ + diff --git a/docs/patterns/library-setup/index.html b/docs/patterns/library-setup/index.html index cdc732b..c779076 100644 --- a/docs/patterns/library-setup/index.html +++ b/docs/patterns/library-setup/index.html @@ -291,8 +291,8 @@ theme = "infusion"
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -301,5 +301,6 @@ theme = "infusion" + diff --git a/docs/patterns/serving/index.html b/docs/patterns/serving/index.html index d2531b1..4a57ca7 100644 --- a/docs/patterns/serving/index.html +++ b/docs/patterns/serving/index.html @@ -256,8 +256,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -266,5 +266,6 @@ + diff --git a/docs/patterns/writing/expandable-sections/index.html b/docs/patterns/writing/expandable-sections/index.html index 28c81c2..364330b 100644 --- a/docs/patterns/writing/expandable-sections/index.html +++ b/docs/patterns/writing/expandable-sections/index.html @@ -331,8 +331,8 @@ Here is some markdown including [a link](https://twitter.com/heydonworks). Donec
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -341,5 +341,6 @@ Here is some markdown including [a link](https://twitter.com/heydonworks). Donec + diff --git a/docs/patterns/writing/including-images/index.html b/docs/patterns/writing/including-images/index.html index a15c9da..a805de5 100644 --- a/docs/patterns/writing/including-images/index.html +++ b/docs/patterns/writing/including-images/index.html @@ -292,8 +292,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -302,5 +302,6 @@ + diff --git a/docs/patterns/writing/index.html b/docs/patterns/writing/index.html index b685c44..39063d4 100644 --- a/docs/patterns/writing/index.html +++ b/docs/patterns/writing/index.html @@ -294,8 +294,8 @@
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -304,5 +304,6 @@ + diff --git a/docs/patterns/writing/library-structure/index.html b/docs/patterns/writing/library-structure/index.html index d1995ac..52ccc27 100644 --- a/docs/patterns/writing/library-structure/index.html +++ b/docs/patterns/writing/library-structure/index.html @@ -284,8 +284,8 @@ title = "Popups"
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -294,5 +294,6 @@ title = "Popups" + diff --git a/docs/patterns/writing/markdown-and-metadata/index.html b/docs/patterns/writing/markdown-and-metadata/index.html index 6ee95ad..a6b1049 100644 --- a/docs/patterns/writing/markdown-and-metadata/index.html +++ b/docs/patterns/writing/markdown-and-metadata/index.html @@ -279,8 +279,8 @@ weight = 1
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -289,5 +289,6 @@ weight = 1 + diff --git a/docs/patterns/writing/notes-and-warnings/index.html b/docs/patterns/writing/notes-and-warnings/index.html index b97d4de..e22f934 100644 --- a/docs/patterns/writing/notes-and-warnings/index.html +++ b/docs/patterns/writing/notes-and-warnings/index.html @@ -282,8 +282,8 @@ This is a warning! It's about something the reader should be careful to do or to
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -292,5 +292,6 @@ This is a warning! It's about something the reader should be careful to do or to + diff --git a/docs/patterns/writing/references/index.html b/docs/patterns/writing/references/index.html index b3ed97c..cfe3b88 100644 --- a/docs/patterns/writing/references/index.html +++ b/docs/patterns/writing/references/index.html @@ -649,8 +649,8 @@ I can reference the {{% pattern "Notes & warnings" %}} pattern here.
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -659,5 +659,6 @@ I can reference the {{% pattern "Notes & warnings" %}} pattern here. + diff --git a/docs/service-worker.js b/docs/service-worker.js new file mode 100644 index 0000000..07db54f --- /dev/null +++ b/docs/service-worker.js @@ -0,0 +1,268 @@ +/** + * Copyright 2016 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +// DO NOT EDIT THIS GENERATED OUTPUT DIRECTLY! +// This file should be overwritten as part of your build process. +// If you need to extend the behavior of the generated service worker, the best approach is to write +// additional code and include it using the importScripts option: +// https://github.com/GoogleChrome/sw-precache#importscripts-arraystring +// +// Alternatively, it's possible to make changes to the underlying template file and then use that as the +// new base for generating output, via the templateFilePath option: +// https://github.com/GoogleChrome/sw-precache#templatefilepath-string +// +// If you go that route, make sure that whenever you update your sw-precache dependency, you reconcile any +// changes made to this original template file with your modified copy. + +// This generated service worker JavaScript will precache your site's resources. +// The code needs to be saved in a .js file at the top-level of your site, and registered +// from your pages in order to be used. See +// https://github.com/googlechrome/sw-precache/blob/master/demo/app/js/service-worker-registration.js +// for an example of how you can register this script and handle various service worker events. + +/* eslint-env worker, serviceworker */ +/* eslint-disable indent, no-unused-vars, no-multiple-empty-lines, max-nested-callbacks, space-before-function-paren, quotes, comma-spacing */ +'use strict'; + +var precacheConfig = [["browserconfig.xml","67c3113b1574fecc6015d56d774e1d38"],["categories/index.xml","0ac1d02cfbcad2fcc8c13b2c54715338"],["css/images/icon-tick.svg","35d4d4728ea80d254508b2bca4109d70"],["css/images/stripe.svg","fa3f32a026b6a1bb04ee98d963432e15"],["css/prism.css","004029c8c70ed2bbaa5d9debcf14f8c7"],["css/styles.css","a73d74c5722727195079094376dd2a2f"],["images/android-icon-144x144.png","43e1f47f182b13d0dee15f510213e928"],["images/android-icon-192x192.png","4c07782e52e0ab714074e6d3d69dc3ec"],["images/android-icon-36x36.png","3b2cd8c925a66bf84c89b68bb30e5f62"],["images/android-icon-48x48.png","45dc386eea1d8a46216a8b6de9b156c6"],["images/android-icon-72x72.png","b04c64637efed2b04fa900ddfcbfe75d"],["images/android-icon-96x96.png","bd9c126a4d6baf7ce442122ce0e89e11"],["images/apple-icon-114x114.png","72e127d6f01dfcd2ba2340141babc536"],["images/apple-icon-120x120.png","bc7cd9e36869e66aaca78412207bf723"],["images/apple-icon-144x144.png","43e1f47f182b13d0dee15f510213e928"],["images/apple-icon-152x152.png","567c64205576865b5e5d06c849613ca2"],["images/apple-icon-180x180.png","6b8734c446bf02ab50be598b4c01ec9c"],["images/apple-icon-57x57.png","f8c586086752c78870820b6190d6b42b"],["images/apple-icon-60x60.png","6e88df111e506bcd5501bed4ff10542e"],["images/apple-icon-72x72.png","b04c64637efed2b04fa900ddfcbfe75d"],["images/apple-icon-76x76.png","d8666e0ac256f39f8c5c628486bd71fb"],["images/apple-icon-precomposed.png","725f6cec25256abb1db10385e0724400"],["images/apple-icon.png","725f6cec25256abb1db10385e0724400"],["images/browser-Chrome-Android.svg","3100b2a9c5f0e34982c717fc2aa46d73"],["images/browser-Chrome.svg","fa39b4be6727525330e928f582fbe80a"],["images/browser-Edge.svg","9e8265ab8f6a701587a4271dd3aa6a73"],["images/browser-Firefox-Android.svg","452df7b9e83c70a07e8e03b4e8dab9c4"],["images/browser-Firefox.svg","d3093eda664be3d0cc6d791e1386420f"],["images/browser-IE.svg","13e192cf2b3fe17e7049a49b7d085caa"],["images/browser-Opera.svg","95d65630c9f7deef6a3098af8f5baf9f"],["images/browser-Safari-iOS.svg","f729e629ec998ec40d313495d7257741"],["images/browser-Safari.svg","523ee9491f5a937b8975f4d23aa77f62"],["images/favicon-16x16.png","7a99c20d6c00babddd26d03607b8721d"],["images/favicon-32x32.png","129881474a1bf130027bff7a1e89febd"],["images/favicon-96x96.png","bd9c126a4d6baf7ce442122ce0e89e11"],["images/favicon.ico","81c46feedbfcc6c6dc9495e4fd5adfad"],["images/icon-info.svg","53a6c555ce41f818556c71ab0dfc533b"],["images/icon-tag.svg","f067bbbc072941b2a0335679300bfc6c"],["images/icon-warning.svg","2a4322abbee9aed694fadb50e98a1f61"],["images/logo.png","0134d77c2c6b01eabb425990bab7ce9a"],["images/ms-icon-144x144.png","43e1f47f182b13d0dee15f510213e928"],["images/ms-icon-150x150.png","e73370837ab9060772a18d62aaacd0f0"],["images/ms-icon-310x310.png","8a7143516b929702e3309bb537a99c5c"],["images/ms-icon-70x70.png","d7c6e7368733d53b5f979546d5aa4fe9"],["images/open_in_desktop.png","e899d6679b011aa7b0e783683d90d99b"],["images/serve_from_docs.png","15ae9eac3737a21593ebe00a9312bf9e"],["images/steve_faulkner.jpg","b90382f2b505ce6f6b1e08657637395e"],["index.html","a06059b63a3af942d2526ae2212b2a4e"],["index.xml","74d031827892612b4be9cd599fbdb36f"],["js/dom-scripts.js","9956fb927a1097a05d07f48cdfbb9140"],["js/prism.js","0c1fb8d3a69ee7c91dbf0f361ded7763"],["js/service-worker-registration.js","d60f01dc1393cbaaf4f7435339074d5e"],["js/webcomponents.js","c5f6fe397db634cde89f66c2f1bc2f62"],["manifest.json","4e77b7f1253442852a2f185822f1b4d8"],["patterns/coding/code-blocks/index.html","b7d673ff150a07aba0c41f79b6b40ec8"],["patterns/coding/codepen-embedding/index.html","49ae008aa7d14f36609930d59cd88914"],["patterns/coding/color-palettes/index.html","8a317238fd5d6afae8c1629bbdac8340"],["patterns/coding/index.html","0eee8672ab7c5ecda70aacd9cef28311"],["patterns/coding/index.xml","e05792f5d471e69af658fcfe0d949e05"],["patterns/coding/tested/index.html","4d080e7127e26dac41aaf6ef091f6df9"],["patterns/coding/writing-inline-demos/index.html","174f4eae3c99156cb85bd84a4fe9bdd6"],["patterns/index.html","6936d20cff158276ccf36721e77a9abe"],["patterns/index.xml","b2fe2e8940440bfcc3f152e9c43f4a28"],["patterns/installation/index.html","b1fef8d4bdb27f746e122ab905fec14f"],["patterns/library-setup/index.html","3c5d4c609a77fa785443693729bb60ee"],["patterns/serving/index.html","06d968a280d941340f90311933315fc9"],["patterns/writing/expandable-sections/index.html","630c97adbcf044f15a4834a9ead68401"],["patterns/writing/including-images/index.html","9bec078c8544193a18ee24ab9184bedf"],["patterns/writing/index.html","171ccbc1429caae8922a145e8f88be74"],["patterns/writing/index.xml","865db6ba800170f1efc2e8a2413e4b36"],["patterns/writing/library-structure/index.html","8ceb23d88edbddb1f41b02546df145d5"],["patterns/writing/markdown-and-metadata/index.html","033d65521447629f675c0368c782e747"],["patterns/writing/notes-and-warnings/index.html","4257a2bd4f56e1f65c3dfde2d654be3f"],["patterns/writing/references/index.html","ffad6b7b9d4dc7f9a89600313e734f9d"],["sitemap.xml","1797bd7bb5cd23a161415b194580572c"],["tags/index.xml","c49e6e2b318d5ee86534194441e4dc1e"]]; +var cacheName = 'sw-precache-v3-sw-precache-' + (self.registration ? self.registration.scope : ''); + + +var ignoreUrlParametersMatching = [/^utm_/]; + + + +var addDirectoryIndex = function (originalUrl, index) { + var url = new URL(originalUrl); + if (url.pathname.slice(-1) === '/') { + url.pathname += index; + } + return url.toString(); + }; + +var cleanResponse = function (originalResponse) { + // If this is not a redirected response, then we don't have to do anything. + if (!originalResponse.redirected) { + return Promise.resolve(originalResponse); + } + + // Firefox 50 and below doesn't support the Response.body stream, so we may + // need to read the entire body to memory as a Blob. + var bodyPromise = 'body' in originalResponse ? + Promise.resolve(originalResponse.body) : + originalResponse.blob(); + + return bodyPromise.then(function(body) { + // new Response() is happy when passed either a stream or a Blob. + return new Response(body, { + headers: originalResponse.headers, + status: originalResponse.status, + statusText: originalResponse.statusText + }); + }); + }; + +var createCacheKey = function (originalUrl, paramName, paramValue, + dontCacheBustUrlsMatching) { + // Create a new URL object to avoid modifying originalUrl. + var url = new URL(originalUrl); + + // If dontCacheBustUrlsMatching is not set, or if we don't have a match, + // then add in the extra cache-busting URL parameter. + if (!dontCacheBustUrlsMatching || + !(url.pathname.match(dontCacheBustUrlsMatching))) { + url.search += (url.search ? '&' : '') + + encodeURIComponent(paramName) + '=' + encodeURIComponent(paramValue); + } + + return url.toString(); + }; + +var isPathWhitelisted = function (whitelist, absoluteUrlString) { + // If the whitelist is empty, then consider all URLs to be whitelisted. + if (whitelist.length === 0) { + return true; + } + + // Otherwise compare each path regex to the path of the URL passed in. + var path = (new URL(absoluteUrlString)).pathname; + return whitelist.some(function(whitelistedPathRegex) { + return path.match(whitelistedPathRegex); + }); + }; + +var stripIgnoredUrlParameters = function (originalUrl, + ignoreUrlParametersMatching) { + var url = new URL(originalUrl); + // Remove the hash; see https://github.com/GoogleChrome/sw-precache/issues/290 + url.hash = ''; + + url.search = url.search.slice(1) // Exclude initial '?' + .split('&') // Split into an array of 'key=value' strings + .map(function(kv) { + return kv.split('='); // Split each 'key=value' string into a [key, value] array + }) + .filter(function(kv) { + return ignoreUrlParametersMatching.every(function(ignoredRegex) { + return !ignoredRegex.test(kv[0]); // Return true iff the key doesn't match any of the regexes. + }); + }) + .map(function(kv) { + return kv.join('='); // Join each [key, value] array into a 'key=value' string + }) + .join('&'); // Join the array of 'key=value' strings into a string with '&' in between each + + return url.toString(); + }; + + +var hashParamName = '_sw-precache'; +var urlsToCacheKeys = new Map( + precacheConfig.map(function(item) { + var relativeUrl = item[0]; + var hash = item[1]; + var absoluteUrl = new URL(relativeUrl, self.location); + var cacheKey = createCacheKey(absoluteUrl, hashParamName, hash, false); + return [absoluteUrl.toString(), cacheKey]; + }) +); + +function setOfCachedUrls(cache) { + return cache.keys().then(function(requests) { + return requests.map(function(request) { + return request.url; + }); + }).then(function(urls) { + return new Set(urls); + }); +} + +self.addEventListener('install', function(event) { + event.waitUntil( + caches.open(cacheName).then(function(cache) { + return setOfCachedUrls(cache).then(function(cachedUrls) { + return Promise.all( + Array.from(urlsToCacheKeys.values()).map(function(cacheKey) { + // If we don't have a key matching url in the cache already, add it. + if (!cachedUrls.has(cacheKey)) { + var request = new Request(cacheKey, {credentials: 'same-origin'}); + return fetch(request).then(function(response) { + // Bail out of installation unless we get back a 200 OK for + // every request. + if (!response.ok) { + throw new Error('Request for ' + cacheKey + ' returned a ' + + 'response with status ' + response.status); + } + + return cleanResponse(response).then(function(responseToCache) { + return cache.put(cacheKey, responseToCache); + }); + }); + } + }) + ); + }); + }).then(function() { + + // Force the SW to transition from installing -> active state + return self.skipWaiting(); + + }) + ); +}); + +self.addEventListener('activate', function(event) { + var setOfExpectedUrls = new Set(urlsToCacheKeys.values()); + + event.waitUntil( + caches.open(cacheName).then(function(cache) { + return cache.keys().then(function(existingRequests) { + return Promise.all( + existingRequests.map(function(existingRequest) { + if (!setOfExpectedUrls.has(existingRequest.url)) { + return cache.delete(existingRequest); + } + }) + ); + }); + }).then(function() { + + return self.clients.claim(); + + }) + ); +}); + + +self.addEventListener('fetch', function(event) { + if (event.request.method === 'GET') { + // Should we call event.respondWith() inside this fetch event handler? + // This needs to be determined synchronously, which will give other fetch + // handlers a chance to handle the request if need be. + var shouldRespond; + + // First, remove all the ignored parameters and hash fragment, and see if we + // have that URL in our cache. If so, great! shouldRespond will be true. + var url = stripIgnoredUrlParameters(event.request.url, ignoreUrlParametersMatching); + shouldRespond = urlsToCacheKeys.has(url); + + // If shouldRespond is false, check again, this time with 'index.html' + // (or whatever the directoryIndex option is set to) at the end. + var directoryIndex = 'index.html'; + if (!shouldRespond && directoryIndex) { + url = addDirectoryIndex(url, directoryIndex); + shouldRespond = urlsToCacheKeys.has(url); + } + + // If shouldRespond is still false, check to see if this is a navigation + // request, and if so, whether the URL matches navigateFallbackWhitelist. + var navigateFallback = ''; + if (!shouldRespond && + navigateFallback && + (event.request.mode === 'navigate') && + isPathWhitelisted([], event.request.url)) { + url = new URL(navigateFallback, self.location).toString(); + shouldRespond = urlsToCacheKeys.has(url); + } + + // If shouldRespond was set to true at any point, then call + // event.respondWith(), using the appropriate cache key. + if (shouldRespond) { + event.respondWith( + caches.open(cacheName).then(function(cache) { + return cache.match(urlsToCacheKeys.get(url)).then(function(response) { + if (response) { + return response; + } + throw Error('The cached response that was expected is missing.'); + }); + }).catch(function(e) { + // Fall back to just fetch()ing the request if some unexpected error + // prevented the cached response from being valid. + console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e); + return fetch(event.request); + }) + ); + } + } +}); + + + + + + + diff --git a/package.json b/package.json index bbc5d68..2e9f98f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "serve": "hugo server", "clean": "rm -rf content && mkdir content && mkdir content/patterns && hugo new patterns/pattern.md && hugo new _index.md", - "build": "rm -rfv docs/* && hugo && git add -A" + "build": "rm -rfv docs/* && hugo && sw-precache --root=docs && git add -A" }, "pre-commit": [ "build" @@ -23,6 +23,7 @@ }, "homepage": "https://github.com/Heydon/infusion#readme", "devDependencies": { - "pre-commit": "^1.2.2" + "pre-commit": "^1.2.2", + "sw-precache": "^5.2.0" } } diff --git a/themes/infusion/layouts/_default/baseof.html b/themes/infusion/layouts/_default/baseof.html index 2ae73b4..13d920c 100644 --- a/themes/infusion/layouts/_default/baseof.html +++ b/themes/infusion/layouts/_default/baseof.html @@ -82,8 +82,8 @@ {{ block "main" . }} {{ end }}
- Powered by Infusion, a The Paciello Group project
- For general enquiries, contact us on info@paciellogroup.com + Powered by Infusion, a The Paciello Group project
. + For general enquiries, contact us on info@paciellogroup.com.
@@ -92,5 +92,8 @@ {{ end }} + {{ if .Page.IsHome }} + + {{ end }} diff --git a/themes/infusion/static/css/styles.css b/themes/infusion/static/css/styles.css index c8e284c..05bb883 100644 --- a/themes/infusion/static/css/styles.css +++ b/themes/infusion/static/css/styles.css @@ -471,7 +471,7 @@ main { figcaption::before { counter-increment: fig; - content: 'Figure ' counter(fig) ':'; + content: 'Figure ' counter(fig) ':\0020'; font-weight: bold; } @@ -708,10 +708,7 @@ h1 svg { [id^="demo-"] { all: initial; -} - -[id^="demo-"] * { - all: initial; + display: block; } @media (max-width: 45em) { diff --git a/themes/infusion/static/js/service-worker-registration.js b/themes/infusion/static/js/service-worker-registration.js new file mode 100644 index 0000000..bbcc757 --- /dev/null +++ b/themes/infusion/static/js/service-worker-registration.js @@ -0,0 +1,62 @@ +/** + * Copyright 2015 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* eslint-env browser */ +'use strict'; + +if ('serviceWorker' in navigator) { + // Delay registration until after the page has loaded, to ensure that our + // precaching requests don't degrade the first visit experience. + // See https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/registration + window.addEventListener('load', function() { + // Your service-worker.js *must* be located at the top-level directory relative to your site. + // It won't be able to control pages unless it's located at the same level or higher than them. + // *Don't* register service worker file in, e.g., a scripts/ sub-directory! + // See https://github.com/slightlyoff/ServiceWorker/issues/468 + navigator.serviceWorker.register('service-worker.js').then(function(reg) { + // updatefound is fired if service-worker.js changes. + reg.onupdatefound = function() { + // The updatefound event implies that reg.installing is set; see + // https://w3c.github.io/ServiceWorker/#service-worker-registration-updatefound-event + var installingWorker = reg.installing; + + installingWorker.onstatechange = function() { + switch (installingWorker.state) { + case 'installed': + if (navigator.serviceWorker.controller) { + // At this point, the old content will have been purged and the fresh content will + // have been added to the cache. + // It's the perfect time to display a "New content is available; please refresh." + // message in the page's interface. + console.log('New or updated content is available.'); + } else { + // At this point, everything has been precached. + // It's the perfect time to display a "Content is cached for offline use." message. + console.log('Content is now available offline!'); + } + break; + + case 'redundant': + console.error('The installing service worker became redundant.'); + break; + } + }; + }; + }).catch(function(e) { + console.error('Error during service worker registration:', e); + }); + }); +}