Fix syntax highlighting, static dir and add back header template
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
BIN
static/android-chrome-192x192.png
Normal file
After Width: | Height: | Size: 65 KiB |
BIN
static/android-chrome-512x512.png
Normal file
After Width: | Height: | Size: 296 KiB |
BIN
static/apple-touch-icon.png
Normal file
After Width: | Height: | Size: 39 KiB |
9
static/browserconfig.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<browserconfig>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square150x150logo src="/mstile-150x150.png"/>
|
||||
<TileColor>#1B1D1E</TileColor>
|
||||
</tile>
|
||||
</msapplication>
|
||||
</browserconfig>
|
BIN
static/favicon-16x16.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
static/favicon-32x32.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
static/favicon.ico
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
static/mstile-150x150.png
Normal file
After Width: | Height: | Size: 26 KiB |
214
static/rouge.css
Normal file
|
@ -0,0 +1,214 @@
|
|||
.highlight table td {
|
||||
padding: 5px;
|
||||
}
|
||||
.highlight table pre {
|
||||
margin: 0;
|
||||
}
|
||||
.highlight .gh {
|
||||
color: #999999;
|
||||
}
|
||||
.highlight .sr {
|
||||
color: #f6aa11;
|
||||
}
|
||||
.highlight .go {
|
||||
color: #888888;
|
||||
}
|
||||
.highlight .gp {
|
||||
color: #555555;
|
||||
}
|
||||
.highlight .gs {
|
||||
}
|
||||
.highlight .gu {
|
||||
color: #aaaaaa;
|
||||
}
|
||||
.highlight .nb {
|
||||
color: #f6aa11;
|
||||
}
|
||||
.highlight .cm {
|
||||
color: #75715e;
|
||||
}
|
||||
.highlight .cp {
|
||||
color: #75715e;
|
||||
}
|
||||
.highlight .c1 {
|
||||
color: #75715e;
|
||||
}
|
||||
.highlight .cs {
|
||||
color: #75715e;
|
||||
}
|
||||
.highlight .c,
|
||||
.highlight .ch,
|
||||
.highlight .cd,
|
||||
.highlight .cpf {
|
||||
color: #75715e;
|
||||
}
|
||||
.highlight .err {
|
||||
color: #960050;
|
||||
}
|
||||
.highlight .gr {
|
||||
color: #960050;
|
||||
}
|
||||
.highlight .gt {
|
||||
color: #960050;
|
||||
}
|
||||
.highlight .gd {
|
||||
color: #49483e;
|
||||
}
|
||||
.highlight .gi {
|
||||
color: #49483e;
|
||||
}
|
||||
.highlight .ge {
|
||||
color: #49483e;
|
||||
}
|
||||
.highlight .kc {
|
||||
color: #66d9ef;
|
||||
}
|
||||
.highlight .kd {
|
||||
color: #66d9ef;
|
||||
}
|
||||
.highlight .kr {
|
||||
color: #66d9ef;
|
||||
}
|
||||
.highlight .no {
|
||||
color: #66d9ef;
|
||||
}
|
||||
.highlight .kt {
|
||||
color: #66d9ef;
|
||||
}
|
||||
.highlight .mf {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .mh {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .il {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .mi {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .mo {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .m,
|
||||
.highlight .mb,
|
||||
.highlight .mx {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .sc {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .se {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .ss {
|
||||
color: #ae81ff;
|
||||
}
|
||||
.highlight .sd {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .s2 {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .sb {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .sh {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .si {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .sx {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .s1 {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .s,
|
||||
.highlight .sa,
|
||||
.highlight .dl {
|
||||
color: #e6db74;
|
||||
}
|
||||
.highlight .na {
|
||||
color: #a6e22e;
|
||||
}
|
||||
.highlight .nc {
|
||||
color: #a6e22e;
|
||||
}
|
||||
.highlight .nd {
|
||||
color: #a6e22e;
|
||||
}
|
||||
.highlight .ne {
|
||||
color: #a6e22e;
|
||||
}
|
||||
.highlight .nf,
|
||||
.highlight .fm {
|
||||
color: #a6e22e;
|
||||
}
|
||||
.highlight .vc {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .nn {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .nl {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .ni {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .bp {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .vg {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .vi {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .nv,
|
||||
.highlight .vm {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .w {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .n,
|
||||
.highlight .py,
|
||||
.highlight .nx {
|
||||
color: #ffffff;
|
||||
background-color: #272822;
|
||||
}
|
||||
.highlight .ow {
|
||||
color: #f92672;
|
||||
}
|
||||
.highlight .nt {
|
||||
color: #f92672;
|
||||
}
|
||||
.highlight .k,
|
||||
.highlight .kv {
|
||||
color: #f92672;
|
||||
}
|
||||
.highlight .kn {
|
||||
color: #f92672;
|
||||
}
|
||||
.highlight .kp {
|
||||
color: #f92672;
|
||||
}
|
||||
.highlight .o {
|
||||
color: #f92672;
|
||||
}
|
83
static/safari-pinned-tab.svg
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="1500.000000pt" height="1500.000000pt" viewBox="0 0 1500.000000 1500.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
Created by potrace 1.14, written by Peter Selinger 2001-2017
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,1500.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M7168 14995 c-2 -1 -57 -6 -123 -10 -118 -6 -136 -8 -265 -20 -157
|
||||
-15 -290 -31 -345 -41 -10 -2 -37 -6 -60 -9 -84 -12 -279 -46 -285 -50 -4 -3
|
||||
-25 -7 -46 -10 -52 -7 -92 -14 -134 -25 -19 -5 -50 -12 -69 -15 -19 -3 -37 -8
|
||||
-41 -10 -3 -2 -17 -6 -31 -9 -25 -5 -253 -63 -279 -71 -8 -2 -31 -9 -50 -14
|
||||
-79 -22 -141 -40 -250 -76 -124 -40 -426 -149 -475 -170 -16 -8 -59 -26 -95
|
||||
-41 -36 -14 -83 -34 -105 -44 -22 -10 -78 -35 -125 -56 -190 -83 -519 -255
|
||||
-718 -376 -63 -37 -118 -68 -123 -68 -5 0 -9 -4 -9 -10 0 -5 -4 -10 -9 -10
|
||||
-16 0 -424 -275 -457 -307 -7 -7 -15 -13 -19 -13 -3 0 -38 -26 -79 -57 -40
|
||||
-32 -88 -69 -106 -83 -18 -14 -44 -35 -59 -48 -14 -13 -45 -37 -68 -53 -24
|
||||
-17 -43 -33 -43 -37 0 -4 -11 -14 -24 -22 -36 -23 -186 -155 -330 -292 -39
|
||||
-37 -74 -68 -78 -68 -5 0 -8 -6 -8 -12 0 -7 -16 -24 -35 -38 -19 -14 -35 -31
|
||||
-35 -37 0 -7 -4 -13 -10 -13 -5 0 -31 -23 -57 -51 -26 -28 -70 -75 -98 -104
|
||||
-44 -46 -97 -104 -169 -185 -12 -14 -46 -54 -76 -90 -30 -35 -59 -70 -65 -76
|
||||
-5 -6 -23 -29 -40 -50 -16 -21 -38 -46 -47 -56 -10 -10 -18 -21 -18 -24 0 -4
|
||||
-12 -21 -27 -38 -16 -18 -37 -45 -48 -60 -11 -16 -29 -40 -41 -55 -30 -37
|
||||
-181 -246 -185 -257 -2 -5 -43 -67 -90 -139 -136 -206 -255 -409 -361 -615
|
||||
-22 -41 -43 -79 -49 -84 -5 -6 -9 -18 -9 -28 0 -10 -4 -18 -10 -18 -5 0 -10
|
||||
-4 -10 -9 0 -5 -27 -67 -61 -138 -33 -70 -72 -154 -85 -185 -13 -32 -35 -81
|
||||
-48 -110 -78 -172 -231 -612 -296 -848 -17 -63 -35 -126 -40 -140 -7 -21 -40
|
||||
-148 -55 -216 -15 -66 -84 -416 -89 -449 -4 -22 -11 -65 -16 -95 -5 -30 -12
|
||||
-77 -15 -105 -3 -27 -8 -61 -10 -75 -2 -14 -7 -47 -10 -75 -3 -27 -8 -63 -10
|
||||
-80 -4 -27 -8 -71 -20 -210 -21 -245 -28 -856 -12 -1070 4 -55 10 -127 12
|
||||
-160 3 -33 7 -78 9 -100 3 -22 8 -71 11 -110 6 -63 12 -111 30 -226 3 -20 7
|
||||
-51 9 -70 2 -19 12 -77 21 -129 9 -52 19 -108 22 -125 5 -32 87 -407 102 -465
|
||||
45 -177 131 -471 150 -515 5 -11 25 -68 45 -126 74 -221 204 -536 324 -779 41
|
||||
-85 76 -157 76 -160 1 -3 4 -10 8 -16 4 -5 27 -48 51 -95 24 -46 58 -108 76
|
||||
-137 17 -29 31 -55 31 -58 0 -2 12 -23 27 -47 15 -23 33 -51 39 -62 19 -34 47
|
||||
-81 94 -155 25 -39 50 -79 55 -88 59 -101 384 -549 452 -622 18 -19 33 -38 33
|
||||
-42 0 -4 6 -13 13 -20 7 -7 40 -44 72 -83 32 -38 61 -72 64 -75 4 -3 21 -23
|
||||
40 -45 86 -103 312 -335 490 -505 80 -76 274 -248 303 -268 10 -8 29 -23 41
|
||||
-35 12 -12 38 -33 56 -47 19 -14 50 -39 70 -57 19 -17 39 -29 43 -27 5 3 8 1
|
||||
8 -4 0 -6 42 -41 93 -78 50 -38 97 -72 102 -77 95 -74 478 -327 496 -327 5 0
|
||||
9 -4 9 -10 0 -5 4 -10 9 -10 5 0 39 -18 76 -41 91 -55 137 -81 310 -175 50
|
||||
-27 93 -48 98 -46 4 1 7 -3 7 -9 0 -5 4 -7 10 -4 6 3 10 1 10 -5 0 -6 5 -8 10
|
||||
-5 6 3 10 1 10 -4 0 -6 3 -10 7 -9 5 1 69 -28 143 -64 74 -36 185 -86 245
|
||||
-112 61 -26 119 -51 130 -56 156 -71 779 -281 825 -279 3 0 19 -5 35 -12 17
|
||||
-6 46 -15 65 -20 31 -7 100 -24 140 -35 58 -15 331 -74 368 -79 25 -3 48 -8
|
||||
52 -10 3 -2 26 -6 50 -10 25 -3 52 -8 60 -10 18 -5 342 -51 415 -59 331 -35
|
||||
437 -40 820 -41 368 0 539 8 845 40 48 5 304 42 425 60 36 6 370 72 405 80 53
|
||||
13 228 56 240 60 8 2 51 14 95 25 84 22 386 115 420 129 11 5 56 21 100 36 91
|
||||
31 334 126 413 161 29 13 54 24 57 24 4 0 100 43 244 111 57 27 107 49 112 49
|
||||
5 0 9 4 9 9 0 5 9 11 20 14 32 8 33 9 72 33 21 13 40 24 43 24 4 0 49 24 234
|
||||
127 200 111 646 404 791 520 8 6 44 34 80 62 102 81 128 101 229 185 53 43
|
||||
106 88 118 100 12 11 40 37 62 56 153 132 435 413 581 580 30 35 70 78 88 97
|
||||
17 18 32 36 32 38 0 3 8 13 18 23 28 30 64 73 122 147 30 39 57 72 60 75 12
|
||||
11 220 293 237 320 9 17 21 30 25 30 4 0 8 5 8 10 0 6 18 35 40 65 22 30 40
|
||||
56 40 58 0 3 31 51 68 108 70 106 154 244 184 302 9 17 21 37 25 42 4 6 19 33
|
||||
33 60 14 28 27 52 30 55 3 3 21 37 40 75 19 39 38 72 43 73 4 2 7 12 7 22 0
|
||||
10 3 20 8 22 10 4 138 275 201 428 29 69 57 133 62 143 19 35 154 406 164 447
|
||||
2 8 10 33 19 55 48 123 185 651 222 855 4 19 8 44 11 55 5 23 29 162 38 220 9
|
||||
52 12 70 20 134 4 30 8 61 10 70 5 27 16 115 20 157 2 21 6 66 10 99 24 250
|
||||
30 387 30 735 0 317 -8 509 -30 710 -3 30 -8 78 -11 105 -7 71 -24 205 -30
|
||||
235 -2 14 -7 45 -10 70 -4 38 -65 369 -79 435 -11 49 -71 300 -79 330 -3 11
|
||||
-12 47 -21 80 -8 33 -17 67 -19 75 -11 40 -87 281 -97 306 -6 16 -12 36 -14
|
||||
44 -4 19 -74 214 -109 305 -33 83 -38 96 -65 157 -12 26 -21 50 -21 52 0 6
|
||||
-123 282 -152 341 -62 125 -187 364 -211 402 -15 24 -27 45 -27 49 0 3 -37 67
|
||||
-83 142 -46 76 -90 148 -98 161 -8 14 -18 30 -22 35 -10 13 -128 191 -142 214
|
||||
-5 10 -13 19 -16 22 -3 3 -21 28 -39 55 -19 28 -38 55 -42 60 -11 14 -154 204
|
||||
-176 233 -9 13 -29 38 -44 54 -16 17 -28 33 -28 37 0 3 -18 26 -40 51 -43 48
|
||||
-48 53 -99 115 -52 63 -148 169 -238 263 -46 48 -83 90 -83 95 0 4 -7 7 -15 7
|
||||
-8 0 -15 4 -15 9 0 11 -219 224 -340 331 -34 30 -83 73 -108 95 -24 22 -54 47
|
||||
-66 55 -12 8 -31 24 -43 37 -13 12 -40 34 -60 50 -21 15 -40 31 -43 34 -5 5
|
||||
-203 157 -251 192 -29 21 -158 113 -179 127 -49 34 -277 183 -299 196 -14 8
|
||||
-39 23 -56 33 -234 144 -651 360 -910 470 -93 40 -179 76 -190 81 -72 31 -368
|
||||
139 -398 145 -9 2 -21 6 -26 10 -6 3 -61 21 -123 41 -115 36 -135 41 -177 50
|
||||
-13 3 -32 9 -43 15 -10 5 -18 7 -18 5 0 -3 -12 -1 -27 6 -16 6 -53 16 -83 23
|
||||
-30 7 -82 20 -115 29 -71 18 -180 43 -215 50 -14 3 -36 7 -50 10 -14 3 -41 9
|
||||
-60 12 -19 4 -44 9 -55 11 -35 7 -189 34 -225 38 -19 3 -46 7 -60 10 -14 3
|
||||
-38 7 -55 9 -16 2 -66 9 -110 15 -44 6 -107 13 -140 16 -33 3 -73 8 -90 10
|
||||
-16 2 -68 7 -115 10 -47 3 -107 8 -135 11 -56 6 -802 14 -807 9z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 5.6 KiB |
22
static/site.webmanifest
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/web-manifest-combined.json",
|
||||
"name": "Marko Korhonen",
|
||||
"description": "personal website and portfolio",
|
||||
"short_name": "Marko Korhonen",
|
||||
"start_url": ".",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/android-chrome-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/android-chrome-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"theme_color": "#E38A93",
|
||||
"background_color": "#1B1D1E",
|
||||
"display": "standalone"
|
||||
}
|
242
static/sw.js
Normal file
|
@ -0,0 +1,242 @@
|
|||
const CACHE_VERSION = 1;
|
||||
|
||||
const BASE_CACHE_FILES = ["/site.webmanifest"];
|
||||
|
||||
const OFFLINE_CACHE_FILES = [
|
||||
//"/images/logo.png",
|
||||
];
|
||||
|
||||
const NOT_FOUND_CACHE_FILES = ["/404.html"];
|
||||
|
||||
const OFFLINE_PAGE = "/offline/index.html";
|
||||
const NOT_FOUND_PAGE = "/404.html";
|
||||
|
||||
const CACHE_VERSIONS = {
|
||||
assets: "assets-v" + CACHE_VERSION,
|
||||
content: "content-v" + CACHE_VERSION,
|
||||
offline: "offline-v" + CACHE_VERSION,
|
||||
notFound: "404-v" + CACHE_VERSION,
|
||||
};
|
||||
|
||||
// Define MAX_TTL's in SECONDS for specific file extensions
|
||||
const MAX_TTL = {
|
||||
"/": 3600,
|
||||
html: 3600,
|
||||
json: 86400,
|
||||
js: 86400,
|
||||
css: 86400,
|
||||
};
|
||||
|
||||
const CACHE_BLACKLIST = [
|
||||
(str) => {
|
||||
return !str.startsWith("http://localhost");
|
||||
},
|
||||
];
|
||||
|
||||
const SUPPORTED_METHODS = ["GET"];
|
||||
|
||||
/**
|
||||
* isBlackListed
|
||||
* @param {string} url
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isBlacklisted(url) {
|
||||
return CACHE_BLACKLIST.length > 0
|
||||
? !CACHE_BLACKLIST.filter((rule) => {
|
||||
if (typeof rule === "function") {
|
||||
return !rule(url);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}).length
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* getFileExtension
|
||||
* @param {string} url
|
||||
* @returns {string}
|
||||
*/
|
||||
function getFileExtension(url) {
|
||||
let extension = url.split(".").reverse()[0].split("?")[0];
|
||||
return extension.endsWith("/") ? "/" : extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTTL
|
||||
* @param {string} url
|
||||
*/
|
||||
function getTTL(url) {
|
||||
if (typeof url === "string") {
|
||||
let extension = getFileExtension(url);
|
||||
if (typeof MAX_TTL[extension] === "number") {
|
||||
return MAX_TTL[extension];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* installServiceWorker
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function installServiceWorker() {
|
||||
return Promise.all([
|
||||
caches.open(CACHE_VERSIONS.assets).then((cache) => {
|
||||
return cache.addAll(BASE_CACHE_FILES);
|
||||
}),
|
||||
caches.open(CACHE_VERSIONS.offline).then((cache) => {
|
||||
return cache.addAll(OFFLINE_CACHE_FILES);
|
||||
}),
|
||||
caches.open(CACHE_VERSIONS.notFound).then((cache) => {
|
||||
return cache.addAll(NOT_FOUND_CACHE_FILES);
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* cleanupLegacyCache
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function cleanupLegacyCache() {
|
||||
let currentCaches = Object.keys(CACHE_VERSIONS).map((key) => {
|
||||
return CACHE_VERSIONS[key];
|
||||
});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) => {
|
||||
return (legacyKeys = keys.filter((key) => {
|
||||
return !~currentCaches.indexOf(key);
|
||||
}));
|
||||
})
|
||||
.then((legacy) => {
|
||||
if (legacy.length) {
|
||||
Promise.all(
|
||||
legacy.map((legacyKey) => {
|
||||
return caches.delete(legacyKey);
|
||||
})
|
||||
)
|
||||
.then(() => {
|
||||
resolve();
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(installServiceWorker());
|
||||
});
|
||||
|
||||
// The activate handler takes care of cleaning up old caches.
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
Promise.all([cleanupLegacyCache()]).catch((err) => {
|
||||
event.skipWaiting();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
event.respondWith(
|
||||
caches.open(CACHE_VERSIONS.content).then((cache) => {
|
||||
return cache
|
||||
.match(event.request)
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
let headers = response.headers.entries();
|
||||
let date = null;
|
||||
|
||||
for (let pair of headers) {
|
||||
if (pair[0] === "date") {
|
||||
date = new Date(pair[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (date) {
|
||||
let age = parseInt(
|
||||
(new Date().getTime() - date.getTime()) / 1000
|
||||
);
|
||||
let ttl = getTTL(event.request.url);
|
||||
|
||||
if (ttl && age > ttl) {
|
||||
return new Promise((resolve) => {
|
||||
return fetch(event.request)
|
||||
.then((updatedResponse) => {
|
||||
if (updatedResponse) {
|
||||
cache.put(event.request, updatedResponse.clone());
|
||||
resolve(updatedResponse);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
resolve(response);
|
||||
});
|
||||
}).catch((err) => {
|
||||
return response;
|
||||
});
|
||||
} else {
|
||||
return response;
|
||||
}
|
||||
} else {
|
||||
return response;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
return response;
|
||||
} else {
|
||||
return fetch(event.request)
|
||||
.then((response) => {
|
||||
if (response.status < 400) {
|
||||
if (
|
||||
~SUPPORTED_METHODS.indexOf(event.request.method) &&
|
||||
!isBlacklisted(event.request.url)
|
||||
) {
|
||||
cache.put(event.request, response.clone());
|
||||
}
|
||||
return response;
|
||||
} else {
|
||||
return caches.open(CACHE_VERSIONS.notFound).then((cache) => {
|
||||
return cache.match(NOT_FOUND_PAGE);
|
||||
});
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
return caches
|
||||
.open(CACHE_VERSIONS.offline)
|
||||
.then((offlineCache) => {
|
||||
return offlineCache.match(OFFLINE_PAGE);
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(" Error in fetch handler:", error);
|
||||
throw error;
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|