Inkspring / website / scripts / check.mjs
| 1 | import { readFile, readdir, stat } from 'node:fs/promises'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { createHash } from 'node:crypto'; |
| 4 | for (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 | } |
| 15 | const html = await readFile('dist/index.html', 'utf8'); |
| 16 | const download = await readFile('dist/download.html', 'utf8'); |
| 17 | assert.match(html, /href="\/download"[^>]*><svg[^>]*class="mac-download-icon"[^>]*>.*?<\/svg>Download for Mac/); |
| 18 | assert.doesNotMatch(html, /href="[^"]+\.dmg"/); |
| 19 | assert.match(download, /How to install Inkspring/); |
| 20 | const installer = download.match(/href="(\/updates\/[^"]+\.dmg)" download/); |
| 21 | assert.ok(installer, 'Download page must link to the installer'); |
| 22 | const installerBytes = await readFile('dist' + installer[1]); |
| 23 | assert.ok(download.includes(createHash('sha256').update(installerBytes).digest('hex')), 'Download page must show the installer checksum'); |
| 24 | const appcast = await readFile('dist/updates/appcast.xml', 'utf8'); |
| 25 | assert.ok(appcast.includes(`url="https://inkspring.ai${installer[1]}" length="${installerBytes.length}"`), 'Sparkle must use the same DMG as the download page'); |
| 26 | assert.ok((await readdir('dist/updates')).every(file => !file.endsWith('.zip')), 'The site must only distribute DMG installers'); |
| 27 | const missing = await readFile('dist/404.html', 'utf8'); |
| 28 | assert.match(missing, /name="robots" content="noindex, follow"/); |
| 29 | assert.match(missing, /<h1>This page went missing\.<\/h1>/); |
| 30 | const help = await readFile('dist/help.html', 'utf8'); |
| 31 | assert.match(help, /<h1>Inkspring Help<\/h1>/); |
| 32 | for (const [, anchor] of help.matchAll(/href="#([^"]+)"/g)) { |
| 33 | assert.ok(help.includes(`id="${anchor}"`), `Help anchor #${anchor} needs a destination`); |
| 34 | } |
| 35 | for (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 | } |
| 38 | const comparePage = await readFile('dist/compare.html', 'utf8'); |
| 39 | assert.match(comparePage, /<h1>Inkspring compared with /); |
| 40 | assert.match(comparePage, /"@type":"FAQPage"/, 'Compare page needs its FAQ data'); |
| 41 | const files = await readdir('dist'); |
| 42 | assert.ok(!files.includes('api') && !files.includes('server')); |
| 43 | await stat('dist/og/inkspring-monochrome.png'); |
| 44 | for (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); |
| 45 | assert.doesNotMatch(await readFile('dist/index.html', 'utf8'), /projectatom\.ai/); |
| 46 | assert.match(await readFile('dist/index.html', 'utf8'), /data-visitor-site="inkspring"/); |
| 47 | console.log('Static page checks passed.'); |