Branchwell

Inkspring / website / scripts / check.mjs

1import { readFile, readdir, stat } from 'node:fs/promises';
2import assert from 'node:assert/strict';
3import { createHash } from 'node:crypto';
4for (const path of ['dist/index.html', 'dist/download.html', 'dist/help.html', 'dist/compare.html', 'dist/404.html', 'dist/privacy.html', 'dist/app-notices.html']) {
5 const html = await readFile(path, 'utf8');
6 assert.ok(html.includes('<main'), `${path} must contain prerendered content`);
7 assert.ok(html.includes('rel="canonical"'), `${path} needs a canonical URL`);
8 assert.doesNotMatch(html.replace(/href="https:\/\/(?!inkspring\.ai(?:\/|"))[^"]+"/g, ''), /\/api\//i);
9 assert.doesNotMatch(html, /\/auth\/sign-in|turnstile|supabase|googletagmanager|google-analytics/i);
10 assert.doesNotMatch(html, /<form|type="email"/);
11 assert.doesNotMatch(html, /<!--app-html-->|<!--seo-->/);
12 for (const tag of ['og:title', 'og:description', 'og:url', 'og:image', 'og:image:alt', 'twitter:card', 'twitter:image', 'application/ld+json']) assert.ok(html.includes(tag), `${path} needs ${tag}`);
13 assert.equal((html.match(/<title>/g) || []).length, 1, `${path} needs exactly one title`);
14}
15const html = await readFile('dist/index.html', 'utf8');
16const download = await readFile('dist/download.html', 'utf8');
17assert.match(html, /href="\/download"[^>]*><svg[^>]*class="mac-download-icon"[^>]*>.*?<\/svg>Download for Mac/);
18assert.doesNotMatch(html, /href="[^"]+\.dmg"/);
19assert.match(download, /How to install Inkspring/);
20const installer = download.match(/href="(\/updates\/[^"]+\.dmg)" download/);
21assert.ok(installer, 'Download page must link to the installer');
22const installerBytes = await readFile('dist' + installer[1]);
23assert.ok(download.includes(createHash('sha256').update(installerBytes).digest('hex')), 'Download page must show the installer checksum');
24const appcast = await readFile('dist/updates/appcast.xml', 'utf8');
25assert.ok(appcast.includes(`url="https://inkspring.ai${installer[1]}" length="${installerBytes.length}"`), 'Sparkle must use the same DMG as the download page');
26assert.ok((await readdir('dist/updates')).every(file => !file.endsWith('.zip')), 'The site must only distribute DMG installers');
27const missing = await readFile('dist/404.html', 'utf8');
28assert.match(missing, /name="robots" content="noindex, follow"/);
29assert.match(missing, /<h1>This page went missing\.<\/h1>/);
30const help = await readFile('dist/help.html', 'utf8');
31assert.match(help, /<h1>Inkspring Help<\/h1>/);
32for (const [, anchor] of help.matchAll(/href="#([^"]+)"/g)) {
33 assert.ok(help.includes(`id="${anchor}"`), `Help anchor #${anchor} needs a destination`);
34}
35for (const page of [html, download, help]) {
36 for (const asset of page.matchAll(/(?:src|href)="(\/[^"#?]+\.(?:js|css|png|jpg|svg|woff2))"/g)) await stat('dist' + asset[1]);
37}
38const comparePage = await readFile('dist/compare.html', 'utf8');
39assert.match(comparePage, /<h1>Inkspring compared with /);
40assert.match(comparePage, /"@type":"FAQPage"/, 'Compare page needs its FAQ data');
41const files = await readdir('dist');
42assert.ok(!files.includes('api') && !files.includes('server'));
43await stat('dist/og/inkspring-monochrome.png');
44for (const path of ['dist/index.html', 'dist/download.html', 'dist/help.html', 'dist/compare.html', 'dist/404.html', 'dist/privacy.html', 'dist/app-notices.html']) assert.doesNotMatch(await readFile(path, 'utf8'), /src="\/analytics\.js"|googletagmanager|data-analytics-settings/i);
45assert.doesNotMatch(await readFile('dist/index.html', 'utf8'), /projectatom\.ai/);
46assert.match(await readFile('dist/index.html', 'utf8'), /data-visitor-site="inkspring"/);
47console.log('Static page checks passed.');