-
Notifications
You must be signed in to change notification settings - Fork 270
/
ipx.ts
38 lines (32 loc) · 983 Bytes
/
ipx.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { joinURL, encodePath, encodeParam } from 'ufo'
import type { ProviderGetImage } from '../../module'
import { createOperationsGenerator } from '#image'
const operationsGenerator = createOperationsGenerator({
keyMap: {
format: 'f',
fit: 'fit',
width: 'w',
height: 'h',
resize: 's',
quality: 'q',
background: 'b',
},
joinWith: '&',
formatter: (key, val) => encodeParam(key) + '_' + encodeParam(val),
})
export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL } = {}, ctx) => {
if (modifiers.width && modifiers.height) {
modifiers.resize = `${modifiers.width}x${modifiers.height}`
delete modifiers.width
delete modifiers.height
}
const params = operationsGenerator(modifiers) || '_'
if (!baseURL) {
baseURL = joinURL(ctx.options.nuxt.baseURL, '/_ipx')
}
return {
url: joinURL(baseURL, params, encodePath(src)),
}
}
export const validateDomains = true
export const supportsAlias = true