Skip to content

Commit e121452

Browse files
committed
feat (PWA): offline first
1 parent 778a049 commit e121452

File tree

10 files changed

+209
-2
lines changed

10 files changed

+209
-2
lines changed
1.03 KB
Loading

assets/img/favicon-144x144.png

2.25 KB
Loading

assets/img/favicon-32x32.png

594 Bytes
Loading

assets/img/favicon-48x48.png

781 Bytes
Loading

assets/img/favicon-512x512.png

5.46 KB
Loading

assets/img/favicon-96x96.png

1.72 KB
Loading

assets/img/favicon.ico

425 Bytes
Binary file not shown.

index.html

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@
99
<meta name="description" content="A practical generator for creating standardized semantic commits. This convention adds human and machine readable meanings.">
1010
<meta name="keywords" content="commit generator, semantic commit, git commit generator, semantic generator, git semantic commit, semantic git commits, semmantic commit">
1111

12-
<meta name="author" content="Jádson Lucena">
12+
<meta name="author" content="JadsonLucena <jadsonlucena@gmail.com>">
1313

1414
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1515

16-
<link rel="icon" href="./assets/img/favicon.svg">
16+
<link rel="shortcut icon" type="image/x-icon" sizes="16x16" href="./assets/img/favicon.ico">
17+
<link rel="icon" type="image/png" sizes="32x32" href="./assets/img/favicon-32x32.png">
18+
<link rel="icon" type="image/png" sizes="48x48" href="./assets/img/favicon-48x48.png">
19+
<link rel="icon" type="image/png" sizes="96x96" href="./assets/img/favicon-96x96.png">
20+
<link rel="icon" type="image/png" sizes="144x144" href="./assets/img/favicon-144x144.png">
21+
<link rel="icon" type="image/png" sizes="512x512" href="./assets/img/favicon-512x512.png">
22+
<link rel="apple-touch-icon" href="./assets/img/apple-touch-icon-192x192.webp">
23+
24+
<meta name="theme-color" content="#FFFFFF" />
1725

1826
<link rel="stylesheet" href="./assets/style/index.css">
1927

28+
<link rel="manifest" href="./manifest.json" />
29+
2030
</head>
2131
<body>
2232

@@ -306,6 +316,25 @@ <h3>commits must be atomic!</h3>
306316

307317
</footer>
308318

319+
<script>
320+
if ('serviceWorker' in navigator) {
321+
322+
navigator.serviceWorker.register('./sw.js', { scope: './' }).then(e => {
323+
324+
console.log('Service worker register:', e);
325+
326+
}).catch(err => {
327+
328+
console.error(`Service worker register:`, err);
329+
330+
});
331+
332+
} else {
333+
334+
console.error('Service workers are not supported');
335+
336+
}
337+
</script>
309338
<script src="./assets/script/index.js"></script>
310339

311340
</body>

manifest.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "Semantic Commit Generator",
3+
"short_name": "Semantic Commit",
4+
"description": "A practical generator for creating standardized semantic commits. This convention adds human and machine readable meanings.",
5+
"background_color": "#FFFFFF",
6+
"theme_color": "#FFFFFF",
7+
"display": "fullscreen",
8+
"start_url": "./",
9+
"icons": [
10+
{
11+
"src": "./assets/img/favicon.svg",
12+
"sizes": "196x196",
13+
"type": "image/svg+xml",
14+
"purpose": "any maskable"
15+
},
16+
{
17+
"src": "./assets/img/favicon.ico",
18+
"sizes": "16x16",
19+
"type": "image/x-icon"
20+
},
21+
{
22+
"src": "./assets/img/favicon-32x32.png",
23+
"sizes": "32x32",
24+
"type": "image/png"
25+
},
26+
{
27+
"src": "./assets/img/favicon-48x48.png",
28+
"sizes": "48x48",
29+
"type": "image/png"
30+
},
31+
{
32+
"src": "./assets/img/favicon-96x96.png",
33+
"sizes": "96x96",
34+
"type": "image/png"
35+
},
36+
{
37+
"src": "./assets/img/favicon-144x144.png",
38+
"sizes": "144x144",
39+
"type": "image/png"
40+
},
41+
{
42+
"src": "./assets/img/favicon-512x512.png",
43+
"sizes": "512x512",
44+
"type": "image/png"
45+
}
46+
]
47+
}

sw.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
const CACHE_NAME = 'v1.0.0';
2+
3+
const FILES_TO_CACHE = [
4+
'./assets/img/apple-touch-icon-192x192.webp',
5+
'./assets/img/favicon-32x32.png',
6+
'./assets/img/favicon-48x48.png',
7+
'./assets/img/favicon-96x96.png',
8+
'./assets/img/favicon-144x144.png',
9+
'./assets/img/favicon-512x512.png',
10+
'./assets/img/favicon.ico',
11+
'./assets/img/favicon.svg',
12+
'./assets/script/index.js',
13+
'./assets/style/index.css',
14+
'./index.html',
15+
'./'
16+
];
17+
18+
19+
self.addEventListener('install', e => {
20+
21+
// self.skipWaiting();
22+
23+
e.waitUntil(async () => {
24+
25+
const cache = await caches.open(CACHE_NAME);
26+
await cache.addAll(FILES_TO_CACHE);
27+
28+
});
29+
30+
});
31+
32+
self.addEventListener('activate', e => {
33+
34+
// self.clients.claim();
35+
36+
e.waitUntil(async () => {
37+
38+
// Navigation Preload
39+
if (self.registration.navigationPreload) {
40+
41+
await self.registration.navigationPreload.enable();
42+
43+
}
44+
45+
// Deleting old caches
46+
const oldCaches = (await caches.keys()).filter(key => CACHE_NAME != key);
47+
48+
await Promise.all(oldCaches.map(key => caches.delete(key)));
49+
50+
});
51+
52+
});
53+
54+
self.addEventListener('fetch', e => {
55+
56+
if (
57+
!e.request.url.startsWith('http')
58+
|| e.request.method == 'POST'
59+
|| new URL(e.request.url).origin != location.origin
60+
) {
61+
62+
return;
63+
64+
}
65+
66+
e.respondWith(new Promise(async (resolve, reject) => {
67+
68+
try {
69+
70+
const cache = await caches.open(CACHE_NAME).catch(err => {
71+
72+
throw err;
73+
74+
});
75+
76+
let res = await cache.match(e.request).catch(err => {
77+
78+
throw err;
79+
80+
});
81+
82+
if (res) {
83+
84+
return resolve(res);
85+
86+
}
87+
88+
res = await fetch(e.request).catch(err => {
89+
90+
throw err;
91+
92+
});
93+
94+
if (res.ok) {
95+
96+
// be careful not to cache dynamic information
97+
await cache.put(e.request, res.clone()).catch(err => {
98+
99+
throw err;
100+
101+
});
102+
103+
resolve(res);
104+
105+
} else {
106+
107+
reject(new Response(await res.text().catch(err => {
108+
109+
throw err;
110+
111+
}), {
112+
status: res.status,
113+
statusText: res.statusText
114+
}));
115+
116+
}
117+
118+
} catch(err) {
119+
120+
console.error(err);
121+
122+
reject(new Response(err.message, {
123+
status: 500,
124+
statusText: 'Internal Server Error'
125+
}));
126+
127+
}
128+
129+
}));
130+
131+
});

0 commit comments

Comments
 (0)