@profullstack/footer 0.2.2 → 0.2.4
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/README.md +2 -2
- package/package.json +1 -1
- package/src/index.js +42 -2
- package/src/template.js +1 -1
- package/template.json +1 -1
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@ One footer for every Profullstack site: your links, the copyright line, and the
|
|
|
6
6
|
**Publish once, every site updates.** The markup and CSS ship as data
|
|
7
7
|
(`template.json`). At render time each site fetches
|
|
8
8
|
`https://cdn.jsdelivr.net/npm/@profullstack/footer@latest/template.json`
|
|
9
|
-
(
|
|
10
|
-
every site within
|
|
9
|
+
(15 min cache, 1.5 s timeout, the bundled copy as the fallback), so a release reaches
|
|
10
|
+
every site within about an hour (sooner on sites without a page cache) with no bump, rebuild or redeploy. Install it as
|
|
11
11
|
`"@profullstack/footer": "latest"` too, so the render code follows on the next install.
|
|
12
12
|
|
|
13
13
|
It renders on the server: the ring's verifier reads your HTML and never runs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/footer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "One footer for every Profullstack site: links, copyright and the << Profullstack >> webring nav with Random. Sites render the @latest template from the CDN at runtime, so a release updates every site without a redeploy.",
|
|
6
6
|
"keywords": ["footer", "webring", "openwebring", "copyright", "react", "nextjs", "hono", "ssr"],
|
package/src/index.js
CHANGED
|
@@ -23,7 +23,10 @@ export { bundled as bundledTemplate };
|
|
|
23
23
|
|
|
24
24
|
export const TEMPLATE_URL = 'https://cdn.jsdelivr.net/npm/@profullstack/footer@latest/template.json';
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// 15 min: a page cache (ISR, 1 h) and Next's fetch cache both sit in front of
|
|
27
|
+
// this one and each serves one stale copy before refreshing, so the layers add up.
|
|
28
|
+
const DEFAULT_TTL_MS = 15 * 60 * 1000;
|
|
29
|
+
const NEXT_REVALIDATE_S = 300;
|
|
27
30
|
const FAILURE_TTL_MS = 5 * 60 * 1000;
|
|
28
31
|
|
|
29
32
|
/** @type {{ template: any, until: number, pending: Promise<any> | null }} */
|
|
@@ -51,6 +54,11 @@ export async function latestTemplate(opts = {}) {
|
|
|
51
54
|
const env = typeof process !== 'undefined' ? process.env ?? {} : {};
|
|
52
55
|
if (env.PROFULLSTACK_FOOTER_OFFLINE === '1') return bundled;
|
|
53
56
|
const now = (opts.now ?? Date.now)();
|
|
57
|
+
// Under Next.js, always go through fetch: Next caches it (revalidate 300 s)
|
|
58
|
+
// AND marks the route as revalidating. Answering from memory instead left
|
|
59
|
+
// every page rendered after the first at build time fully static
|
|
60
|
+
// (s-maxage=31536000), so it never saw a template release.
|
|
61
|
+
if (!opts.fetch && underNext()) return fetchFresh(opts, env, now);
|
|
54
62
|
if (cache.template && now < cache.until) return cache.template;
|
|
55
63
|
// Stale while revalidating: hand back what we have, refresh once.
|
|
56
64
|
if (cache.template && cache.pending) return cache.template;
|
|
@@ -65,7 +73,7 @@ export async function latestTemplate(opts = {}) {
|
|
|
65
73
|
const ctrl = typeof AbortController === 'function' ? new AbortController() : null;
|
|
66
74
|
const timer = ctrl ? setTimeout(() => ctrl.abort(), opts.timeoutMs ?? 1500) : null;
|
|
67
75
|
/** @type {RequestInit & { next?: { revalidate: number } }} */
|
|
68
|
-
const init = { signal: ctrl?.signal, headers: { accept: 'application/json' }, next: { revalidate:
|
|
76
|
+
const init = { signal: ctrl?.signal, headers: { accept: 'application/json' }, next: { revalidate: NEXT_REVALIDATE_S } };
|
|
69
77
|
const res = await doFetch(url, init).finally(() => timer && clearTimeout(timer));
|
|
70
78
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
71
79
|
const t = await res.json();
|
|
@@ -84,6 +92,38 @@ export async function latestTemplate(opts = {}) {
|
|
|
84
92
|
return cache.template ?? cache.pending;
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
/** Next.js patches fetch (and marks it) and sets NEXT_RUNTIME in its servers. */
|
|
96
|
+
function underNext() {
|
|
97
|
+
// @ts-ignore Next's marker on its patched fetch
|
|
98
|
+
if (globalThis.fetch && globalThis.fetch.__nextPatched) return true;
|
|
99
|
+
// Written out literally so Next's compile-time define can replace it.
|
|
100
|
+
return typeof process !== 'undefined' && !!process.env.NEXT_RUNTIME;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** One uncached-by-us fetch, for runtimes (Next) that cache fetch themselves. */
|
|
104
|
+
async function fetchFresh(opts, env, now) {
|
|
105
|
+
try {
|
|
106
|
+
const ctrl = typeof AbortController === 'function' ? new AbortController() : null;
|
|
107
|
+
const timer = ctrl ? setTimeout(() => ctrl.abort(), opts.timeoutMs ?? 1500) : null;
|
|
108
|
+
const res = await globalThis
|
|
109
|
+
.fetch(opts.url ?? env.PROFULLSTACK_FOOTER_TEMPLATE_URL ?? TEMPLATE_URL, {
|
|
110
|
+
signal: ctrl?.signal,
|
|
111
|
+
headers: { accept: 'application/json' },
|
|
112
|
+
// @ts-ignore Next's fetch extension
|
|
113
|
+
next: { revalidate: NEXT_REVALIDATE_S },
|
|
114
|
+
})
|
|
115
|
+
.finally(() => timer && clearTimeout(timer));
|
|
116
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
117
|
+
const t = await res.json();
|
|
118
|
+
if (!usable(t)) throw new Error('template not usable by this renderer');
|
|
119
|
+
cache.template = t;
|
|
120
|
+
cache.until = now + (opts.ttlMs ?? DEFAULT_TTL_MS);
|
|
121
|
+
return t;
|
|
122
|
+
} catch {
|
|
123
|
+
return cache.template ?? bundled;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
87
127
|
/** Forget the cached template (tests, or a manual refresh hook). */
|
|
88
128
|
export function resetTemplateCache() {
|
|
89
129
|
cache.template = null;
|
package/src/template.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// render.js does not fill; older installs then keep their bundled template.
|
|
10
10
|
|
|
11
11
|
export default {
|
|
12
|
-
version: '0.2.
|
|
12
|
+
version: '0.2.4',
|
|
13
13
|
renderer: 1,
|
|
14
14
|
css: [
|
|
15
15
|
'.pfs-footer{--pfs-footer-muted:color-mix(in srgb,currentColor 62%,transparent);--pfs-footer-gap:.5rem 1.25rem;--pfs-footer-size:.875rem;',
|
package/template.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.4",
|
|
3
3
|
"renderer": 1,
|
|
4
4
|
"css": ".pfs-footer{--pfs-footer-muted:color-mix(in srgb,currentColor 62%,transparent);--pfs-footer-gap:.5rem 1.25rem;--pfs-footer-size:.875rem;border-top:1px solid color-mix(in srgb,currentColor 14%,transparent);font-size:var(--pfs-footer-size);line-height:1.5;color:inherit}.pfs-footer__inner{max-width:72rem;margin:0 auto;padding:1.5rem 1rem;display:flex;flex-direction:column;align-items:center;gap:.75rem;text-align:center}.pfs-footer a{color:var(--pfs-footer-muted);text-decoration:none}.pfs-footer a:hover,.pfs-footer a:focus-visible{color:inherit;text-decoration:underline}.pfs-footer__links{display:flex;flex-wrap:wrap;justify-content:center;gap:var(--pfs-footer-gap)}.pfs-footer__ring{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:.6rem}.pfs-footer__copy{margin:0;color:var(--pfs-footer-muted)}.pfs-footer__copy a{color:inherit}",
|
|
5
5
|
"link": "<a href=\"{{href}}\"{{#rel}} rel=\"{{rel}}\"{{/rel}}>{{label}}</a>",
|