@profullstack/waitlist 0.5.0 → 0.6.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 +1 -0
- package/package.json +3 -2
- package/src/build.js +28 -3
- package/src/plugins.js +16 -1
package/README.md
CHANGED
|
@@ -116,6 +116,7 @@ Every page showcases all plugins by default. Pick per site in `sites.json`:
|
|
|
116
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
|
+
| `buyaday` | `<pf-buy-a-day>` from [@profullstack/marketing-widgets](https://github.com/profullstack/marketing-widgets): the next free doors on [holi.days](https://holi.days.pit.world/calendars) calendars (ones matching the site's keywords first), baked in and refreshed live, every sale credited to this site with `?ref=<host>`. Nothing shows when the feed is down. `buyadayKeywords` / `buyadayLimit` in `sites.json` override the keywords and count (default 3) |
|
|
119
120
|
|
|
120
121
|
`keywords` (also the `<meta name="keywords">`) default to the name's labels plus the tagline's
|
|
121
122
|
meaningful words; set `keywords` or `resourcesQuery` per site to steer the resources.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/waitlist",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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,8 @@
|
|
|
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.2.0"
|
|
52
|
+
"@profullstack/comments": "^0.2.0",
|
|
53
|
+
"@profullstack/marketing-widgets": "^0.1.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@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 {
|
|
@@ -237,8 +238,11 @@ export async function buildSite(spec, out, { footers = true, images = true, fetc
|
|
|
237
238
|
}
|
|
238
239
|
const foot = footers ? await renderFooters(s, { fetchImpl }) : '';
|
|
239
240
|
const { slot } = await runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs });
|
|
240
|
-
|
|
241
|
-
|
|
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
|
@@ -16,7 +16,7 @@ import { esc } from './seo.js';
|
|
|
16
16
|
|
|
17
17
|
const require = createRequire(import.meta.url);
|
|
18
18
|
|
|
19
|
-
export const PLUGINS = ['form', 'stats', 'ab', 'faq', 'resources', 'board', 'share', 'feed'];
|
|
19
|
+
export const PLUGINS = ['form', 'stats', 'ab', 'faq', 'resources', 'board', 'share', 'feed', 'buyaday'];
|
|
20
20
|
|
|
21
21
|
/** Resolve a site's `plugins` setting to a Set (default: all of them). */
|
|
22
22
|
export function pluginSet(setting) {
|
|
@@ -126,6 +126,21 @@ export async function runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs } = {})
|
|
|
126
126
|
slot.scripts.push('<script type="module" src="assets/comments.js"></script>');
|
|
127
127
|
slot.head.push(`<link rel="alternate" type="application/rss+xml" title="${esc(s.title)} discussion" href="${esc(s.api)}/api/comments/feed?dn=${encodeURIComponent(s.dn)}">`);
|
|
128
128
|
}
|
|
129
|
+
if (on.has('buyaday')) {
|
|
130
|
+
// @profullstack/marketing-widgets: sell holi.days doors, credited to this site.
|
|
131
|
+
// Offers are baked in (no script needed, crawlers read them); the copied script
|
|
132
|
+
// refreshes them live so taken doors drop off. An empty feed renders nothing.
|
|
133
|
+
const mw = await import('@profullstack/marketing-widgets');
|
|
134
|
+
const html = await mw.buyADayHtml({ ref: s.host, keywords: s.buyadayKeywords || keywordsFor(s), limit: s.buyadayLimit || 3, fetchImpl });
|
|
135
|
+
if (html.includes('pf-mw-offer')) {
|
|
136
|
+
const core = await readFile(mw.assetPath.core, 'utf8');
|
|
137
|
+
const widgets = (await readFile(mw.assetPath.widgets, 'utf8')).replace(/from '\.\/core\.js'/, "from './mw-core.js'");
|
|
138
|
+
await writeFile(join(out, 'assets', 'mw-core.js'), core);
|
|
139
|
+
await writeFile(join(out, 'assets', 'mw-widgets.js'), widgets);
|
|
140
|
+
slot.sections.push(`<section class="stack" aria-label="Buy a day">${html}</section>`);
|
|
141
|
+
slot.scripts.push('<script type="module" src="assets/mw-widgets.js"></script>');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
129
144
|
if (on.has('feed')) {
|
|
130
145
|
const f = feeds(s, res);
|
|
131
146
|
await writeFile(join(out, 'feed.xml'), f.rss);
|