@profullstack/waitlist 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +56 -2
- package/bin/waitlist.js +46 -0
- package/package.json +24 -4
- package/src/build.js +188 -0
- package/src/index.js +248 -0
- package/src/waitlist.css +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Profullstack, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @profullstack/waitlist
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An email waitlist for any launch page: a `<waitlist-form>` web component, a live signup
|
|
4
|
+
chart drawn with [@profullstack/charts](https://www.npmjs.com/package/@profullstack/charts),
|
|
5
|
+
and a static-site builder on [@profullstack/css](https://www.npmjs.com/package/@profullstack/css)
|
|
6
|
+
with its retro **looks** (neon, matrix, terminal, amber CRT, synthwave, GeoCities, vaporwave).
|
|
7
|
+
No server of your own: sites publish to c0mpute hosting and signups go to the house waitlist API.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @profullstack/waitlist
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Build a site
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx @profullstack/waitlist build --name alt.atheism \
|
|
17
|
+
--tagline "Arguing about god since 1989." --point "Threaded discussion" --look geocities --out site
|
|
18
|
+
c0mpute hosting publish site --name waitlist-alt-atheism
|
|
19
|
+
moshcode name c0mpute alt.atheism <site_id> # https://alt.atheism and alt.atheism.pit.world
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`waitlist build-many sites.json --out sites` builds one folder per entry
|
|
23
|
+
(`[{ name, title, tagline, about, points, look, kicker }]`).
|
|
24
|
+
|
|
25
|
+
Each site gets `index.html`, `404.html`, `robots.txt`, `sitemap.xml`, the CSS and chart
|
|
26
|
+
assets, the Profullstack webring footer and (for Moshpit names) the pit.world footer, plus
|
|
27
|
+
the network's crawlproof tag. Leave `--look` out and one is picked from the name: `comp.*`
|
|
28
|
+
terminal, `alt.*` GeoCities, `sci.*` matrix, `rec.*` synthwave, `soc.*` vaporwave,
|
|
29
|
+
`news.*` amber, `talk.*` neon.
|
|
30
|
+
|
|
31
|
+
## Use the components on any page
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<link rel="stylesheet" href="https://unpkg.com/@profullstack/css/css/profullstack.css">
|
|
35
|
+
<link rel="stylesheet" href="https://unpkg.com/@profullstack/css/css/looks.css">
|
|
36
|
+
<script src="https://unpkg.com/@profullstack/charts/dist/charts.global.js"></script>
|
|
37
|
+
<script type="module" src="https://unpkg.com/@profullstack/waitlist/src/index.js"></script>
|
|
38
|
+
|
|
39
|
+
<waitlist-form dn="example.com"></waitlist-form>
|
|
40
|
+
<waitlist-stats dn="example.com" days="30"></waitlist-stats>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Attributes: `dn` (the list; defaults to the page's host), `api` (default
|
|
44
|
+
`https://moshcoding.com`), `button`, `label`, `placeholder`. A successful signup fires
|
|
45
|
+
`waitlist:joined`. From JavaScript: `join({ email, dn })`, `stats({ dn })`.
|
|
46
|
+
|
|
47
|
+
## The API
|
|
48
|
+
|
|
49
|
+
Any server with these two routes works (moshcoding.com runs them: double opt-in email,
|
|
50
|
+
a list per domain in the owner's dashboard, `waitlist.signup` domain webhooks):
|
|
51
|
+
|
|
52
|
+
- `POST /api/waitlist` `{ email, dn, ref? }` -> `{ ok, pending, already }` or `{ error }`
|
|
53
|
+
- `GET /api/waitlist/stats?dn=&days=` -> `{ total, verified, days: [{ day, n }] }` (counts only)
|
|
54
|
+
|
|
55
|
+
Both send `Access-Control-Allow-Origin: *`.
|
|
56
|
+
|
|
57
|
+
MIT
|
package/bin/waitlist.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { buildSite, buildMany, readSpecs } from '../src/build.js';
|
|
3
|
+
|
|
4
|
+
const HELP = `waitlist: build static waitlist sites (@profullstack/css + @profullstack/charts)
|
|
5
|
+
|
|
6
|
+
usage:
|
|
7
|
+
waitlist build --name <name> [--title T] [--tagline T] [--about T] [--point P]... [--out dir]
|
|
8
|
+
waitlist build-many <sites.json> [--out dir] one folder per site under --out
|
|
9
|
+
|
|
10
|
+
flags:
|
|
11
|
+
--api <url> waitlist API (default https://moshcoding.com)
|
|
12
|
+
--host <host> public host (default <name>.pit.world for Moshpit names)
|
|
13
|
+
--theme dark|light
|
|
14
|
+
--look <look> neon|matrix|terminal|amber|synthwave|geocities|vaporwave (default: picked from the name)
|
|
15
|
+
--no-footers skip the webring + pit.world footers (offline builds)
|
|
16
|
+
|
|
17
|
+
publish: c0mpute hosting publish <dir> --name waitlist-<name>
|
|
18
|
+
moshcode name c0mpute <name> <site_id>`;
|
|
19
|
+
|
|
20
|
+
const argv = process.argv.slice(2);
|
|
21
|
+
const cmd = argv.shift();
|
|
22
|
+
const flags = { point: [] };
|
|
23
|
+
const pos = [];
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const a = argv[i];
|
|
26
|
+
if (a === '--no-footers') flags.footers = false;
|
|
27
|
+
else if (a.startsWith('--')) {
|
|
28
|
+
const k = a.slice(2);
|
|
29
|
+
const v = argv[++i];
|
|
30
|
+
if (k === 'point') flags.point.push(v);
|
|
31
|
+
else flags[k] = v;
|
|
32
|
+
} else pos.push(a);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const opts = { footers: flags.footers !== false };
|
|
36
|
+
if (cmd === 'build') {
|
|
37
|
+
const s = await buildSite({ name: flags.name, title: flags.title, tagline: flags.tagline, about: flags.about, points: flags.point, api: flags.api, host: flags.host, theme: flags.theme, look: flags.look }, flags.out || `./${flags.name}`, opts);
|
|
38
|
+
console.log(`built ${s.name} -> ${flags.out || `./${s.name}`}`);
|
|
39
|
+
} else if (cmd === 'build-many' && pos[0]) {
|
|
40
|
+
const specs = await readSpecs(pos[0]);
|
|
41
|
+
const done = await buildMany(specs.map((s) => ({ api: flags.api, theme: flags.theme, ...s })), flags.out || './sites', opts);
|
|
42
|
+
console.log(`built ${done.length} sites -> ${flags.out || './sites'}`);
|
|
43
|
+
} else {
|
|
44
|
+
console.log(HELP);
|
|
45
|
+
process.exit(cmd && cmd !== 'help' && cmd !== '--help' ? 1 : 0);
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/waitlist",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Profullstack, Inc.",
|
|
8
|
+
"homepage": "https://github.com/profullstack/waitlist#readme",
|
|
9
|
+
"repository": { "type": "git", "url": "git+https://github.com/profullstack/waitlist.git" },
|
|
10
|
+
"keywords": ["waitlist", "launch", "landing-page", "web-component", "static-site", "c0mpute", "moshpit"],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.js",
|
|
13
|
+
"./build": "./src/build.js",
|
|
14
|
+
"./waitlist.css": "./src/waitlist.css",
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"bin": { "waitlist": "bin/waitlist.js" },
|
|
18
|
+
"files": ["src", "bin", "README.md", "LICENSE"],
|
|
19
|
+
"engines": { "node": ">=20" },
|
|
20
|
+
"scripts": { "test": "node --test" },
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@profullstack/charts": "^0.3.0",
|
|
23
|
+
"@profullstack/css": "^0.4.0",
|
|
24
|
+
"@profullstack/footer": "^0.7.3"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/build.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @profullstack/waitlist/build: write a complete static waitlist site (no server)
|
|
3
|
+
* for one name, ready for `c0mpute hosting publish <dir> --name <site>`.
|
|
4
|
+
*/
|
|
5
|
+
import { mkdir, writeFile, copyFile, readFile } from 'node:fs/promises';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { dirname, join } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
/** The crawlproof project every Moshpit landing and parked page reports to. */
|
|
14
|
+
export const MOSHPIT_STATS_SITE = '2cbffe9d-1b6e-43f0-85f3-3cadee132048';
|
|
15
|
+
|
|
16
|
+
export function esc(s) {
|
|
17
|
+
return String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Every look @profullstack/css/looks ships. */
|
|
21
|
+
export const LOOKS = ['neon', 'matrix', 'terminal', 'amber', 'synthwave', 'geocities', 'vaporwave'];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A look that fits the name when none is given: newsgroup hierarchies get their
|
|
25
|
+
* era (comp.* a terminal, alt.* a GeoCities page, sci.* the matrix, rec.* synthwave),
|
|
26
|
+
* anything else a stable pick from the name.
|
|
27
|
+
*/
|
|
28
|
+
export function lookFor(name) {
|
|
29
|
+
const first = name.split('.')[0];
|
|
30
|
+
const byPrefix = { comp: 'terminal', news: 'amber', alt: 'geocities', sci: 'matrix', rec: 'synthwave', soc: 'vaporwave', talk: 'neon', misc: 'amber' };
|
|
31
|
+
if (byPrefix[first]) return byPrefix[first];
|
|
32
|
+
const ending = name.split('.').pop();
|
|
33
|
+
const byEnding = { cli: 'terminal', pit: 'terminal', dns: 'terminal', v6: 'terminal', onions: 'matrix', agent: 'matrix', desktop: 'vaporwave', politics: 'neon', lobby: 'amber', whatever: 'geocities', yeah: 'synthwave', rank: 'neon' };
|
|
34
|
+
if (byEnding[ending]) return byEnding[ending];
|
|
35
|
+
let h = 0;
|
|
36
|
+
for (const ch of name) h = (h * 31 + ch.charCodeAt(0)) >>> 0;
|
|
37
|
+
return LOOKS[h % LOOKS.length];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A Moshpit name (label.ending, no dot-TLD of the old internet) -> its pit.world relay host. */
|
|
41
|
+
export function relayHost(name) {
|
|
42
|
+
return name.endsWith('.pit.world') ? name : `${name}.pit.world`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Fill defaults and validate one site spec. */
|
|
46
|
+
export function normalize(spec) {
|
|
47
|
+
const name = String(spec.name || '').trim().toLowerCase();
|
|
48
|
+
if (!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(name)) throw new Error(`bad name: ${spec.name}`);
|
|
49
|
+
const moshpit = spec.moshpit ?? !/\.(com|org|net|io|dev|app|sh|xyz|me|info|co|ai)$/.test(name);
|
|
50
|
+
const host = spec.host || (moshpit ? relayHost(name) : name);
|
|
51
|
+
return {
|
|
52
|
+
name,
|
|
53
|
+
host,
|
|
54
|
+
moshpit,
|
|
55
|
+
dn: spec.dn || name,
|
|
56
|
+
title: spec.title || name,
|
|
57
|
+
tagline: spec.tagline || `${name} is coming soon.`,
|
|
58
|
+
about: spec.about || '',
|
|
59
|
+
points: Array.isArray(spec.points) ? spec.points : [],
|
|
60
|
+
kicker: spec.kicker || (moshpit ? 'Coming soon on the Moshpit' : 'Coming soon'),
|
|
61
|
+
button: spec.button || 'Join the waitlist',
|
|
62
|
+
api: spec.api || 'https://moshcoding.com',
|
|
63
|
+
theme: spec.theme || 'dark',
|
|
64
|
+
look: LOOKS.includes(spec.look) ? spec.look : lookFor(name),
|
|
65
|
+
marquee: spec.marquee || `Welcome to ${name}! You are visitor #000${(name.length * 7919) % 9000 + 1000}. Sign the waitlist below!`,
|
|
66
|
+
crawlproof: spec.crawlproof === undefined ? (moshpit ? MOSHPIT_STATS_SITE : null) : spec.crawlproof,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The page HTML. `footers` is pre-rendered HTML (webring row, pit.world footer) placed last. */
|
|
71
|
+
export function pageHtml(s, { footers = '' } = {}) {
|
|
72
|
+
const url = `https://${s.host}/`;
|
|
73
|
+
const desc = `${s.tagline} Join the waitlist.`;
|
|
74
|
+
const points = s.points.length
|
|
75
|
+
? `<section class="stack" aria-labelledby="what"><h2 id="what">What's coming</h2><ul class="waitlist-points">${s.points.map((p) => `<li>${esc(p)}</li>`).join('')}</ul></section>`
|
|
76
|
+
: '';
|
|
77
|
+
const about = s.about ? `<p>${esc(s.about)}</p>` : '';
|
|
78
|
+
const ld = { '@context': 'https://schema.org', '@type': 'WebSite', name: s.title, url, description: desc };
|
|
79
|
+
return `<!doctype html>
|
|
80
|
+
<html lang="en" data-theme="${esc(s.theme)}" data-look="${esc(s.look)}">
|
|
81
|
+
<head>
|
|
82
|
+
<meta charset="utf-8">
|
|
83
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
84
|
+
<title>${esc(s.title)}: ${esc(s.tagline)}</title>
|
|
85
|
+
<meta name="description" content="${esc(desc)}">
|
|
86
|
+
<link rel="canonical" href="${esc(url)}">
|
|
87
|
+
<meta property="og:type" content="website">
|
|
88
|
+
<meta property="og:title" content="${esc(s.title)}">
|
|
89
|
+
<meta property="og:description" content="${esc(desc)}">
|
|
90
|
+
<meta property="og:url" content="${esc(url)}">
|
|
91
|
+
<meta name="twitter:card" content="summary">
|
|
92
|
+
<link rel="icon" href="assets/icon.svg" type="image/svg+xml">
|
|
93
|
+
<link rel="stylesheet" href="assets/profullstack.css">
|
|
94
|
+
<link rel="stylesheet" href="assets/looks.css">
|
|
95
|
+
<link rel="stylesheet" href="assets/charts.css">
|
|
96
|
+
<link rel="stylesheet" href="assets/waitlist.css">
|
|
97
|
+
<script type="application/ld+json">${JSON.stringify(ld).replace(/</g, '\\u003c')}</script>
|
|
98
|
+
</head>
|
|
99
|
+
<body class="waitlist-page">
|
|
100
|
+
<div data-look-marquee aria-hidden="true"><span>${esc(s.marquee)}</span></div>
|
|
101
|
+
<main class="container">
|
|
102
|
+
<header class="waitlist-hero stack" data-space="lg">
|
|
103
|
+
<p class="waitlist-kicker"><span class="badge">${esc(s.kicker)}</span></p>
|
|
104
|
+
<h1>${esc(s.title)}</h1>
|
|
105
|
+
<p class="waitlist-tagline">${esc(s.tagline)}</p>
|
|
106
|
+
${about}
|
|
107
|
+
<waitlist-form dn="${esc(s.dn)}" api="${esc(s.api)}" button="${esc(s.button)}">
|
|
108
|
+
<form class="stack" method="post" action="${esc(s.api)}/api/waitlist"><label for="wl-email">Email</label>
|
|
109
|
+
<div class="field-group"><input id="wl-email" name="email" type="email" autocomplete="email" required><button type="submit">${esc(s.button)}</button></div></form>
|
|
110
|
+
</waitlist-form>
|
|
111
|
+
</header>
|
|
112
|
+
<div class="grid" data-columns="2">
|
|
113
|
+
${points ? `<div class="card">${points}</div>` : ''}
|
|
114
|
+
<section class="card stack" aria-labelledby="count"><h2 id="count">Who's waiting</h2>
|
|
115
|
+
<waitlist-stats dn="${esc(s.dn)}" api="${esc(s.api)}" days="30"></waitlist-stats>
|
|
116
|
+
</section>
|
|
117
|
+
</div>
|
|
118
|
+
<p class="waitlist-meta">${s.moshpit ? `Also at <a href="https://${esc(s.name)}">https://${esc(s.name)}</a> on the Moshpit. ` : ''}One email when it opens, nothing else. Hosted on <a href="https://c0mpute.com/hosting">c0mpute</a>.</p>
|
|
119
|
+
</main>
|
|
120
|
+
<footer class="site-footer container"><p class="waitlist-meta">${esc(s.title)} · <a href="https://pit.world/directory">pit.world directory</a></p></footer>
|
|
121
|
+
${footers}
|
|
122
|
+
<script src="assets/charts.global.js"></script>
|
|
123
|
+
<script type="module" src="assets/waitlist.js"></script>
|
|
124
|
+
${s.crawlproof ? `<script defer data-site="${esc(s.crawlproof)}" src="https://crawlproof.com/stats.js"></script>` : ''}
|
|
125
|
+
</body>
|
|
126
|
+
</html>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function iconSvg(name) {
|
|
131
|
+
const ch = esc((name.match(/[a-z0-9]/i) || ['?'])[0].toUpperCase());
|
|
132
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="#111"/><text x="32" y="44" text-anchor="middle" font-family="ui-monospace,monospace" font-size="36" font-weight="700" fill="#7CFC00">${ch}</text></svg>\n`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Render the shared footers for a host: the Profullstack webring row, then (Moshpit names only) the pit.world footer. */
|
|
136
|
+
export async function renderFooters(s, { fetchImpl = globalThis.fetch } = {}) {
|
|
137
|
+
let out = '';
|
|
138
|
+
try {
|
|
139
|
+
const { footerHtml } = await import('@profullstack/footer');
|
|
140
|
+
out += await footerHtml({ site: `https://${s.host}/`, since: 2026 });
|
|
141
|
+
} catch (err) {
|
|
142
|
+
process.emitWarning(`webring footer skipped for ${s.host}: ${err.message}`);
|
|
143
|
+
}
|
|
144
|
+
if (s.moshpit) {
|
|
145
|
+
try {
|
|
146
|
+
const res = await fetchImpl(`https://pit.world/snippets/footer.html?site=${encodeURIComponent(s.host)}`);
|
|
147
|
+
if (res.ok) out += '\n' + (await res.text());
|
|
148
|
+
} catch (err) {
|
|
149
|
+
process.emitWarning(`pit.world footer skipped for ${s.host}: ${err.message}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Write the site for one spec into `out`. Returns the normalized spec. */
|
|
156
|
+
export async function buildSite(spec, out, { footers = true, fetchImpl } = {}) {
|
|
157
|
+
const s = normalize(spec);
|
|
158
|
+
await mkdir(join(out, 'assets'), { recursive: true });
|
|
159
|
+
await mkdir(join(out, '.well-known'), { recursive: true });
|
|
160
|
+
const cssDir = dirname(require.resolve('@profullstack/css/css'));
|
|
161
|
+
for (const f of ['profullstack.css', 'tokens.css', 'widgets.css', 'platform.css', 'looks.css']) await copyFile(join(cssDir, f), join(out, 'assets', f));
|
|
162
|
+
const chartsDir = dirname(require.resolve('@profullstack/charts/global'));
|
|
163
|
+
await copyFile(join(chartsDir, 'charts.global.js'), join(out, 'assets', 'charts.global.js'));
|
|
164
|
+
await copyFile(join(chartsDir, 'charts.css'), join(out, 'assets', 'charts.css'));
|
|
165
|
+
await copyFile(join(here, 'index.js'), join(out, 'assets', 'waitlist.js'));
|
|
166
|
+
await copyFile(join(here, 'waitlist.css'), join(out, 'assets', 'waitlist.css'));
|
|
167
|
+
await writeFile(join(out, 'assets', 'icon.svg'), iconSvg(s.name));
|
|
168
|
+
const foot = footers ? await renderFooters(s, { fetchImpl }) : '';
|
|
169
|
+
const html = pageHtml(s, { footers: foot });
|
|
170
|
+
await writeFile(join(out, 'index.html'), html);
|
|
171
|
+
await writeFile(join(out, '404.html'), html);
|
|
172
|
+
await writeFile(join(out, 'robots.txt'), `User-agent: *\nAllow: /\nSitemap: https://${s.host}/sitemap.xml\n`);
|
|
173
|
+
await writeFile(join(out, 'sitemap.xml'), `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://${s.host}/</loc></url></urlset>\n`);
|
|
174
|
+
await writeFile(join(out, '.well-known', 'openwebring.json'), JSON.stringify({ name: s.title, url: `https://${s.host}/`, ring: 'profullstack', description: s.tagline }, null, 2) + '\n');
|
|
175
|
+
return s;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Build many: specs is an array; each lands in `${outRoot}/${name}`. */
|
|
179
|
+
export async function buildMany(specs, outRoot, opts = {}) {
|
|
180
|
+
const done = [];
|
|
181
|
+
for (const spec of specs) done.push(await buildSite(spec, join(outRoot, spec.name), opts));
|
|
182
|
+
return done;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function readSpecs(file) {
|
|
186
|
+
const data = JSON.parse(await readFile(file, 'utf8'));
|
|
187
|
+
return Array.isArray(data) ? data : data.sites;
|
|
188
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @profullstack/waitlist: the browser side.
|
|
3
|
+
*
|
|
4
|
+
* <waitlist-form dn="alt.atheism"></waitlist-form>
|
|
5
|
+
* <waitlist-stats dn="alt.atheism"></waitlist-stats>
|
|
6
|
+
* <script type="module">import '@profullstack/waitlist';</script>
|
|
7
|
+
*
|
|
8
|
+
* Signups go to the house waitlist API (moshcoding.com, double opt-in, one list per
|
|
9
|
+
* domain, shown to the domain owner in the moshcoding dashboard). Point `api` at any
|
|
10
|
+
* server that speaks the same two routes:
|
|
11
|
+
* POST {api}/api/waitlist {email, dn, ref?} -> {ok, pending, already} | {error}
|
|
12
|
+
* GET {api}/api/waitlist/stats ?dn=&days= -> {total, verified, days:[{day,n}]}
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const DEFAULT_API = 'https://moshcoding.com';
|
|
16
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
|
|
17
|
+
|
|
18
|
+
/** Trimmed email when it looks valid, else null. */
|
|
19
|
+
export function cleanEmail(raw) {
|
|
20
|
+
const e = String(raw ?? '').trim();
|
|
21
|
+
return EMAIL_RE.test(e) && e.length <= 254 ? e : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** ?ref=<code> from a URL, URL-safe and bounded, or null. */
|
|
25
|
+
export function refFrom(href) {
|
|
26
|
+
try {
|
|
27
|
+
const r = new URL(href).searchParams.get('ref') || '';
|
|
28
|
+
return r.replace(/[^A-Za-z0-9_-]/g, '').slice(0, 64) || null;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The message to show for an API answer. */
|
|
35
|
+
export function messageFor(res, email) {
|
|
36
|
+
if (res && res.ok) {
|
|
37
|
+
if (res.pending) return { tone: 'success', text: `Almost there: we sent a confirmation link to ${email}.` };
|
|
38
|
+
if (res.already) return { tone: 'success', text: `${email} is already on the list.` };
|
|
39
|
+
return { tone: 'success', text: `You're on the list, ${email}.` };
|
|
40
|
+
}
|
|
41
|
+
return { tone: 'danger', text: (res && res.error) || 'Could not save that. Try again.' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** POST one signup. Resolves to the API body plus `status`; never throws on HTTP errors. */
|
|
45
|
+
export async function join({ email, dn, ref = null, api = DEFAULT_API, fetchImpl = globalThis.fetch }) {
|
|
46
|
+
const clean = cleanEmail(email);
|
|
47
|
+
if (!clean) return { ok: false, status: 400, error: "That doesn't look like an email." };
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetchImpl(new URL('/api/waitlist', api).href, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { 'content-type': 'application/json' },
|
|
52
|
+
body: JSON.stringify({ email: clean, dn, ref }),
|
|
53
|
+
});
|
|
54
|
+
const body = await res.json().catch(() => ({}));
|
|
55
|
+
return { ...body, ok: Boolean(res.ok && body.ok), status: res.status };
|
|
56
|
+
} catch (err) {
|
|
57
|
+
return { ok: false, status: 0, error: 'Could not reach the waitlist. Try again.' };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** GET the public, email-free counts for a domain. Null when unavailable. */
|
|
62
|
+
export async function stats({ dn, days = 30, api = DEFAULT_API, fetchImpl = globalThis.fetch }) {
|
|
63
|
+
try {
|
|
64
|
+
const u = new URL('/api/waitlist/stats', api);
|
|
65
|
+
u.searchParams.set('dn', dn);
|
|
66
|
+
u.searchParams.set('days', String(days));
|
|
67
|
+
const res = await fetchImpl(u.href);
|
|
68
|
+
if (!res.ok) return null;
|
|
69
|
+
return await res.json();
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const HTMLElementBase = globalThis.HTMLElement ?? class {};
|
|
76
|
+
|
|
77
|
+
/** <waitlist-form dn="name" [api] [button] [placeholder] [label]>: light DOM, styled by @profullstack/css. */
|
|
78
|
+
export class WaitlistForm extends HTMLElementBase {
|
|
79
|
+
connectedCallback() {
|
|
80
|
+
if (this.dataset.ready) return;
|
|
81
|
+
this.dataset.ready = '1';
|
|
82
|
+
const id = `wl-${Math.random().toString(36).slice(2, 8)}`;
|
|
83
|
+
this.innerHTML = `
|
|
84
|
+
<form class="stack waitlist-form" novalidate>
|
|
85
|
+
<label for="${id}">${esc(this.getAttribute('label') || 'Email')}</label>
|
|
86
|
+
<div class="field-group">
|
|
87
|
+
<input id="${id}" name="email" type="email" autocomplete="email" required
|
|
88
|
+
placeholder="${esc(this.getAttribute('placeholder') || 'you@example.com')}" aria-describedby="${id}-msg">
|
|
89
|
+
<button type="submit">${esc(this.getAttribute('button') || 'Join the waitlist')}</button>
|
|
90
|
+
</div>
|
|
91
|
+
<p id="${id}-msg" class="alert" role="status" hidden></p>
|
|
92
|
+
</form>`;
|
|
93
|
+
const form = this.querySelector('form');
|
|
94
|
+
const input = this.querySelector('input');
|
|
95
|
+
const button = this.querySelector('button');
|
|
96
|
+
const msg = this.querySelector('[role="status"]');
|
|
97
|
+
const say = ({ tone, text }) => {
|
|
98
|
+
msg.hidden = false;
|
|
99
|
+
msg.dataset.tone = tone;
|
|
100
|
+
msg.textContent = text;
|
|
101
|
+
input.setAttribute('aria-invalid', tone === 'danger' ? 'true' : 'false');
|
|
102
|
+
};
|
|
103
|
+
form.addEventListener('submit', async (e) => {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
const email = cleanEmail(input.value);
|
|
106
|
+
if (!email) return say({ tone: 'danger', text: "That doesn't look like an email." });
|
|
107
|
+
button.disabled = true;
|
|
108
|
+
say({ tone: 'warning', text: 'Saving…' });
|
|
109
|
+
const res = await join({
|
|
110
|
+
email,
|
|
111
|
+
dn: this.getAttribute('dn') || location.hostname,
|
|
112
|
+
ref: refFrom(location.href),
|
|
113
|
+
api: this.getAttribute('api') || DEFAULT_API,
|
|
114
|
+
});
|
|
115
|
+
say(messageFor(res, email));
|
|
116
|
+
button.disabled = false;
|
|
117
|
+
if (res.ok) {
|
|
118
|
+
form.reset();
|
|
119
|
+
this.dispatchEvent(new CustomEvent('waitlist:joined', { bubbles: true, detail: { email, ...res } }));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* <waitlist-stats dn="name" [api] [days]>: a KPI and a per-day bar chart drawn with
|
|
127
|
+
* @profullstack/charts (window.pfcharts from charts.global.js, else the ESM bundle).
|
|
128
|
+
* Refreshes after a signup on the same page.
|
|
129
|
+
*/
|
|
130
|
+
export class WaitlistStats extends HTMLElementBase {
|
|
131
|
+
connectedCallback() {
|
|
132
|
+
if (this.dataset.ready) return;
|
|
133
|
+
this.dataset.ready = '1';
|
|
134
|
+
this.innerHTML = `<div class="stack waitlist-stats"><div data-kpi></div><div data-chart></div><p data-empty hidden></p></div>`;
|
|
135
|
+
this.refresh();
|
|
136
|
+
document.addEventListener('waitlist:joined', () => setTimeout(() => this.refresh(), 800));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async refresh() {
|
|
140
|
+
const dn = this.getAttribute('dn') || location.hostname;
|
|
141
|
+
const s = await stats({ dn, days: Number(this.getAttribute('days')) || 30, api: this.getAttribute('api') || DEFAULT_API });
|
|
142
|
+
const kpi = this.querySelector('[data-kpi]');
|
|
143
|
+
const chartEl = this.querySelector('[data-chart]');
|
|
144
|
+
const empty = this.querySelector('[data-empty]');
|
|
145
|
+
if (!s) {
|
|
146
|
+
kpi.textContent = '';
|
|
147
|
+
chartEl.hidden = true;
|
|
148
|
+
empty.hidden = false;
|
|
149
|
+
empty.textContent = 'The list is open. Be one of the first.';
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const charts = await loadCharts();
|
|
153
|
+
const series = s.days.map((d) => ({ day: d.day.slice(5), signups: d.n }));
|
|
154
|
+
if (!charts) {
|
|
155
|
+
kpi.textContent = `${s.total} on the waitlist`;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (this._kpi) this._kpi.update({ value: s.total, trend: s.days.map((d) => d.n) });
|
|
159
|
+
else this._kpi = charts(kpi).chart('stat', { value: s.total, trend: s.days.map((d) => d.n) }, { title: 'On the waitlist', table: false });
|
|
160
|
+
if (s.total === 0) {
|
|
161
|
+
empty.hidden = false;
|
|
162
|
+
empty.textContent = 'Nobody yet. Be the first.';
|
|
163
|
+
chartEl.hidden = true;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
empty.hidden = true;
|
|
167
|
+
chartEl.hidden = false;
|
|
168
|
+
const opts = { title: `Signups, last ${s.days.length} days`, height: 180, format: 'd', legend: false };
|
|
169
|
+
if (this._chart) this._chart.update(series, opts);
|
|
170
|
+
else this._chart = charts(chartEl).chart('bar', series, opts);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The charts `$` from charts.global.js (window.pfcharts) or the ESM bundle; null when neither loads. */
|
|
175
|
+
export function chartsFn(g) {
|
|
176
|
+
if (typeof g === 'function') return g;
|
|
177
|
+
if (g && typeof g.default === 'function') return g.default;
|
|
178
|
+
if (g && typeof g.$ === 'function') return g.$;
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function loadCharts() {
|
|
183
|
+
const fromGlobal = chartsFn(globalThis.pfcharts);
|
|
184
|
+
if (fromGlobal) return fromGlobal;
|
|
185
|
+
try {
|
|
186
|
+
return chartsFn(await import('@profullstack/charts/bundle'));
|
|
187
|
+
} catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function esc(s) {
|
|
193
|
+
return String(s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Background effects for the louder looks: matrix rain on a canvas. Static (one
|
|
198
|
+
* frame) under prefers-reduced-motion, so the look survives without the motion.
|
|
199
|
+
*/
|
|
200
|
+
export function startLookEffects(doc = globalThis.document) {
|
|
201
|
+
if (!doc || !doc.documentElement) return;
|
|
202
|
+
const look = doc.documentElement.dataset.look;
|
|
203
|
+
if (look !== 'matrix' || doc.querySelector('canvas[data-look-fx]')) return;
|
|
204
|
+
const c = doc.createElement('canvas');
|
|
205
|
+
c.setAttribute('data-look-fx', '');
|
|
206
|
+
c.setAttribute('aria-hidden', 'true');
|
|
207
|
+
doc.body.prepend(c);
|
|
208
|
+
const ctx = c.getContext('2d');
|
|
209
|
+
if (!ctx) return;
|
|
210
|
+
const glyphs = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ<>/$#*+=:;{}[]|';
|
|
211
|
+
const size = 16;
|
|
212
|
+
let drops = [];
|
|
213
|
+
const resize = () => {
|
|
214
|
+
c.width = innerWidth;
|
|
215
|
+
c.height = innerHeight;
|
|
216
|
+
drops = Array.from({ length: Math.ceil(c.width / size) }, () => Math.random() * -50);
|
|
217
|
+
};
|
|
218
|
+
resize();
|
|
219
|
+
addEventListener('resize', resize);
|
|
220
|
+
const frame = () => {
|
|
221
|
+
ctx.fillStyle = 'rgba(0,0,0,0.08)';
|
|
222
|
+
ctx.fillRect(0, 0, c.width, c.height);
|
|
223
|
+
ctx.font = `${size}px monospace`;
|
|
224
|
+
drops.forEach((y, i) => {
|
|
225
|
+
ctx.fillStyle = Math.random() > 0.975 ? '#d7ffe0' : '#00ff41';
|
|
226
|
+
ctx.fillText(glyphs[(Math.random() * glyphs.length) | 0], i * size, y * size);
|
|
227
|
+
drops[i] = y * size > c.height && Math.random() > 0.975 ? 0 : y + 1;
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
231
|
+
for (let i = 0; i < 80; i++) frame();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
setInterval(frame, 55);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Register the elements (runs on import in a browser). */
|
|
238
|
+
export function defineWaitlist() {
|
|
239
|
+
if (!globalThis.customElements) return;
|
|
240
|
+
if (!customElements.get('waitlist-form')) customElements.define('waitlist-form', WaitlistForm);
|
|
241
|
+
if (!customElements.get('waitlist-stats')) customElements.define('waitlist-stats', WaitlistStats);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
defineWaitlist();
|
|
245
|
+
if (globalThis.document) {
|
|
246
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => startLookEffects());
|
|
247
|
+
else startLookEffects();
|
|
248
|
+
}
|
package/src/waitlist.css
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* @profullstack/waitlist: page layer on top of @profullstack/css tokens (--pf-*). */
|
|
2
|
+
.waitlist-page { min-height: 100dvh; display: flex; flex-direction: column; }
|
|
3
|
+
.waitlist-page > main { flex: 1; }
|
|
4
|
+
.waitlist-hero { padding-block: clamp(2.5rem, 8vw, 6rem) 2rem; }
|
|
5
|
+
.waitlist-hero h1 { font-size: clamp(2.2rem, 6vw, 4rem); line-height: 1.05; letter-spacing: -0.02em; margin: 0; overflow-wrap: anywhere; }
|
|
6
|
+
.waitlist-hero .waitlist-tagline { font-size: clamp(1.1rem, 2.4vw, 1.45rem); color: var(--pf-color-muted, inherit); max-width: 40rem; }
|
|
7
|
+
.waitlist-kicker { font-family: var(--pf-font-mono, ui-monospace, monospace); font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; }
|
|
8
|
+
.waitlist-form .field-group { max-width: 34rem; }
|
|
9
|
+
.waitlist-form .field-group input { flex: 1; min-width: 0; }
|
|
10
|
+
.waitlist-points li { margin-block: 0.35rem; }
|
|
11
|
+
.waitlist-stats [data-empty] { color: var(--pf-color-muted, inherit); margin: 0; }
|
|
12
|
+
.waitlist-meta { font-size: 0.9rem; color: var(--pf-color-muted, inherit); }
|
|
13
|
+
|
|
14
|
+
/* Looks (neon, matrix, terminal, amber, synthwave, geocities, vaporwave) come from
|
|
15
|
+
@profullstack/css/looks: <html data-look="...">. Only page tweaks live here. */
|
|
16
|
+
[data-look] .waitlist-hero h1 { font-size: clamp(2.2rem, 7vw, 4.5rem); }
|