-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerender.js
More file actions
41 lines (31 loc) · 1.28 KB
/
prerender.js
File metadata and controls
41 lines (31 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const toAbsolute = (p) => path.resolve(__dirname, p);
const template = fs.readFileSync(toAbsolute('dist/client/index.html'), 'utf-8');
const { render } = await import('./dist/server/entry-server.js');
// Routes to pre-render
const routesToPrerender = ['/', '/projects', '/work', '/education', '/resume'];
// Pre-render each route
(async () => {
for (const url of routesToPrerender) {
const rendered = render(url);
// Debug: Check what we're getting from helmet
console.log(`\nRendering ${url}:`)
console.log('Head content length:', rendered.head?.length || 0);
if (rendered.head) {
console.log('First 200 chars of head:', rendered.head.substring(0, 200));
}
const html = template
.replace(`<!--app-head-->`, rendered.head ?? '')
.replace(`<!--app-html-->`, rendered.html ?? '');
const filePath = `dist/client${url === '/' ? '/index' : url}.html`;
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(toAbsolute(filePath), html);
console.log('pre-rendered:', filePath);
}
})();