Skip to content

Commit 6c450bc

Browse files
Amey-Thakurmsatmod
andcommitted
Amey's Arc
Co-authored-by: Mega Satish <mega.modha@gmail.com>
1 parent 2d03e70 commit 6c450bc

5 files changed

Lines changed: 207 additions & 3 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* ==============================================================================
2+
- File: pwa-handler.js (Progressive Web Application Orchestrator)
3+
- Author: Amey Thakur
4+
- Profile: https://github.com/Amey-Thakur
5+
- Repository: https://github.com/Amey-Thakur/Amey-Thakur.github.io
6+
- Release Date: December 16, 2025
7+
- License: MIT License
8+
- ==============================================================================
9+
-
10+
- DESCRIPTION:
11+
- This component manages the client-side lifecycle of the AmeyArc PWA.
12+
- It handles service worker registration, installation event capturing,
13+
- and non-intrusive UI suggestions for device-level integration.
14+
-
15+
- HOW IT WORKS:
16+
- The script validates browser capabilities before registering the site-wide
17+
- service worker. It intercepts the native 'beforeinstallprompt' event to
18+
- deliver a bespoke, high-fidelity installation banner that encourages users
19+
- to add the archive to their home screen without disrupting the focal experience.
20+
-
21+
- TECH STACK:
22+
- - Service Worker API
23+
- - Web App Manifest Specification
24+
- - Client-side UI Orchestration (Vanilla JS)
25+
-
26+
- ============================================================================== */
27+
28+
(function () {
29+
/* Technical Guard: Validating browser capabilities for service worker support. */
30+
if ('serviceWorker' in navigator) {
31+
window.addEventListener('load', () => {
32+
navigator.serviceWorker.register('/sw.js').then((registration) => {
33+
// Registration successful: Site is now offline-capable.
34+
}).catch((err) => {
35+
console.warn('Service worker orchestration failed:', err);
36+
});
37+
});
38+
}
39+
40+
let deferredPrompt;
41+
/* Installation Hook: Capturing the browser's native installation trigger. */
42+
window.addEventListener('beforeinstallprompt', (e) => {
43+
// Prevent default browser prompt sequence.
44+
e.preventDefault();
45+
deferredPrompt = e;
46+
47+
// Deployment of the personalized installation suggestion at the top.
48+
renderInstallSuggestion();
49+
});
50+
51+
/**
52+
* renderInstallSuggestion: Orchestrates a non-intrusive UI suggestion
53+
* at the document apex, encouraging the archival of AmeyArc to the device.
54+
*/
55+
function renderInstallSuggestion() {
56+
if (localStorage.getItem('pwa-suggestion-dismissed')) return;
57+
58+
const banner = document.createElement('div');
59+
banner.id = 'pwa-install-banner';
60+
banner.style.cssText = `
61+
position: fixed;
62+
top: 0;
63+
left: 0;
64+
width: 100%;
65+
background: var(--entry);
66+
border-bottom: 1px solid var(--border);
67+
padding: 10px 24px;
68+
z-index: 10001;
69+
display: flex;
70+
align-items: center;
71+
justify-content: center;
72+
cursor: pointer;
73+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
74+
animation: slideDown 0.5s cubic-bezier(0.4, 0, 0.2, 1);
75+
transition: opacity 0.3s ease;
76+
`;
77+
78+
banner.innerHTML = `
79+
<div style="display: flex; align-items: center; gap: 12px;">
80+
<span style="font-size: 1.2rem;">💭</span>
81+
<span style="font-size: 13px; color: var(--primary); font-weight: 500;">
82+
Install <strong>AmeyArc</strong> for a focused, offline-ready archival experience.
83+
</span>
84+
</div>
85+
<button id="pwa-dismiss" style="position: absolute; right: 24px; background: none; border: none; color: var(--secondary); cursor: pointer; font-size: 16px;">&times;</button>
86+
`;
87+
88+
banner.onclick = (e) => {
89+
if (e.target.id === 'pwa-dismiss') {
90+
banner.style.opacity = '0';
91+
setTimeout(() => banner.remove(), 300);
92+
localStorage.setItem('pwa-suggestion-dismissed', 'true');
93+
return;
94+
}
95+
banner.remove();
96+
deferredPrompt.prompt();
97+
deferredPrompt.userChoice.then((choiceResult) => {
98+
deferredPrompt = null;
99+
});
100+
};
101+
102+
document.body.prepend(banner);
103+
104+
// Inject animation keyframes
105+
const style = document.createElement('style');
106+
style.textContent = `
107+
@keyframes slideDown {
108+
from { transform: translateY(-100%); }
109+
to { transform: translateY(0); }
110+
}
111+
`;
112+
document.head.appendChild(style);
113+
}
114+
})();

Source Code/layouts/partials/internal/Injected_Footer_Hooks.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@
3232

