Skip to content

Commit 14e586d

Browse files
committed
Fixed
Signed-off-by: Someshdiwan <[email protected]>
1 parent 9a5eae7 commit 14e586d

File tree

5 files changed

+140
-38
lines changed

5 files changed

+140
-38
lines changed

site/_includes/nav.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
<li><a href="{{ site.baseurl }}/content">All Contents</a></li>
55
<li><a href="https://github.com/Someshdiwan/JavaEvolution-Learning-Growing-Mastering">GitHub Repo</a></li>
66
</ul>
7-
</nav>
7+
</nav>

site/_layouts/default.html

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
<link rel="apple-touch-icon" sizes="180x180" href="{{ '/assets/apple-touch-icon.png' | relative_url }}" />
1212
<meta name="apple-mobile-web-app-title" content="Java" />
1313

14-
<!-- Manifest (use only one, with correct GitHub Pages path) -->
14+
<!-- Manifest (for GitHub Pages project path) -->
1515
<link rel="manifest" href="/JavaEvolution-Learning-Growing-Mastering/assets/site.webmanifest">
1616
<meta name="theme-color" content="#ffffff">
1717

1818
<title>{{ page.title }}</title>
19-
<link rel="stylesheet" href="{{ "/assets/style.css" | relative_url }}">
19+
<link rel="stylesheet" href="{{ '/assets/style.css' | relative_url }}">
2020

2121
<script>
2222
// Sidebar Toggle Function
@@ -36,13 +36,13 @@
3636
}
3737
}
3838

39-
// Dark Mode Toggle Function (now used inside time container)
39+
// Dark Mode Toggle Function
4040
const toggleDarkMode = () => {
4141
document.body.classList.toggle('dark-mode');
4242
localStorage.setItem('dark-mode', document.body.classList.contains('dark-mode'));
4343
};
4444

45-
// Live Time Update Function with GMT Offset
45+
// Live Time Update Function (with GMT offset)
4646
function updateLiveTime() {
4747
const now = new Date();
4848
let hours = now.getHours();
@@ -52,14 +52,14 @@
5252
hours = hours % 12 || 12;
5353
const timeString = `${hours}:${minutes}:${seconds} ${ampm}`;
5454

55-
// Calculate GMT offset (JS returns minutes behind UTC; we negate to show positive for IST)
55+
// Calculate GMT offset (negate offset from getTimezoneOffset)
5656
const offset = -now.getTimezoneOffset();
5757
const offsetHours = Math.floor(Math.abs(offset) / 60);
5858
const offsetMinutes = Math.abs(offset) % 60;
5959
const offsetSign = offset >= 0 ? '+' : '-';
6060
const offsetString = `GMT${offsetSign}${offsetHours.toString().padStart(2, '0')}:${offsetMinutes.toString().padStart(2, '0')}`;
6161

62-
document.getElementById('live-time').textContent = `Time: ${timeString} ${offsetString}`;
62+
document.getElementById('current-time').textContent = timeString + ' ' + offsetString;
6363
}
6464

6565
// Service Worker Registration
@@ -71,21 +71,58 @@
7171

