Update service-worker, show tag

This commit is contained in:
tree 2023-02-05 16:24:34 +01:00
parent f2bf563640
commit 8ac8bced5b
6 changed files with 126 additions and 54 deletions

24
package-lock.json generated
View File

@ -21,6 +21,7 @@
"postcss": "^8.4.21",
"prettier": "^2.8.3",
"prettier-plugin-svelte": "^2.9.0",
"s-offline": "^0.5.1",
"svelte": "^3.55.1",
"svelte-markdown": "^0.2.3",
"tailwindcss": "^3.2.4",
@ -2068,6 +2069,12 @@
"node": ">=0.10.0"
}
},
"node_modules/ping.js": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/ping.js/-/ping.js-0.3.0.tgz",
"integrity": "sha512-qisFwio7j0cwYbOcRL4BlTdxKALcpGPTkpl8ichGASgkrVqfI3sZfQDsP8wETR5rfutXZJLjlJ117aLkRnk2mA==",
"dev": true
},
"node_modules/playwright-core": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz",
@ -2411,6 +2418,23 @@
"queue-microtask": "^1.2.2"
}
},
"node_modules/s-offline": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/s-offline/-/s-offline-0.5.1.tgz",
"integrity": "sha512-CD8OWW87Y2XYbPYqfKgeHF/4yv33A2RFrcD8stgxuL+QI+ydMcMTX6CtA6SRlbhAMKScwhvXCXDxBcwk4hqiPw==",
"dev": true,
"dependencies": {
"ping.js": "^0.3.0"
},
"engines": {
"node": ">=18.0.0",
"npm": ">=9.0.0"
},
"peerDependencies": {
"ping.js": "^0.3.0",
"svelte": "^3.53.1"
}
},
"node_modules/sade": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz",

View File

@ -23,6 +23,7 @@
"postcss": "^8.4.21",
"prettier": "^2.8.3",
"prettier-plugin-svelte": "^2.9.0",
"s-offline": "^0.5.1",
"svelte": "^3.55.1",
"svelte-markdown": "^0.2.3",
"tailwindcss": "^3.2.4",

View File

@ -55,8 +55,9 @@
href="https://github.com/utxo-foundation/prague-blockchain-week/commits/main"
target="_blank"
class="underline hover:no-underline"
>{formatDistanceToNow(new Date(bundle.time))} ago</a
>{formatDistanceToNow(new Date(bundle.__time || null))} ago</a
>
({bundle.__tag})
&nbsp;|&nbsp;
<a
href="https://analytics.gwei.cz/explore.prgblockweek.com"

View File

@ -12,7 +12,8 @@ export const config = {
speakers: {
title: 'Speakers',
model: 'speaker',
img: 'photoUrl'
img: 'photoUrl',
virtual: true
},
'media-partners': {
title: 'Media Partners & Communities',

View File

@ -2,6 +2,11 @@
import { page } from '$app/stores';
import '../app.css';
import DarkModeToggle from '$lib/components/DarkModeToggle.svelte';
import { SOffline } from 's-offline';
const handleNetworkChange = (status) => {
console.log('event details: ', status);
};
$: homepage =
!$page.params.type &&
@ -12,7 +17,31 @@
</script>
<div class="w-full h-full bg-pbw-red">
<div class="flex max-w-7xl items-right justify-end p-2 m-auto h-[50px] -mb-[30px]">
<div
class="flex gap-4 max-w-7xl items-center justify-end p-2 m-auto h-[50px] -mb-[30px] text-white"
>
<div class="my-auto">
{#if typeof window !== 'undefined'}
<SOffline pingUrl="https://x.gwei.cz/" on:detectedCondition={handleNetworkChange}>
<span slot="online" class="flex gap-2 items-center text-pbw-yellow">
<div>
<svg class="w-2" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="50" fill="rgb(255 222 89)" />
</svg>
</div>
<div>Online</div>
</span>
<span slot="offline" class="flex gap-2 items-center text-red-300">
<div>
<svg class="w-2" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="50" fill="rgb(252 165 165)" />
</svg>
</div>
<div>Offline</div>
</span>
</SOffline>
{/if}
</div>
<DarkModeToggle />
</div>

View File

@ -1,61 +1,77 @@
import { build, files, version } from '$service-worker';
import data from '$lib/data.json' assert { type: 'json' };
import { config } from '$lib/pbw.js';
// Create a unique cache name for this deployment
const CACHE = `cache-${version}`;
const images = [];
for (const col in config.collections) {
if (config.collections[col].virtual) continue;
images.push(...data[col].map((x) => x.logo || x.photoUrl || x.photo).filter((e) => e));
}
for (const ev of data.events) {
if (ev.speakers) {
images.push(...ev.speakers.map((s) => s.photoUrl).filter((x) => x));
}
}
const ASSETS = [
...build, // the app itself
...files // everything in `static`
...build, // the app itself
...files, // everything in `static`
...images
];
console.log(ASSETS);
self.addEventListener('install', (event) => {
// Create a new cache and add all files to it
async function addFilesToCache() {
const cache = await caches.open(CACHE);
await cache.addAll(ASSETS);
}
event.waitUntil(addFilesToCache());
// Create a new cache and add all files to it
async function addFilesToCache() {
const cache = await caches.open(CACHE);
await cache.addAll(ASSETS);
}
event.waitUntil(addFilesToCache());
});
self.addEventListener('activate', (event) => {
// Remove previous cached data from disk
async function deleteOldCaches() {
for (const key of await caches.keys()) {
if (key !== CACHE) await caches.delete(key);
}
}
event.waitUntil(deleteOldCaches());
// Remove previous cached data from disk
async function deleteOldCaches() {
for (const key of await caches.keys()) {
if (key !== CACHE) await caches.delete(key);
}
}
event.waitUntil(deleteOldCaches());
});
self.addEventListener('fetch', (event) => {
// ignore POST requests etc
if (event.request.method !== 'GET') return;
async function respond() {
const url = new URL(event.request.url);
const cache = await caches.open(CACHE);
// `build`/`files` can always be served from the cache
if (ASSETS.includes(url.pathname)) {
return cache.match(event.request);
}
// for everything else, try the network first, but
// fall back to the cache if we're offline
try {
const response = await fetch(event.request);
if (response.status === 200) {
cache.put(event.request, response.clone());
}
return response;
} catch {
return cache.match(event.request);
}
}
event.respondWith(respond());
});
// ignore POST requests etc
if (event.request.method !== 'GET') return;
async function respond() {
const url = new URL(event.request.url);
const cache = await caches.open(CACHE);
// `build`/`files` can always be served from the cache
if (ASSETS.includes(url.pathname)) {
return cache.match(event.request);
}
// for everything else, try the network first, but
// fall back to the cache if we're offline
try {
const response = await fetch(event.request);
if (response.status === 200) {
cache.put(event.request, response.clone());
}
return response;
} catch {
return cache.match(event.request);
}
}
event.respondWith(respond());
});