3333
{{- /* Signature Animation: Processing and injecting Amey's thought-balloon logic. */ -}}
3434
{{- $anim := resources.Get "js/thought-animation.js" | js.Build }}
35-
<script src="{{ $anim.RelPermalink }}"></script>
35+
<script src="{{ $anim.RelPermalink }}"></script>
36+
{{- /* PWA Orchestration: Handling service workers and installation cycles. */ -}}
37+
{{- $pwa := resources.Get "js/pwa-handler.js" | js.Build | resources.Minify -}}
38+
<script src="{{ $pwa.RelPermalink }}"></script>

Source Code/layouts/partials/internal/Site_Head.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
{{- .Summary | default (printf " %s - %s" .Title site.Title) }}{{- else }} {{- with site.Params.description }}{{ .
6060
}}{{- end }}{{- end }}{{- end -}}">
6161

62-
<meta name="author" content="{{ (partial "scholarly/Scholar_Identity.html" . ) }}">
62+
<meta name="author" content="{{ (partial " scholarly/Scholar_Identity.html" . ) }}">
6363

6464
<link rel="canonical"
6565
href="{{ if .Params.canonicalURL -}} {{ trim .Params.canonicalURL " " }} {{- else -}} {{ .Permalink }} {{- end }}">
@@ -175,6 +175,7 @@
175175
<link rel="mask-icon" href="{{ site.Params.assets.safari_pinned_tab | default " safari-pinned-tab.svg" | absURL }}">
176176
<meta name="theme-color" content="{{ site.Params.assets.theme_color | default " #2e2e33" }}">
177177
<meta name="msapplication-TileColor" content="{{ site.Params.assets.msapplication_TileColor | default " #2e2e33" }}">
178+
<link rel="manifest" href="{{ " site.webmanifest" | absURL }}">
178179

179180
{{- /* Scholarly Dissemination: Alternative output formats (RSS/JSON) and Localization links. */ -}}
180181
{{ range .AlternativeOutputFormats -}}
@@ -285,4 +286,4 @@
285286
{{- partial "internal/SEO_OpenGraph.html" . -}}
286287
{{- partial "internal/SEO_Twitter_Cards.html" . -}}
287288
{{- partial "internal/SEO_Schema_JSON.html" . -}}
288-
{{- end -}}
289+
{{- end -}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "AmeyArc",
3+
"short_name": "AmeyArc",
4+
"description": "Advancing ideas @ AmeyArc - A personal digital archive of thoughts and projects.",
5+
"start_url": "/",
6+
"display": "standalone",
7+
"background_color": "#1d1e20",
8+
"theme_color": "#1d1e20",
9+
"icons": [
10+
{
11+
"src": "favicon_balloon.ico",
12+
"sizes": "any",
13+
"type": "image/x-icon"
14+
}
15+
]
16+
}

Source Code/static/sw.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* ==============================================================================
2+
- File: sw.js (Service Worker Orchestrator)
3+
- Author: Amey Thakur
4+
- Profile: https://github.com/Amey-Thakur
5+
- Repository: https://github.com/Amey-Thakur/Amey-Thakur.github.io
6+
- Release Date: December 16, 2025
7+
- License: MIT License
8+
- ==============================================================================
9+
-
10+
- DESCRIPTION:
11+
- This script serves as the primary Service Worker for AmeyArc. It handles
12+
- persistent offline caching, resource synchronization, and intercepting
13+
- network requests to ensure site availability in low-connectivity environments.
14+
-
15+
- HOW IT WORKS:
16+
- The orchestrator utilizes the Cache API to store critical site assets during
17+
- the installation phase. It performs cache-first fetch strategies and
18+
- identifies/purges legacy cache versions during activation to maintain
19+
- architectural efficiency and resource integrity.
20+
-
21+
- TECH STACK:
22+
- - Service Worker API
23+
- - Cache Storage API
24+
- - Fetch Event Orchestration
25+
-
26+
- ============================================================================== */
27+
28+
const CACHE_NAME = 'amey-arc-cache-v1';
29+
const ASSETS_TO_CACHE = [
30+
'/',
31+
'/archives/',
32+
'/search/',
33+
'/tags/',
34+
'/connect/',
35+
'/favicon_balloon.ico',
36+
'/site.webmanifest'
37+
];
38+
39+
/* Installation Event: Lifecycle initialization and primary asset caching. */
40+
self.addEventListener('install', (event) => {
41+
event.waitUntil(
42+
caches.open(CACHE_NAME).then((cache) => {
43+
return cache.addAll(ASSETS_TO_CACHE);
44+
})
45+
);
46+
});
47+
48+
/* Activation Event: Cache purge the technical debt of legacy versions. */
49+
self.addEventListener('activate', (event) => {
50+
event.waitUntil(
51+
caches.keys().then((cacheNames) => {
52+
return Promise.all(
53+
cacheNames.map((cacheName) => {
54+
if (cacheName !== CACHE_NAME) {
55+
return caches.delete(cacheName);
56+
}
57+
})
58+
);
59+
})
60+
);
61+
});
62+
63+
/* Fetch Orchestration: Intercepting network requests for offline resilience. */
64+
self.addEventListener('fetch', (event) => {
65+
event.respondWith(
66+
caches.match(event.request).then((response) => {
67+
return response || fetch(event.request);
68+
})
69+
);
70+
});

0 commit comments

Comments
 (0)