Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 21, 2022
1 parent 03e036b commit 3243bf8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
36 changes: 17 additions & 19 deletions docs/content/en/4.providers/cloudimage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,41 @@ export default {
}
}
```

**Note:** Current integration uses API `v7`.

## Options

You can override default options:

## token
### `token`

###### Type: **String** | Default: **"demo"** | _required_
- Type: **String** (required)
- Default: `demo`

Your Cloudimage customer token.
[Subscribe](https://www.cloudimage.io/en/register_page) for a
Cloudimage account to get one. The subscription takes less than a
minute and is totally free.
Your Cloudimage customer token. [register](https://www.cloudimage.io/en/register_page) for a Cloudimage account to get one. The subscription takes less than a minute and is totally free.

## baseURL
### `baseURL`

###### Type: **String** | _optional_
- Type: **String**

Your image folder on server; this alows to shorten your origin image URLs.
Your uploads base URL. This alows to shorten your origin image URLs.

```js{}[nuxt.config.js]
export default {
image: {
cloudimage: {
token: 'demo',
baseURL: 'https://cdn.scaleflex.it/demo/' // optional
baseURL: 'sample.li' // optional
}
}
}
```
## doNotReplaceURL

###### Type: **bool** | Default: **false**

If set to **true**, the plugin will only add query parameters to the provided image source URL.

## apiVersion
### `cdnURL`

###### Type: **String** | Default: **'v7'** | _optional_
Allow to use a specific version of API.
- Type: **String**
- Default: `https://{token}.cloudimg.io/v7`

## Cloudimage modifiers

Expand All @@ -74,4 +72,4 @@ Beside [the standard values for `fit` property](/components/nuxt-img#fit) of Nux

* `bound` - Resizes to a given width and height box and keeps proportions. Similar to fit but without adding padding.

* `boundmin` - Resizes an image while bounding the smaller dimension to the desired width or height while keeping proportions.
* `boundmin` - Resizes an image while bounding the smaller dimension to the desired width or height while keeping proportions.
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default <NuxtConfig> {
contentful: {},
cloudimage: {
token: 'demo',
baseURL: 'https://cdn.scaleflex.it/demo/'
baseURL: 'sample.li'
},
fastly: {
baseURL: 'https://www.fastly.io'
Expand Down
6 changes: 3 additions & 3 deletions playground/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,20 @@ export const providers: Provider[] = [
name: 'cloudimage',
samples: [
{
src: 'luca-bravo-121932.jpg',
src: 'bag.jpg',
width: 500,
height: 500,
fit: 'contain'
},
{
src: 'alain.jpg',
src: 'boat.jpg',
width: 800,
height: 800,
quality: 75,
fit: 'cover'
},
{
src: 'ameen-fahmy.jpg',
src: 'img.jpg',
width: 300,
height: 300,
format: 'webp',
Expand Down
16 changes: 9 additions & 7 deletions src/runtime/providers/cloudimage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { joinURL } from 'ufo'
import type { ProviderGetImage } from 'src'
import { createOperationsGenerator } from '~image'

const domain = 'cloudimg.io'
const operationsGenerator = createOperationsGenerator({
keyMap: {
fit: 'func',
Expand All @@ -22,15 +21,18 @@ const operationsGenerator = createOperationsGenerator({
formatter: (key, value) => `${key}=${value}`
})

// https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/introduction
export const getImage: ProviderGetImage = (src, {
modifiers = {}, baseURL = '',
token = 'demo', apiVersion = 'v7', doNotReplaceURL = false
modifiers = {},
baseURL = '',
token = 'demo',
cdnURL = ''
} = {}) => {
const operations = operationsGenerator(modifiers)
const finalDomain = token + '.' + domain
const finalUrl = doNotReplaceURL ? baseURL : `https://${finalDomain}/${apiVersion}/${baseURL}`

if (!cdnURL) {
cdnURL = `https://${token}.cloudimg.io/v7`
}
return {
url: joinURL(finalUrl, src + (operations ? ('?' + operations) : ''))
url: joinURL(cdnURL, baseURL, src) + (operations ? ('?' + operations) : '')
}
}

0 comments on commit 3243bf8

Please sign in to comment.