|
1 | 1 | import { randomUUID } from 'node:crypto'; |
2 | 2 |
|
3 | | -import { minifySync } from '@swc/html'; |
4 | 3 | import { jsx, toJs } from 'estree-util-to-js'; |
5 | 4 | import { transform } from 'lightningcss'; |
6 | 5 |
|
7 | | -import { SPECULATION_RULES } from '../constants.mjs'; |
8 | 6 | import bundleCode from './bundle.mjs'; |
9 | 7 | import { createChunkedRequire } from './chunks.mjs'; |
| 8 | +import { minifyHTML } from '../../../utils/html-minifier.mjs'; |
| 9 | +import { SPECULATION_RULES } from '../constants.mjs'; |
10 | 10 |
|
11 | 11 | /** |
12 | 12 | * Converts JSX AST entries to server and client JavaScript code. |
@@ -109,24 +109,26 @@ export async function processJSXEntries( |
109 | 109 | const titleSuffix = `Node.js v${version.version} Documentation`; |
110 | 110 |
|
111 | 111 | // Step 3: Create final HTML (could be parallelized in workers) |
112 | | - const results = entries.map(({ data: { api, heading } }) => { |
113 | | - const fileName = `${api}.js`; |
114 | | - const title = `${heading.data.name} | ${titleSuffix}`; |
115 | | - |
116 | | - // Replace template placeholders with actual content |
117 | | - const renderedHtml = template |
118 | | - .replace('{{title}}', title) |
119 | | - .replace('{{dehydrated}}', serverBundle.pages.get(fileName) ?? '') |
120 | | - .replace('{{importMap}}', clientBundle.importMap ?? '') |
121 | | - .replace('{{entrypoint}}', `./${fileName}?${randomUUID()}`) |
122 | | - .replace('{{speculationRules}}', SPECULATION_RULES) |
123 | | - .replace('{{ogTitle}}', title); |
124 | | - |
125 | | - // Minify HTML (input must be a Buffer) |
126 | | - const { code: html } = minifySync(renderedHtml); |
127 | | - |
128 | | - return { html, api }; |
129 | | - }); |
| 112 | + const results = await Promise.all( |
| 113 | + entries.map(async ({ data: { api, heading } }) => { |
| 114 | + const fileName = `${api}.js`; |
| 115 | + const title = `${heading.data.name} | ${titleSuffix}`; |
| 116 | + |
| 117 | + // Replace template placeholders with actual content |
| 118 | + const renderedHtml = template |
| 119 | + .replace('{{title}}', title) |
| 120 | + .replace('{{dehydrated}}', serverBundle.pages.get(fileName) ?? '') |
| 121 | + .replace('{{importMap}}', clientBundle.importMap ?? '') |
| 122 | + .replace('{{entrypoint}}', `./${fileName}?${randomUUID()}`) |
| 123 | + .replace('{{speculationRules}}', SPECULATION_RULES) |
| 124 | + .replace('{{ogTitle}}', title); |
| 125 | + |
| 126 | + const minifiedHtml = await minifyHTML(renderedHtml); |
| 127 | + const html = Buffer.from(minifiedHtml); |
| 128 | + |
| 129 | + return { html, api }; |
| 130 | + }) |
| 131 | + ); |
130 | 132 |
|
131 | 133 | const { code: minifiedCSS } = transform({ |
132 | 134 | code: Buffer.from(`${serverBundle.css}\n${clientBundle.css}`), |
|
0 commit comments