Skip to content

Commit ba65f70

Browse files
committed
Updated UI 2.6
Signed-off-by: Someshdiwan <[email protected]>
1 parent 6dfaff0 commit ba65f70

File tree

2 files changed

+57
-222
lines changed

2 files changed

+57
-222
lines changed

site/_layouts/default.html

Lines changed: 0 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,3 @@
1-
<!--
2-
<!DOCTYPE html>
3-
<html lang="en">
4-
<head>
5-
<meta charset="UTF-8" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
8-
&lt;!&ndash; Font Awesome &ndash;&gt;
9-
<link
10-
rel="stylesheet"
11-
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
12-
/>
13-
14-
&lt;!&ndash; Favicons &ndash;&gt;
15-
<link
16-
rel="icon" type="image/png"
17-
href="{{ '/assets/favicon-96x96.png' | relative_url }}"
18-
sizes="96x96"
19-
/>
20-
<link
21-
rel="icon" type="image/svg+xml"
22-
href="{{ '/assets/favicon.svg' | relative_url }}"
23-
/>
24-
<link
25-
rel="shortcut icon"
26-
href="{{ '/assets/favicon.ico' | relative_url }}"
27-
/>
28-
<link
29-
rel="apple-touch-icon"
30-
sizes="180x180"
31-
href="{{ '/assets/apple-touch-icon.png' | relative_url }}"
32-
/>
33-
<meta name="apple-mobile-web-app-title" content="Java" />
34-
<link
35-
rel="manifest"
36-
href="/JavaEvolution-Learning-Growing-Mastering/assets/site.webmanifest"
37-
/>
38-
<meta name="theme-color" content="#ffffff" />
39-
40-
<title>{{ page.title }}</title>
41-
<link
42-
rel="stylesheet"
43-
href="{{ '/assets/style.css' | relative_url }}"
44-
/>
45-
46-
<script>
47-
// Current timezone tracker
48-
let currentZone = 'IST';
49-
50-
// Sidebar toggle
51-
function toggleSidebar() {
52-
document.getElementById('sidebar').classList.toggle('hidden');
53-
}
54-
55-
// Hide sidebar on outside click
56-
function hideSidebarIfClickedOutside(e) {
57-
const sidebar = document.getElementById('sidebar');
58-
const toggleBtn = document.querySelector('.toggle-btn');
59-
if (
60-
!sidebar.classList.contains('hidden') &&
61-
!sidebar.contains(e.target) &&
62-
!toggleBtn.contains(e.target)
63-
) {
64-
sidebar.classList.add('hidden');
65-
}
66-
}
67-
68-
// Dark mode toggle
69-
function toggleDarkMode() {
70-
document.body.classList.toggle('dark-mode');
71-
localStorage.setItem('dark-mode', document.body.classList.contains('dark-mode'));
72-
}
73-
74-
// Timezone toggle
75-
function toggleTimezone() {
76-
currentZone = currentZone === 'IST' ? 'GMT' : 'IST';
77-
document.getElementById('tz-toggle-btn').textContent = currentZone;
78-
updateLiveTime();
79-
}
80-
81-
// Update live time
82-
function updateLiveTime() {
83-
const now = new Date();
84-
let date;
85-
if (currentZone === 'GMT') {
86-
date = new Date(now.getTime() + now.getTimezoneOffset() * 60000);
87-
} else {
88-
const utc = now.getTime() + now.getTimezoneOffset() * 60000;
89-
date = new Date(utc + 5.5 * 3600000);
90-
}
91-
let h = date.getHours();
92-
const m = date.getMinutes().toString().padStart(2,'0');
93-
const s = date.getSeconds().toString().padStart(2,'0');
94-
const ampm = h >= 12 ? 'PM' : 'AM';
95-
h = h % 12 || 12;
96-
document.getElementById('live-time').textContent =
97-
`Time (${currentZone}): ${h}:${m}:${s} ${ampm}`;
98-
}
99-
100-
// On load: init dark mode, listeners, time, SW
101-
window.onload = () => {
102-
if (localStorage.getItem('dark-mode') === 'true') {
103-
document.body.classList.add('dark-mode');
104-
}
105-
document.addEventListener('click', hideSidebarIfClickedOutside);
106-
updateLiveTime();
107-
setInterval(updateLiveTime, 1000);
108-
109-
if ('serviceWorker' in navigator) {
110-
navigator.serviceWorker
111-
.register('/JavaEvolution-Learning-Growing-Mastering/assets/sw.js')
112-
.then(() => console.log('Service Worker Registered'))
113-
.catch(err => console.error('SW registration failed', err));
114-
}
115-
};
116-
117-
</script>
118-
</head>
119-
120-
<body>
121-
&lt;!&ndash; Dark Mode & Timezone Controls &ndash;&gt;
122-
<div id="theme-time-container">
123-
<button class="dark-toggle" onclick="toggleDarkMode()">🌓</button>
124-
<div id="time-zone-wrapper">
125-
<button id="tz-toggle-btn" onclick="toggleTimezone()">IST</button>
126-
<span id="live-time">Time: Loading...</span>
127-
</div>
128-
</div>
129-
130-
&lt;!&ndash; Collapsible Sidebar &ndash;&gt;
131-
<div id="sidebar" class="sidebar">
132-
<a href="{{ site.baseurl }}/" class="sidebar-link active">
133-
<i class="fas fa-home"></i> Home
134-
</a>
135-
136-
<a href="{{ site.baseurl }}/content" class="sidebar-link">
137-
<i class="fas fa-book"></i> All Contents
138-
</a>
139-
140-
<a
141-
href="https://github.com/Someshdiwan/JavaEvolution-Learning-Growing-Mastering"
142-
target="_blank"
143-
class="sidebar-link"
144-
>
145-
<i class="fab fa-github"></i> GitHub Repo
146-
</a>
147-
</div>
148-
149-
&lt;!&ndash; Toggle Button for Mobile &ndash;&gt;
150-
<button class="toggle-btn" onclick="toggleSidebar()">
151-
<i class="fas fa-bars"></i>
152-
</button>
153-
154-
&lt;!&ndash; Main Content &ndash;&gt;
155-
<div class="wrapper">
156-
<div class="content">
157-
<div class="fade-in">
158-
{{ content }}
159-
</div>
160-
</div>
161-
</div>
162-
</body>
163-
</html>
164-
-->
165-
1661
<!DOCTYPE html>
1672
<html lang="en">
1683
<head>

site/assets/sw.js

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ self.addEventListener("fetch", (event) => {
6969
});
7070
*/
7171

72-
73-
const CACHE_NAME = "java-evolution-cache-v5"; // Updated version
72+
const CACHE_NAME = "java-evolution-cache-v6"; // Updated version
7473
const STATIC_ASSETS = [
7574
"/JavaEvolution-Learning-Growing-Mastering/",
7675
"/JavaEvolution-Learning-Growing-Mastering/default.html",
@@ -80,44 +79,29 @@ const STATIC_ASSETS = [
8079
"/JavaEvolution-Learning-Growing-Mastering/assets/favicon.ico",
8180
"/JavaEvolution-Learning-Growing-Mastering/assets/apple-touch-icon.png",
8281
"/JavaEvolution-Learning-Growing-Mastering/assets/site.webmanifest",
83-
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" // Cache CDN resource
82+
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
8483
];
8584

86-
// Simple offline fallback page
87-
const OFFLINE_PAGE = `
88-
<!DOCTYPE html>
89-
<html lang="en">
90-
<head>
91-
<meta charset="UTF-8">
92-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
93-
<title>Offline</title>
94-
<style>
95-
body { font-family: 'Segoe UI', sans-serif; text-align: center; padding: 2rem; background: #f9f9f9; color: #333; }
96-
h1 { font-size: 1.5rem; }
97-
p { font-size: 1rem; }
98-
</style>
99-
</head>
100-
<body>
101-
<h1>You're Offline</h1>
102-
<p>Please check your internet connection and try again.</p>
103-
</body>
104-
</html>
105-
`;
85+
// Debounce function to limit cache updates
86+
function debounce(func, wait) {
87+
let timeout;
88+
return function executedFunction(...args) {
89+
const later = () => {
90+
clearTimeout(timeout);
91+
func(...args);
92+
};
93+
clearTimeout(timeout);
94+
timeout = setTimeout(later, wait);
95+
};
96+
}
10697

10798
// Install event
10899
self.addEventListener("install", (event) => {
109100
console.log("[Service Worker] Installing and caching static assets");
110101
self.skipWaiting();
111102
event.waitUntil(
112103
caches.open(CACHE_NAME).then((cache) => {
113-
// Cache static assets
114-
return cache.addAll(STATIC_ASSETS).then(() => {
115-
// Cache offline page
116-
const offlineResponse = new Response(OFFLINE_PAGE, {
117-
headers: { 'Content-Type': 'text/html' }
118-
});
119-
return cache.put('/offline.html', offlineResponse);
120-
});
104+
return cache.addAll(STATIC_ASSETS);
121105
})
122106
);
123107
});
@@ -146,17 +130,27 @@ self.addEventListener("fetch", (event) => {
146130
event.respondWith(
147131
fetch(request)
148132
.then((networkResponse) => {
149-
// Cache successful response
150-
return caches.open(CACHE_NAME).then((cache) => {
151-
cache.put(request, networkResponse.clone());
152-
return networkResponse;
153-
});
133+
// Cache successful response asynchronously
134+
debounce(() => {
135+
caches.open(CACHE_NAME).then((cache) => {
136+
cache.put(request, networkResponse.clone());
137+
// Limit cache size
138+
cache.keys().then((keys) => {
139+
if (keys.length > 20) {
140+
cache.delete(keys[0]);
141+
}
142+
});
143+
});
144+
}, 100)();
145+
return networkResponse;
154146
})
155147
.catch(() => {
156-
// Serve cached page or offline fallback
157-
return caches.match(request).then((cachedResponse) => {
158-
return cachedResponse || caches.match('/offline.html');
159-
});
148+
// Fallback to cached default.html
149+
return caches.match('/JavaEvolution-Learning-Growing-Mastering/default.html') ||
150+
new Response('Network error: Please check your connection.', {
151+
status: 503,
152+
statusText: 'Service Unavailable'
153+
});
160154
})
161155
);
162156
return;
@@ -167,12 +161,14 @@ self.addEventListener("fetch", (event) => {
167161
caches.match(request).then((cachedResponse) => {
168162
// Return cached response if available
169163
if (cachedResponse) {
170-
// Refresh cache in background
171-
fetch(request).then((networkResponse) => {
172-
caches.open(CACHE_NAME).then((cache) => {
173-
cache.put(request, networkResponse);
174-
});
175-
}).catch(() => {}); // Silent fail
164+
// Background cache refresh
165+
debounce(() => {
166+
fetch(request).then((networkResponse) => {
167+
caches.open(CACHE_NAME).then((cache) => {
168+
cache.put(request, networkResponse);
169+
});
170+
}).catch(() => {}); // Silent fail
171+
}, 100)();
176172
return cachedResponse;
177173
}
178174

@@ -185,25 +181,29 @@ self.addEventListener("fetch", (event) => {
185181
(request.url.startsWith(self.location.origin) ||
186182
request.url.startsWith('https://cdnjs.cloudflare.com'))
187183
) {
188-
return caches.open(CACHE_NAME).then((cache) => {
189-
cache.put(request, networkResponse.clone());
190-
// Limit cache size
191-
cache.keys().then((keys) => {
192-
if (keys.length > 50) {
193-
cache.delete(keys[0]);
194-
}
184+
debounce(() => {
185+
caches.open(CACHE_NAME).then((cache) => {
186+
cache.put(request, networkResponse.clone());
187+
// Limit cache size
188+
cache.keys().then((keys) => {
189+
if (keys.length > 20) {
190+
cache.delete(keys[0]);
191+
}
192+
});
195193
});
196-
return networkResponse;
197-
});
194+
}, 100)();
198195
}
199196
return networkResponse;
200197
})
201198
.catch(() => {
202-
// Fallback for non-HTML resources
199+
// Fallback for Font Awesome
203200
if (request.url.includes('font-awesome')) {
204201
return caches.match('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css');
205202
}
206-
return caches.match('/offline.html');
203+
return new Response('Resource unavailable offline.', {
204+
status: 503,
205+
statusText: 'Service Unavailable'
206+
});
207207
});
208208
})
209209
);

0 commit comments

Comments
 (0)