@profullstack/waitlist 0.4.0 → 0.5.1
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 +1 -1
- package/bin/waitlist.js +2 -1
- package/package.json +2 -2
- package/src/build.js +31 -6
- package/src/plugins.js +15 -8
- package/src/seo.js +3 -2
package/README.md
CHANGED
|
@@ -113,7 +113,7 @@ Every page showcases all plugins by default. Pick per site in `sites.json`:
|
|
|
113
113
|
| `ab` | the look A/B test (see above) |
|
|
114
114
|
| `faq` | visible questions and answers (the FAQPage JSON-LD stays) |
|
|
115
115
|
| `resources` | useful reading from our own search: `pit.world/api/search?q=<keywords>` at build time, cached in `--cache` (default `.waitlist-cache`), shown with summaries, saved as `resources.json` |
|
|
116
|
-
| `board` | WWWThreads-style posts and replies ([@profullstack/comments](https://www.npmjs.com/package/@profullstack/comments)); reading is open, posting needs **Sign in with CoinPay**; RSS of the posts |
|
|
116
|
+
| `board` | WWWThreads-style posts and replies, plus a compact thread on every resource and FAQ answer ([@profullstack/comments](https://www.npmjs.com/package/@profullstack/comments)); reading is open, posting needs **Sign in with CoinPay**; RSS of the posts |
|
|
117
117
|
| `share` | a Share button on the board, also behind CoinPay sign-in |
|
|
118
118
|
| `feed` | `feed.xml` (RSS) and `feed.json` (JSON Feed) of the page and its resources, for syndication |
|
|
119
119
|
|
package/bin/waitlist.js
CHANGED
|
@@ -18,6 +18,7 @@ flags:
|
|
|
18
18
|
--theme dark|light
|
|
19
19
|
--look <look> neon|matrix|terminal|amber|synthwave|geocities|vaporwave (default: picked from the name)
|
|
20
20
|
--cache <dir> where pit.world search results are cached (default .waitlist-cache)
|
|
21
|
+
--max-age-hours <n> refresh cached search results older than this (default 20)
|
|
21
22
|
--no-footers skip the webring + pit.world footers (offline builds)
|
|
22
23
|
--no-images skip the PNG renders (og.png, icons)
|
|
23
24
|
|
|
@@ -43,7 +44,7 @@ for (let i = 0; i < argv.length; i++) {
|
|
|
43
44
|
} else pos.push(a);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
const opts = { footers: flags.footers !== false, images: flags.images !== false, cacheDir: flags.cache || '.waitlist-cache' };
|
|
47
|
+
const opts = { footers: flags.footers !== false, images: flags.images !== false, cacheDir: flags.cache || '.waitlist-cache', maxAgeMs: flags['max-age-hours'] ? Number(flags['max-age-hours']) * 3600_000 : undefined };
|
|
47
48
|
const pick = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
48
49
|
if (cmd === 'build') {
|
|
49
50
|
const s = await buildSite(pick({ name: flags.name, title: flags.title, tagline: flags.tagline, about: flags.about, points: flags.point, api: flags.api, host: flags.host, url: flags.url, image: flags.image, description: flags.description, theme: flags.theme, look: flags.look }), flags.out || `./${flags.name}`, opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/waitlist",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Email waitlist for any launch page: a <waitlist-form> web component, a live signup chart, and a static-site builder on @profullstack/css + @profullstack/charts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@profullstack/css": "^0.6.0",
|
|
50
50
|
"@profullstack/footer": "^0.7.3",
|
|
51
51
|
"@resvg/resvg-js": "^2.6.2",
|
|
52
|
-
"@profullstack/comments": "^0.
|
|
52
|
+
"@profullstack/comments": "^0.2.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@profullstack/abtest": "^0.1.0"
|
package/src/build.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* @profullstack/waitlist/build: write a complete static waitlist site (no server)
|
|
3
3
|
* for one name, ready for `c0mpute hosting publish <dir> --name <site>`.
|
|
4
4
|
*/
|
|
5
|
-
import { mkdir, writeFile, copyFile, readFile } from 'node:fs/promises';
|
|
5
|
+
import { mkdir, writeFile, copyFile, readFile, readdir } from 'node:fs/promises';
|
|
6
6
|
import { pluginSet, keywordsFor, runPlugins, baseSlot } from './plugins.js';
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
8
9
|
import { dirname, join } from 'node:path';
|
|
9
10
|
import { fileURLToPath } from 'node:url';
|
|
10
11
|
import {
|
|
@@ -171,7 +172,7 @@ ${slot.head.join('\n')}
|
|
|
171
172
|
${points ? `<div class="card">${points}</div>` : ''}
|
|
172
173
|
${slot.cards.join('\n')}
|
|
173
174
|
</div>
|
|
174
|
-
${s.plugins.has('faq') ? faqHtml(s) : ''}
|
|
175
|
+
${s.plugins.has('faq') ? faqHtml(s, { comments: s.plugins.has('board') }) : ''}
|
|
175
176
|
${slot.sections.join('\n')}
|
|
176
177
|
<p class="waitlist-meta">${s.moshpit ? `Also at <a href="${esc(s.nativeUrl)}">${esc(s.nativeUrl.replace(/\/$/, ''))}</a> on the Moshpit. ` : ''}One email when it opens, nothing else. Hosted on <a href="https://c0mpute.com/hosting">c0mpute</a>.</p>
|
|
177
178
|
</main>
|
|
@@ -215,7 +216,7 @@ export async function renderFooters(s, { fetchImpl = globalThis.fetch } = {}) {
|
|
|
215
216
|
* Write the site for one spec into `out`. Returns the normalized spec.
|
|
216
217
|
* `images: false` skips the PNG renders (og.png, icons), e.g. where @resvg/resvg-js cannot load.
|
|
217
218
|
*/
|
|
218
|
-
export async function buildSite(spec, out, { footers = true, images = true, fetchImpl, cacheDir = null } = {}) {
|
|
219
|
+
export async function buildSite(spec, out, { footers = true, images = true, fetchImpl, cacheDir = null, maxAgeMs } = {}) {
|
|
219
220
|
const s = normalize(spec);
|
|
220
221
|
await mkdir(join(out, 'assets'), { recursive: true });
|
|
221
222
|
await mkdir(join(out, '.well-known'), { recursive: true });
|
|
@@ -236,9 +237,12 @@ export async function buildSite(spec, out, { footers = true, images = true, fetc
|
|
|
236
237
|
await writeFile(join(out, 'assets', 'icon-180.png'), await svgToPng(icon, { width: 180 }));
|
|
237
238
|
}
|
|
238
239
|
const foot = footers ? await renderFooters(s, { fetchImpl }) : '';
|
|
239
|
-
const { slot } = await runPlugins(s, out, { fetchImpl, cacheDir });
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
const { slot } = await runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs });
|
|
241
|
+
// Assets are cached by browsers and gateways (max-age 1 h), so a page must name the
|
|
242
|
+
// exact build of every script and stylesheet it needs, or a new page runs old code.
|
|
243
|
+
const ver = await versionAssets(out);
|
|
244
|
+
await writeFile(join(out, 'index.html'), withAssetVersion(pageHtml(s, { footers: foot, slot }), ver));
|
|
245
|
+
await writeFile(join(out, '404.html'), withAssetVersion(pageHtml(s, { footers: foot, noindex: true, slot }), ver));
|
|
242
246
|
await writeFile(join(out, 'robots.txt'), robotsTxt(s));
|
|
243
247
|
await writeFile(join(out, 'sitemap.xml'), sitemapXml(s));
|
|
244
248
|
await writeFile(join(out, 'llms.txt'), llmsTxt(s));
|
|
@@ -247,6 +251,27 @@ export async function buildSite(spec, out, { footers = true, images = true, fetc
|
|
|
247
251
|
return s;
|
|
248
252
|
}
|
|
249
253
|
|
|
254
|
+
/** A short hash of everything in assets/; module imports between assets carry it too. */
|
|
255
|
+
export async function versionAssets(out) {
|
|
256
|
+
const dir = join(out, 'assets');
|
|
257
|
+
const names = (await readdir(dir)).sort();
|
|
258
|
+
const h = createHash('sha256');
|
|
259
|
+
for (const n of names) h.update(n).update(await readFile(join(dir, n)));
|
|
260
|
+
const ver = h.digest('hex').slice(0, 10);
|
|
261
|
+
for (const n of names.filter((x) => x.endsWith('.js'))) {
|
|
262
|
+
const f = join(dir, n);
|
|
263
|
+
const src = await readFile(f, 'utf8');
|
|
264
|
+
const next = src.replace(/(from\s+|import\s*\(\s*)(['"])(\.\/[^'"?]+\.js)\2/g, (_, pre, q, path) => `${pre}${q}${path}?v=${ver}${q}`);
|
|
265
|
+
if (next !== src) await writeFile(f, next);
|
|
266
|
+
}
|
|
267
|
+
return ver;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** assets/x.css -> assets/x.css?v=<ver> in href/src attributes. */
|
|
271
|
+
export function withAssetVersion(html, ver) {
|
|
272
|
+
return html.replace(/((?:href|src)=")(assets\/[^"?#]+)(")/g, `$1$2?v=${ver}$3`);
|
|
273
|
+
}
|
|
274
|
+
|
|
250
275
|
/** Build many: specs is an array; each lands in `${outRoot}/${name}`. */
|
|
251
276
|
export async function buildMany(specs, outRoot, opts = {}) {
|
|
252
277
|
const done = [];
|
package/src/plugins.js
CHANGED
|
@@ -40,13 +40,18 @@ export function keywordsFor(s) {
|
|
|
40
40
|
* Resources from our own search (pit.world /api/search), fetched once at build and
|
|
41
41
|
* cached on disk by query so rebuilds do not search again. Never throws.
|
|
42
42
|
*/
|
|
43
|
-
export async function fetchResources(s, { fetchImpl = globalThis.fetch, cacheDir = null, limit = 8, endpoint = 'https://pit.world/api/search' } = {}) {
|
|
43
|
+
export async function fetchResources(s, { fetchImpl = globalThis.fetch, cacheDir = null, limit = 8, endpoint = 'https://pit.world/api/search', maxAgeMs = 20 * 3600_000, now = Date.now() } = {}) {
|
|
44
44
|
const q = s.resourcesQuery || keywordsFor(s).slice(0, 4).join(' ');
|
|
45
45
|
if (!q) return { query: '', results: [] };
|
|
46
46
|
const key = createHash('sha256').update(q).digest('hex').slice(0, 16);
|
|
47
47
|
const cacheFile = cacheDir ? join(cacheDir, `${key}.json`) : null;
|
|
48
|
+
let stale = null;
|
|
48
49
|
if (cacheFile) {
|
|
49
|
-
try {
|
|
50
|
+
try {
|
|
51
|
+
const c = JSON.parse(await readFile(cacheFile, 'utf8'));
|
|
52
|
+
if (now - Date.parse(c.fetchedAt) < maxAgeMs) return c;
|
|
53
|
+
stale = c; // refresh it, but keep it if the search fails
|
|
54
|
+
} catch { /* not cached */ }
|
|
50
55
|
}
|
|
51
56
|
let results = [];
|
|
52
57
|
try {
|
|
@@ -60,16 +65,18 @@ export async function fetchResources(s, { fetchImpl = globalThis.fetch, cacheDir
|
|
|
60
65
|
} catch {
|
|
61
66
|
results = [];
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
if (!results.length && stale) return stale;
|
|
69
|
+
const out = { query: q, fetchedAt: new Date(now).toISOString(), results };
|
|
64
70
|
if (cacheFile && results.length) { await mkdir(cacheDir, { recursive: true }); await writeFile(cacheFile, JSON.stringify(out, null, 2)); }
|
|
65
71
|
return out;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
|
-
export function resourcesHtml(s, res) {
|
|
74
|
+
export function resourcesHtml(s, res, { comments = false, share = false } = {}) {
|
|
75
|
+
const thread = (r) => comments ? `<comments-board compact dn="${esc(s.dn)}" api="${esc(s.api)}" item="${esc(r.url)}" subject="${esc(`Re: ${r.title}`.slice(0, 120))}"${share ? ' share' : ''}></comments-board>` : '';
|
|
69
76
|
if (!res?.results?.length) return '';
|
|
70
77
|
return `<section class="stack" aria-labelledby="resources"><h2 id="resources">Resources</h2>
|
|
71
78
|
<p class="muted">Useful reading on ${esc(s.title)} while you wait, from <a href="https://pit.world/search?q=${encodeURIComponent(res.query)}">pit.world search</a>.</p>
|
|
72
|
-
<ul role="list" class="grid" data-columns="2">${res.results.map((r) => `<li class="card stack" data-space="sm"><a href="${esc(r.url)}" rel="noopener"><strong>${esc(r.title)}</strong></a><small class="muted">${esc(r.host)}</small>${r.summary ? `<p>${esc(r.summary)}</p>` : ''}</li>`).join('')}</ul>
|
|
79
|
+
<ul role="list" class="grid" data-columns="2">${res.results.map((r) => `<li class="card stack" data-space="sm"><a href="${esc(r.url)}" rel="noopener"><strong>${esc(r.title)}</strong></a><small class="muted">${esc(r.host)}</small>${r.summary ? `<p>${esc(r.summary)}</p>` : ''}${thread(r)}</li>`).join('')}</ul>
|
|
73
80
|
</section>`;
|
|
74
81
|
}
|
|
75
82
|
|
|
@@ -102,13 +109,13 @@ export function baseSlot(s) {
|
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
/** Everything the plugins add to one page: { head, hero, cards, sections, scripts } and files to write. */
|
|
105
|
-
export async function runPlugins(s, out, { fetchImpl, cacheDir } = {}) {
|
|
112
|
+
export async function runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs } = {}) {
|
|
106
113
|
const on = s.plugins;
|
|
107
114
|
const slot = baseSlot(s);
|
|
108
115
|
let res = null;
|
|
109
116
|
if (on.has('resources')) {
|
|
110
|
-
res = await fetchResources(s, { fetchImpl, cacheDir });
|
|
111
|
-
slot.sections.push(resourcesHtml(s, res));
|
|
117
|
+
res = await fetchResources(s, { fetchImpl, cacheDir, maxAgeMs });
|
|
118
|
+
slot.sections.push(resourcesHtml(s, res, { comments: on.has('board'), share: on.has('share') }));
|
|
112
119
|
if (res.results.length) await writeFile(join(out, 'resources.json'), JSON.stringify(res, null, 2) + '\n');
|
|
113
120
|
}
|
|
114
121
|
if (on.has('board')) {
|
package/src/seo.js
CHANGED
|
@@ -152,10 +152,11 @@ export function jsonLdTag(s) {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/** The visible FAQ section: same questions as the FAQPage JSON-LD. */
|
|
155
|
-
export function faqHtml(s) {
|
|
155
|
+
export function faqHtml(s, { comments = false } = {}) {
|
|
156
156
|
if (!s.faq.length) return '';
|
|
157
|
+
const thread = (f, i) => comments ? `<comments-board compact dn="${esc(s.dn)}" api="${esc(s.api)}" item="faq:${i + 1}" subject="${esc(`Re: ${f.q}`.slice(0, 120))}"></comments-board>` : '';
|
|
157
158
|
return `<section class="card stack waitlist-faq" aria-labelledby="faq"><h2 id="faq">Questions</h2>
|
|
158
|
-
${s.faq.map((f) => `<details><summary>${esc(f.q)}</summary><p>${esc(f.a)}</p
|
|
159
|
+
${s.faq.map((f, i) => `<details><summary>${esc(f.q)}</summary><p>${esc(f.a)}</p>${thread(f, i)}</details>`).join('\n ')}
|
|
159
160
|
</section>`;
|
|
160
161
|
}
|
|
161
162
|
|