@rmdes/indiekit-frontend 1.0.0-beta.35 → 1.0.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/sidebar/template.njk +17 -1
- package/lib/serviceworker.js +29 -31
- package/package.json +1 -1
|
@@ -93,8 +93,24 @@
|
|
|
93
93
|
</ul>
|
|
94
94
|
</div>
|
|
95
95
|
|
|
96
|
+
{# --- FEDIVERSE --- #}
|
|
97
|
+
<div class="sidebar__group">
|
|
98
|
+
<span class="sidebar__group-label">Fediverse</span>
|
|
99
|
+
<ul class="sidebar__list" role="list">
|
|
100
|
+
{% for item in items %}{% if item.href and item.text %}
|
|
101
|
+
{% if "/activitypub" in item.href %}
|
|
102
|
+
<li class="sidebar__list-item">
|
|
103
|
+
<a href="{{ item.href }}"{{- attributes(item.attributes) }}>
|
|
104
|
+
{{- item.text | safe -}}
|
|
105
|
+
</a>
|
|
106
|
+
</li>
|
|
107
|
+
{% endif %}
|
|
108
|
+
{% endif %}{% endfor %}
|
|
109
|
+
</ul>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
96
112
|
{# --- UNCATEGORIZED (catch-all for future plugins) --- #}
|
|
97
|
-
{% set knownPaths = ["/posts", "/files", "/microsub", "/webmention", "/blogroll", "/podroll", "/homepage", "/cv", "/github", "/lastfm", "/funkwhale", "/youtube", "/rss"] %}
|
|
113
|
+
{% set knownPaths = ["/posts", "/files", "/microsub", "/webmention", "/blogroll", "/podroll", "/homepage", "/cv", "/github", "/lastfm", "/funkwhale", "/youtube", "/rss", "/activitypub"] %}
|
|
98
114
|
{% set hasOther = [] %}
|
|
99
115
|
{% for item in items %}{% if item.href and item.text %}
|
|
100
116
|
{% set matched = false %}
|
package/lib/serviceworker.js
CHANGED
|
@@ -76,17 +76,6 @@ async function clearOldCaches() {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/**
|
|
80
|
-
* Clear the pages cache so stale HTML (with old asset references) is not served
|
|
81
|
-
*/
|
|
82
|
-
async function clearPagesCache() {
|
|
83
|
-
try {
|
|
84
|
-
await caches.delete(pagesCacheName);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error("Error clearing pages cache", error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
79
|
/**
|
|
91
80
|
* Notify all clients that the service worker has been updated
|
|
92
81
|
*/
|
|
@@ -162,44 +151,53 @@ self.addEventListener("fetch", (event) => {
|
|
|
162
151
|
return;
|
|
163
152
|
}
|
|
164
153
|
|
|
165
|
-
// For HTML requests
|
|
154
|
+
// For HTML requests: network-first with conditional timeout
|
|
155
|
+
// - If a cached version exists: race network against timeout, serve cache on timeout
|
|
156
|
+
// - If no cached version: wait for network without timeout (avoid premature "Offline")
|
|
166
157
|
if (
|
|
167
158
|
request.mode === "navigate" ||
|
|
168
159
|
(request.headers.get("Accept") || "").includes("text/html")
|
|
169
160
|
) {
|
|
170
161
|
event.respondWith(
|
|
171
162
|
(async () => {
|
|
163
|
+
// Check cache and start network fetch in parallel
|
|
164
|
+
const cachedResponse = await caches.match(request);
|
|
165
|
+
const networkFetch = (async () => {
|
|
166
|
+
const preloadResponse = await Promise.resolve(event.preloadResponse);
|
|
167
|
+
return preloadResponse || (await fetch(request));
|
|
168
|
+
})();
|
|
169
|
+
|
|
172
170
|
try {
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
171
|
+
// Only apply timeout when we have a cached fallback.
|
|
172
|
+
// Without a cache, it's better to wait for the network (loading spinner)
|
|
173
|
+
// than to show "Offline" after 5 seconds on a slow backend.
|
|
174
|
+
const responseFromNetwork = cachedResponse
|
|
175
|
+
? await Promise.race([
|
|
176
|
+
networkFetch,
|
|
177
|
+
new Promise((_, reject) =>
|
|
178
|
+
setTimeout(
|
|
179
|
+
() => reject(new Error("Network timeout")),
|
|
180
|
+
timeout,
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
])
|
|
184
|
+
: await networkFetch;
|
|
185
185
|
|
|
186
186
|
// NETWORK succeeded — cache and serve
|
|
187
187
|
try {
|
|
188
|
-
const copy =
|
|
188
|
+
const copy = responseFromNetwork.clone();
|
|
189
189
|
const pagesCache = await caches.open(pagesCacheName);
|
|
190
190
|
await pagesCache.put(request, copy);
|
|
191
191
|
} catch (cacheError) {
|
|
192
192
|
console.error("Failed to cache page:", cacheError);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
return
|
|
195
|
+
return responseFromNetwork;
|
|
196
196
|
} catch {
|
|
197
|
-
// NETWORK failed or timed out — fall back to cache
|
|
198
|
-
const responseFromCache = await caches.match(request);
|
|
199
|
-
const offlineResponse = await caches.match("/offline");
|
|
197
|
+
// NETWORK failed or timed out — fall back to cache or offline
|
|
200
198
|
return (
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
cachedResponse ||
|
|
200
|
+
(await caches.match("/offline")) ||
|
|
203
201
|
new Response("Offline", {
|
|
204
202
|
status: 503,
|
|
205
203
|
statusText: "Service Unavailable",
|