Skip to content

Commit 4cee7a0

Browse files
committed
chore: avoid creating sub-folders
1 parent 0ed3eaf commit 4cee7a0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

adex/runtime/client.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ const baseURL = import.meta.env.BASE_URL ?? '/'
1616

1717
const normalizeURLPath = url => (url ? join(baseURL, url) : undefined)
1818

19+
const removeBaseURL = url => {
20+
if (typeof url !== 'string') {
21+
return undefined
22+
}
23+
24+
if (url.startsWith(baseURL)) {
25+
const result = url.slice(baseURL.length)
26+
return result === '' ? '/' : result
27+
}
28+
29+
const baseURLWithoutSlash = baseURL.endsWith('/')
30+
? baseURL.slice(0, -1)
31+
: baseURL
32+
33+
if (url.startsWith(baseURLWithoutSlash)) {
34+
const result = url.slice(baseURLWithoutSlash.length)
35+
return result === '' ? '/' : result
36+
}
37+
38+
return undefined
39+
}
40+
1941
// @ts-expect-error injected by vite
2042
import { routes } from '~routes'
2143

@@ -60,6 +82,8 @@ export const prerender = async ({ url }) => {
6082

6183
return {
6284
html,
63-
links: new Set([...(discoveredLinks ?? [])]),
85+
links: new Set(
86+
[...discoveredLinks].map(d => removeBaseURL(d)).filter(Boolean)
87+
),
6488
}
6589
}

0 commit comments

Comments
 (0)