7272
// Initialization on DOMContentLoaded
7373
window.addEventListener('DOMContentLoaded', () => {
74+
// Restore dark mode preference
7475
if (localStorage.getItem('dark-mode') === 'true') {
7576
document.body.classList.add('dark-mode');
7677
}
78+
// Attach listener for sidebar auto-hide
7779
document.addEventListener('click', hideSidebarIfClickedOutside);
80+
// Start live time updates
7881
updateLiveTime();
7982
setInterval(updateLiveTime, 1000);
8083
});
8184
</script>
85+
86+
<!-- (Optional inline styles for the time container can also reside in your style.css) -->
87+
<style>
88+
/* Time Container (holds the live time and dark mode toggle) */
89+
#time-container {
90+
position: fixed;
91+
top: 1rem;
92+
right: 1rem;
93+
z-index: 1100;
94+
background: rgba(0, 0, 0, 0.6);
95+
color: #00ffff;
96+
border: 1px solid #00ffff;
97+
box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
98+
border-radius: 16px;
99+
padding: 0.6rem 1rem;
100+
display: flex;
101+
align-items: center;
102+
gap: 0.5rem;
103+
font-weight: 600;
104+
font-size: 1.05rem;
105+
}
106+
/* Dark mode overrides for the time container */
107+
body.dark-mode #time-container {
108+
background-color: #333;
109+
color: #eee;
110+
}
111+
@media (max-width: 600px) {
112+
#time-container {
113+
flex-direction: column;
114+
font-size: 0.95rem;
115+
padding: 0.8rem;
116+
}
117+
}
118+
</style>
82119
</head>
83120
<body>
84-
<!-- The combined Time Container with Dark Mode Toggle -->
121+
122+
<!-- Time Container with Dark Mode Toggle Embedded -->
85123
<div id="time-container">
86-
<div id="live-time">Time: Loading...</div>
87-
<!-- Dark mode toggle button placed inside the time container -->
88-
<button onclick="toggleDarkMode()" class="dark-toggle" style="padding: 0.5rem; font-size: 1.2rem;">🌓</button>
124+
<span id="current-time">--:--</span>
125+
<button class="dark-toggle" onclick="toggleDarkMode()">🌙</button>
89126
</div>
90127

91128
<div class="wrapper">
@@ -96,7 +133,7 @@
96133

97134
<!-- Content Area -->
98135
<div class="content">
99-
<!-- Sidebar Toggle Button (if you want manual control; you may remove it later) -->
136+
<!-- Optional: Manual Sidebar Toggle Button -->
100137
<button class="toggle-btn" onclick="toggleSidebar()"></button>
101138
<div class="fade-in">
102139
{{ content }}

site/assets/site.webmanifest

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
{
2+
"name": "Java Mastery",
3+
"short_name": "Java",
4+
"description": "Master Java step by step with visual learning, practical coding, and deep understanding.",
5+
"start_url": "/JavaEvolution-Learning-Growing-Mastering/?source=pwa",
6+
"scope": "/JavaEvolution-Learning-Growing-Mastering/",
7+
"display": "standalone",
8+
"orientation": "portrait",
9+
"theme_color": "#0d1117",
10+
"background_color": "#ffffff",
11+
"icons": [
12+
{
13+
"src": "/JavaEvolution-Learning-Growing-Mastering/assets/web-app-manifest-192x192.png",
14+
"sizes": "192x192",
15+
"type": "image/png",
16+
"purpose": "maskable"
17+
},
18+
{
19+
"src": "/JavaEvolution-Learning-Growing-Mastering/assets/web-app-manifest-512x512.png",
20+
"sizes": "512x512",
21+
"type": "image/png",
22+
"purpose": "maskable"
23+
}
24+
]
25+
}
26+
27+
28+
/*
129
{
230
"name": "Java Mastery",
331
"short_name": "Java",
@@ -21,3 +49,4 @@
2149
"background_color": "#ffffff",
2250
"display": "standalone"
2351
}
52+
*/

site/assets/style.css

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,39 @@ body {
102102
to { opacity: 1; transform: translateY(0); }
103103
}
104104

105-
/* Time Container */
106105
#time-container {
106+
position: fixed;
107+
top: 1rem;
108+
right: 1rem; /* Stick to top-right */
107109
background: rgba(0, 0, 0, 0.6);
108110
color: #00ffff;
109111
border: 1px solid #00ffff;
110112
box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
111113
border-radius: 16px;
112-
padding: 1.2rem;
113-
margin: 1rem auto;
114-
max-width: 320px;
115-
display: flex;
116-
align-items: center;
117-
justify-content: space-between;
114+
padding: 0.6rem 1rem;
118115
font-weight: 600;
119116
font-size: 1.05rem;
117+
display: flex;
118+
align-items: center;
119+
gap: 0.5rem;
120+
z-index: 1100;
120121
}
121122

