Branchwell

Inkspring / website / scripts / prerender.mjs

1import { readFile, writeFile, mkdir } from 'node:fs/promises';
2import { render } from '../.ssr/render.js';
3import { pages, headTags } from './seo.mjs';
4const template = await readFile('dist/index.html', 'utf8');
5for (const path of Object.keys(pages)) {
6 const html = template.replace('<!--app-html-->', render(path))
7 .replace(/<title>.*?<\/title><!--seo-->/, headTags(path));
8 if (path === '/') await writeFile('dist/index.html', html);
9 else if (path === '/404') await writeFile('dist/404.html', html);
10 else { await writeFile(`dist${path}.html`, html); await mkdir(`dist${path}`, { recursive: true }); await writeFile(`dist${path}/index.html`, html); }
11}
12await mkdir('dist/waitlist', { recursive: true });
13await writeFile('dist/waitlist/index.html', '<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="refresh" content="0;url=/"><link rel="canonical" href="https://inkspring.ai/"><title>Inkspring</title></head><body><a href="/">Inkspring has moved to the homepage.</a></body></html>');
14console.log('Prerendered homepage, download, help, compare, privacy, app notices, 404, and legacy waitlist redirect as static HTML.');