-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3717a39
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker | ||
.register('./sw.js') | ||
.then(() => navigator.serviceWorker.ready) | ||
.then(() => { | ||
const $elemList = document.querySelectorAll('[data-blurhash]'); | ||
for (const $elem of $elemList) { | ||
const blurhash = $elem.dataset.blurhash; | ||
$elem.style.backgroundSize = `100% 100%`; | ||
$elem.style.backgroundImage = `url(/.blurhash/${encodeURIComponent(blurhash)})`; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@import url(https://unpkg.com/modern-css-reset@1.4.0/dist/reset.min.css); | ||
@import url(https://unpkg.com/github-markdown-css@4.0.0/github-markdown.css); | ||
@import url(https://unpkg.com/prism-themes@1.9.0/themes/prism-nord.min.css); | ||
|
||
body { | ||
padding: 64px; | ||
max-width: 1024px; | ||
margin: auto; | ||
} | ||
|
||
@media screen and (max-width: 630px) { | ||
body { | ||
padding: 32px; | ||
} | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} | ||
|
||
p img { | ||
display: inline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
importScripts('https://unpkg.com/blurhash-sw@1.0.15/dist/index.js'); | ||
|
||
blurhashSW({ | ||
routeUrl: '/.blurhash/:blurhash', | ||
width: 32, | ||
height: 32, | ||
}); | ||
|
||
self.addEventListener('install', (ev) => { | ||
ev.waitUntil(self.skipWaiting()); | ||
}); | ||
|
||
self.addEventListener('activate', (ev) => { | ||
ev.waitUntil(self.clients.claim()); | ||
}); | ||
|
||
self.addEventListener('fetch', (/** @type {FetchEvent} */ ev) => { | ||
const url = new URL(ev.request.url); | ||
const delay = parseInt(url.searchParams.get('__delay__')); | ||
|
||
if (Number.isFinite(delay)) { | ||
return ev.respondWith( | ||
Promise.all([ | ||
fetch(ev.request, { cache: 'no-store', mode: 'cors', credentials: 'omit' }).then((res) => { | ||
return new Response(res.body, { | ||
headers: new Headers([...res.headers, ['Cache-Control', 'no-store']]), | ||
}); | ||
}), | ||
new Promise((resolve) => setTimeout(resolve, delay)), | ||
]).then(([res]) => res), | ||
); | ||
} else { | ||
return; | ||
} | ||
}); |