-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add contentful provider (#398)
- Loading branch information
Showing
8 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: Contentful Provider | ||
description: 'Nuxt Image has first class integration with Contentful' | ||
navigation: | ||
title: Contentful | ||
--- | ||
|
||
Integration between [Contentful](https://www.contentful.com/) and the image module. | ||
|
||
To use this provider you just need to specify the base url of your service in Contentful. | ||
|
||
```js{}[nuxt.config.js] | ||
export default { | ||
image: { | ||
contentful: {} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { withBase, parseURL } from 'ufo' | ||
import type { ProviderGetImage } from 'src' | ||
import { createOperationsGenerator } from '~image' | ||
|
||
// https://www.contentful.com/developers/docs/references/images-api/ | ||
const contentfulCDN = 'https://images.ctfassets.net' | ||
|
||
export const operationsGenerator = createOperationsGenerator({ | ||
keyMap: { | ||
format: 'fm', | ||
width: 'w', | ||
height: 'h', | ||
focus: 'f', | ||
radius: 'r', | ||
quality: 'q', | ||
background: 'bg' | ||
}, | ||
valueMap: { | ||
format: { | ||
jpeg: 'jpg' | ||
}, | ||
fit: { | ||
cover: 'crop', | ||
contain: 'fill', | ||
fill: 'scale', | ||
thumbnail: 'thumb' | ||
} | ||
}, | ||
joinWith: '&', | ||
formatter: (key, value) => `${key}=${value}` | ||
}) | ||
|
||
export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = contentfulCDN } = {}) => { | ||
const operations = operationsGenerator(modifiers) | ||
|
||
const { pathname } = parseURL(src) | ||
const path = pathname + (operations ? ('?' + operations) : '') | ||
const url = withBase(path, baseURL) | ||
|
||
return { | ||
url | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters