@profullstack/waitlist 0.4.0 → 0.5.0

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 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.4.0",
3
+ "version": "0.5.0",
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.1.1"
52
+ "@profullstack/comments": "^0.2.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@profullstack/abtest": "^0.1.0"
package/src/build.js CHANGED
@@ -171,7 +171,7 @@ ${slot.head.join('\n')}
171
171
  ${points ? `<div class="card">${points}</div>` : ''}
172
172
  ${slot.cards.join('\n')}
173
173
  </div>
174
- ${s.plugins.has('faq') ? faqHtml(s) : ''}
174
+ ${s.plugins.has('faq') ? faqHtml(s, { comments: s.plugins.has('board') }) : ''}
175
175
  ${slot.sections.join('\n')}
176
176
  <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
177
  </main>
@@ -215,7 +215,7 @@ export async function renderFooters(s, { fetchImpl = globalThis.fetch } = {}) {
215
215
  * Write the site for one spec into `out`. Returns the normalized spec.
216
216
  * `images: false` skips the PNG renders (og.png, icons), e.g. where @resvg/resvg-js cannot load.
217
217
  */
218
- export async function buildSite(spec, out, { footers = true, images = true, fetchImpl, cacheDir = null } = {}) {
218
+ export async function buildSite(spec, out, { footers = true, images = true, fetchImpl, cacheDir = null, maxAgeMs } = {}) {
219
219
  const s = normalize(spec);
220
220
  await mkdir(join(out, 'assets'), { recursive: true });
221
221
  await mkdir(join(out, '.well-known'), { recursive: true });
@@ -236,7 +236,7 @@ export async function buildSite(spec, out, { footers = true, images = true, fetc
236
236
  await writeFile(join(out, 'assets', 'icon-180.png'), await svgToPng(icon, { width: 180 }));
237
237
  }
238
238
  const foot = footers ? await renderFooters(s, { fetchImpl }) : '';
239
- const { slot } = await runPlugins(s, out, { fetchImpl, cacheDir });
239
+ const { slot } = await runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs });
240
240
  await writeFile(join(out, 'index.html'), pageHtml(s, { footers: foot, slot }));
241
241
  await writeFile(join(out, '404.html'), pageHtml(s, { footers: foot, noindex: true, slot }));
242
242
  await writeFile(join(out, 'robots.txt'), robotsTxt(s));
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 { return JSON.parse(await readFile(cacheFile, 'utf8')); } catch { /* not cached */ }
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
- const out = { query: q, fetchedAt: new Date().toISOString(), results };
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></details>`).join('\n ')}
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