-
-
Notifications
You must be signed in to change notification settings - Fork 228
/
cmsimage.ts
41 lines (37 loc) · 1.03 KB
/
cmsimage.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
39
40
41
import ImgixClient from '@imgix/js-core';
/**
* It takes a path and folder and returns a URL to an image on Imgix
* @returns A URL to the Imgix image
* @example
* ```typescript
* const result = createCmsImage({
* path: 'sample.png',
* folder: 'wicker-baskets'})
* console.log(result)
* // => "https://example.imgix.net/wicker-baskets/sample.png?[...misc Imgix params]"
* ```
*/
export default function createCmsImage({
path,
folder,
settings = {},
}: CreateCmsImageProps) {
const client = new ImgixClient({
domain: 'virtualcoffeeio-cms.imgix.net',
});
return client.buildURL(`/${folder}/${path}`, {
auto: 'compress,format',
...settings,
});
}
type CreateCmsImageProps = {
/** The image file name */
path: string;
/** The preceding directory/directories before the file name */
folder: string;
/** Any other {@link https://docs.imgix.com/apis/rendering rendering options} for the Imgix library
* @defaultValue `{}`
*/
settings?: Record<string, any>;
};
createCmsImage({ path: '', folder: '', settings: {} });