Skip to content

Commit 6b7ae04

Browse files
authored
fix(ipxStatic): strip repeated slashes from image path (#1801)
1 parent 393ec8a commit 6b7ae04

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/runtime/providers/ipx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { joinURL, encodePath, encodeParam } from 'ufo'
22
import type { ProviderGetImage } from '../../module'
33
import { createOperationsGenerator } from '#image'
44

5-
const operationsGenerator = createOperationsGenerator({
5+
export const operationsGenerator = createOperationsGenerator({
66
keyMap: {
77
format: 'f',
88
fit: 'fit',

src/runtime/providers/ipxStatic.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
export * from './ipx'
1+
import { joinURL, encodePath } from 'ufo'
2+
import type { ProviderGetImage } from '../../module'
3+
import { operationsGenerator } from './ipx'
4+
5+
export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL } = {}, ctx) => {
6+
if (modifiers.width && modifiers.height) {
7+
modifiers.resize = `${modifiers.width}x${modifiers.height}`
8+
delete modifiers.width
9+
delete modifiers.height
10+
}
11+
12+
const params = operationsGenerator(modifiers) || '_'
13+
14+
if (!baseURL) {
15+
baseURL = joinURL(ctx.options.nuxt.baseURL, '/_ipx')
16+
}
17+
18+
return {
19+
url: joinURL(baseURL, params, encodePath(src).replace(/\/{2,}/g, '/')),
20+
}
21+
}
22+
23+
export { validateDomains, supportsAlias } from './ipx'

0 commit comments

Comments
 (0)