|
1 | 1 | import { randomUUID } from 'node:crypto'; |
2 | | -import { sep } from 'node:path/posix'; |
3 | 2 |
|
4 | 3 | import { jsx, toJs } from 'estree-util-to-js'; |
5 | 4 | import { transform } from 'lightningcss-wasm'; |
6 | 5 |
|
7 | 6 | import bundleCode from './bundle.mjs'; |
8 | 7 | import { createChunkedRequire } from './chunks.mjs'; |
9 | 8 | import { minifyHTML } from '../../../utils/html-minifier.mjs'; |
| 9 | +import { href } from '../../../utils/url.mjs'; |
10 | 10 | import { SPECULATION_RULES } from '../constants.mjs'; |
11 | 11 |
|
12 | 12 | /** |
@@ -113,16 +113,16 @@ export async function processJSXEntries( |
113 | 113 | const results = await Promise.all( |
114 | 114 | entries.map(async ({ data: { api, path, heading } }) => { |
115 | 115 | const title = `${heading.data.name} | ${titleSuffix}`; |
116 | | - |
117 | | - // The number of occurances is 1 less than the length of the split |
118 | | - // We also remove 1 `/`, as the path begins with a `/` |
119 | | - const root = '../'.repeat(path.split(sep).length - 2) || './'; |
| 116 | + const root = `${href('/', path)}/`; |
120 | 117 |
|
121 | 118 | // Replace template placeholders with actual content |
122 | 119 | const renderedHtml = template |
123 | 120 | .replace('{{title}}', title) |
124 | 121 | .replace('{{dehydrated}}', serverBundle.pages.get(`${api}.js`) ?? '') |
125 | | - .replace('{{importMap}}', clientBundle.importMap ?? '') |
| 122 | + .replace( |
| 123 | + '{{importMap}}', |
| 124 | + clientBundle.importMap?.replaceAll('/', root) ?? '' |
| 125 | + ) |
126 | 126 | .replace('{{entrypoint}}', `${api}.js?${randomUUID()}`) |
127 | 127 | .replace('{{speculationRules}}', SPECULATION_RULES) |
128 | 128 | .replace('{{ogTitle}}', title) |
|
0 commit comments