Build Markdown news site with local AI generation and web push
This commit is contained in:
1 parent
ad30f12116
commit
199dec8a1e
26 files changed
+2277
-1
No files matched your search
@@ -0,0 +1,24 @@
|
||||
self.addEventListener('install', () => self.skipWaiting());
|
||||
self.addEventListener('activate', event => event.waitUntil(self.clients.claim()));
|
||||
self.addEventListener('push', event => {
|
||||
let message={};
|
||||
try {message=event.data?.json() || {};} catch { /* Show a generic notification for malformed payloads. */ }
|
||||
let url='/';
|
||||
try {const target=new URL(message.url || '/',self.location.origin);if(target.origin===self.location.origin)url=target.pathname+target.search;} catch {}
|
||||
event.waitUntil(self.registration.showNotification(message.title || 'A new story on TrueNews',{
|
||||
body:message.body || 'Read the latest story.',
|
||||
icon:'/assets/icon-192.png',badge:'/assets/icon-192.png',
|
||||
tag:message.tag || 'truenews-story',data:{url}
|
||||
}));
|
||||
});
|
||||
self.addEventListener('notificationclick', event => {
|
||||
event.notification.close();
|
||||
event.waitUntil((async()=>{
|
||||
const target=new URL(event.notification.data?.url || '/',self.location.origin);
|
||||
if(target.origin!==self.location.origin) return;
|
||||
const windows=await self.clients.matchAll({type:'window',includeUncontrolled:true});
|
||||
const existing=windows.find(client=>new URL(client.url).origin===target.origin);
|
||||
if(existing){await existing.navigate(target.href);await existing.focus();}
|
||||
else await self.clients.openWindow(target.href);
|
||||
})());
|
||||
});
|
||||
Reference in new issue
Block a user