122123
body.dark-mode #time-container {
123124
background-color: #333;
124125
color: #eee;
125126
}
126127

128+
@media (max-width: 600px) {
129+
#time-container {
130+
flex-direction: column;
131+
align-items: flex-end;
132+
font-size: 0.95rem;
133+
padding: 0.8rem;
134+
}
135+
}
136+
137+
127138
/* Image Row */
128139
.image-row {
129140
display: flex;

site/assets/sw.js

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
const CACHE_NAME = "java-evolution-cache-v2";
1+
const CACHE_NAME = "java-evolution-cache-v3";
22
const urlsToCache = [
33
"/JavaEvolution-Learning-Growing-Mastering/",
44
"/JavaEvolution-Learning-Growing-Mastering/index.html",
55
"/JavaEvolution-Learning-Growing-Mastering/assets/style.css",
66
"/JavaEvolution-Learning-Growing-Mastering/assets/script.js",
77
"/JavaEvolution-Learning-Growing-Mastering/assets/favicon-96x96.png",
88
"/JavaEvolution-Learning-Growing-Mastering/assets/apple-touch-icon.png",
9-
// Add more assets like images, fonts, etc.
9+
"/JavaEvolution-Learning-Growing-Mastering/assets/web-app-manifest-192x192.png",
10+
"/JavaEvolution-Learning-Growing-Mastering/assets/web-app-manifest-512x512.png"
1011
];
1112

12-
// Install event: caching essential files
13-
self.addEventListener("install", (e) => {
14-
e.waitUntil(
15-
caches.open(CACHE_NAME).then((cache) => {
16-
return cache.addAll(urlsToCache);
17-
})
13+
// Install event
14+
self.addEventListener("install", (event) => {
15+
console.log("[Service Worker] Installing and caching static assets");
16+
self.skipWaiting();
17+
event.waitUntil(
18+
caches.open(CACHE_NAME).then((cache) => cache.addAll(urlsToCache))
1819
);
19-
console.log("Service Worker Installed & Cached");
2020
});
2121

22-
// Activate event: cleanup old caches
23-
self.addEventListener("activate", (e) => {
24-
e.waitUntil(
22+
// Activate event
23+
self.addEventListener("activate", (event) => {
24+
console.log("[Service Worker] Activated and cleaning old caches");
25+
event.waitUntil(
2526
caches.keys().then((cacheNames) =>
2627
Promise.all(
2728
cacheNames
@@ -30,14 +31,38 @@ self.addEventListener("activate", (e) => {
3031
)
3132
)
3233
);
33-
console.log("Old caches cleaned up");
34+
self.clients.claim();
3435
});
3536

36-
// Fetch event: serve cached files when offline
37-
self.addEventListener("fetch", (e) => {
38-
e.respondWith(
39-
caches.match(e.request).then((response) => {
40-
return response || fetch(e.request);
37+
// Fetch event
38+
self.addEventListener("fetch", (event) => {
39+
event.respondWith(
40+
caches.match(event.request).then((cachedResponse) => {
41+
// Return from cache if available
42+
if (cachedResponse) {
43+
return cachedResponse;
44+
}
45+
46+
// Otherwise fetch from network
47+
return fetch(event.request)
48+
.then((networkResponse) => {
49+
// Cache new fetched files (only GET and same-origin)
50+
if (
51+
event.request.method === "GET" &&
52+
event.request.url.startsWith(self.location.origin)
53+
) {
54+
return caches.open(CACHE_NAME).then((cache) => {
55+
cache.put(event.request, networkResponse.clone());
56+
return networkResponse;
57+
});
58+
} else {
59+
return networkResponse;
60+
}
61+
})
62+
.catch(() =>
63+
// Offline fallback: serve homepage or a fallback page/image
64+
caches.match("/JavaEvolution-Learning-Growing-Mastering/index.html")
65+
);
4166
})
4267
);
43-
});
68+
});

0 commit comments

Comments
 (0)