Inkspring / website / scripts / prerender.mjs
| 1 | import { readFile, writeFile, mkdir } from 'node:fs/promises'; |
| 2 | import { render } from '../.ssr/render.js'; |
| 3 | import { pages, headTags } from './seo.mjs'; |
| 4 | const template = await readFile('dist/index.html', 'utf8'); |
| 5 | for (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 | } |
| 12 | await mkdir('dist/waitlist', { recursive: true }); |
| 13 | await 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>'); |
| 14 | console.log('Prerendered homepage, download, help, compare, privacy, app notices, 404, and legacy waitlist redirect as static HTML.'); |