-
Notifications
You must be signed in to change notification settings - Fork 253
/
ipx.ts
33 lines (28 loc) · 919 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
import { ProviderGetImage } from 'src'
import { joinURL, encodeQueryItem, encodePath } from 'ufo'
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) => encodeQueryItem(key, val)
})
export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = '/_ipx' } = {}, { nuxtContext: { base: nuxtBase = '/' } = {} }) => {
if (modifiers.width && modifiers.height) {
modifiers.resize = `${modifiers.width}_${modifiers.height}`
delete modifiers.width
delete modifiers.height
}
const params = operationsGenerator(modifiers)
return {
url: joinURL(nuxtBase, baseURL, encodePath(src) + (params ? '?' + params : ''))
}
}
export const validateDomains = true