import { mkdir, readFile, writeFile } from 'node:fs/promises'; import { dirname, resolve } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; const productFeatureRoutes = [ '/product/content-planning', '/product/asset-revisions', '/product/comment-threads', '/product/approval-workflows', '/product/client-review', '/product/review-queues', '/product/audit-trail', '/product/workspace-access', '/product/team-collaboration', ]; const publicRoutes = ['/', '/product', ...productFeatureRoutes, '/pricing', '/blogs', '/guides']; const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const distDir = resolve(rootDir, 'dist'); const ssrEntry = resolve(rootDir, 'dist-ssr/entry-public-ssr.js'); const templatePath = resolve(distDir, 'index.html'); const template = await readFile(templatePath, 'utf8'); const { render } = await import(pathToFileURL(ssrEntry)); const baseTemplate = template.replace('Socialize', ''); function outputPathForRoute(route) { if (route === '/') { return resolve(distDir, 'index.html'); } return resolve(distDir, route.replace(/^\//, ''), 'index.html'); } for (const route of publicRoutes) { const { appHtml, headTags } = await render(route); const html = baseTemplate .replace('', `${headTags.headTags}\n`) .replace('
', `
${appHtml}
`); const outputPath = outputPathForRoute(route); await mkdir(dirname(outputPath), { recursive: true }); await writeFile(outputPath, html); console.log(`Prerendered ${route}`); }