Skip to content

Commit 71e8efe

Browse files
committed
fixup!
1 parent 187edc2 commit 71e8efe

File tree

6 files changed

+33
-42
lines changed

6 files changed

+33
-42
lines changed

package-lock.json

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generators/jsx-ast/generate.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { buildSideBarProps } from './utils/buildBarProps.mjs';
22
import buildContent from './utils/buildContent.mjs';
33
import { getSortedHeadNodes } from './utils/getSortedHeadNodes.mjs';
4-
import { href } from '../../utils/file.mjs';
54
import { groupNodesByModule } from '../../utils/generators.mjs';
65
import { getRemarkRecma } from '../../utils/remark.mjs';
6+
import { href } from '../../utils/url.mjs';
77

88
const remarkRecma = getRemarkRecma();
99

src/generators/metadata/utils/parse.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import {
1919
visitTextWithUnixManualNode,
2020
visitYAML,
2121
} from './visitors.mjs';
22-
import { href } from '../../../utils/file.mjs';
2322
import { UNIST } from '../../../utils/queries/index.mjs';
2423
import { getRemark } from '../../../utils/remark.mjs';
24+
import { href } from '../../../utils/url.mjs';
2525
import { IGNORE_STABILITY_STEMS } from '../constants.mjs';
2626

2727
// Creates an instance of the Remark processor with GFM support

src/generators/web/utils/processing.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { randomUUID } from 'node:crypto';
2-
import { sep } from 'node:path/posix';
32

43
import { jsx, toJs } from 'estree-util-to-js';
54
import { transform } from 'lightningcss-wasm';
65

76
import bundleCode from './bundle.mjs';
87
import { createChunkedRequire } from './chunks.mjs';
98
import { minifyHTML } from '../../../utils/html-minifier.mjs';
9+
import { href } from '../../../utils/url.mjs';
1010
import { SPECULATION_RULES } from '../constants.mjs';
1111

1212
/**
@@ -113,16 +113,16 @@ export async function processJSXEntries(
113113
const results = await Promise.all(
114114
entries.map(async ({ data: { api, path, heading } }) => {
115115
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)}/`;
120117

121118
// Replace template placeholders with actual content
122119
const renderedHtml = template
123120
.replace('{{title}}', title)
124121
.replace('{{dehydrated}}', serverBundle.pages.get(`${api}.js`) ?? '')
125-
.replace('{{importMap}}', clientBundle.importMap ?? '')
122+
.replace(
123+
'{{importMap}}',
124+
clientBundle.importMap?.replaceAll('/', root) ?? ''
125+
)
126126
.replace('{{entrypoint}}', `${api}.js?${randomUUID()}`)
127127
.replace('{{speculationRules}}', SPECULATION_RULES)
128128
.replace('{{ogTitle}}', title)

src/utils/file.mjs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,3 @@ export const writeFile = (file, ...args) =>
1818
fs
1919
.mkdir(dirname(file), { recursive: true })
2020
.then(() => fs.writeFile(file, ...args));
21-
22-
/**
23-
* Kind of like `path.posix.relative`, however, this functions more like a URL resolution
24-
* @param {string} from
25-
* @param {string} to
26-
* @returns {string}
27-
*/
28-
export const href = (to, from) => {
29-
if (to.includes('://')) {
30-
return to;
31-
}
32-
33-
const a = to.split('/').filter(Boolean);
34-
const b = from.split('/').slice(0, -1).filter(Boolean);
35-
36-
while (a[0] === b[0]) {
37-
a.shift();
38-
b.shift();
39-
}
40-
41-
return [...b.map(() => '..'), ...a].join('/');
42-
};

src/utils/url.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,26 @@ export const importFromURL = async url => {
4646

4747
return imported.default ?? imported;
4848
};
49+
50+
/**
51+
* Kind of like `path.posix.relative`, however, this functions more like a URL resolution
52+
* @param {string} from
53+
* @param {string} to
54+
* @returns {string}
55+
*/
56+
export const href = (to, from) => {
57+
if (to.includes('://')) {
58+
return to;
59+
}
60+
61+
const a = to.split('/').filter(Boolean);
62+
const b = from.split('/').slice(0, -1).filter(Boolean);
63+
64+
while (a[0] !== undefined && a[0] === b[0]) {
65+
a.shift();
66+
b.shift();
67+
}
68+
69+
const rel = [...b.map(() => '..'), ...a].join('/');
70+
return rel || '.';
71+
};

0 commit comments

Comments
 (0)