-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
0 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
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,22 @@ | ||
--- | ||
menuTitle: Sanity | ||
title: Sanity Provider | ||
description: 'Nuxt Image has first class integration with Sanity' | ||
category: Providers | ||
--- | ||
|
||
Integration between [Sanity](https://www.sanity.io/docs/image-urls) and the image module. | ||
|
||
To use this provider you just need to specify the `projectId` of your project in Sanity. | ||
|
||
```js{}[nuxt.config.js] | ||
export default { | ||
image: { | ||
sanity: { | ||
projectId: 'yourprojectid', | ||
// Defaults to 'production' | ||
// dataset: 'development' | ||
} | ||
} | ||
} | ||
``` |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ const BuiltInProviders = [ | |
'imagekit', | ||
'imgix', | ||
'ipx', | ||
'sanity', | ||
'static', | ||
'twicpics', | ||
'storyblok', | ||
|
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,29 @@ | ||
import type { ProviderGetImage } from 'src' | ||
import { joinURL } from 'ufo' | ||
import { createOperationsGenerator } from '~image' | ||
|
||
const sanityCDN = 'https://cdn.sanity.io/images' | ||
|
||
const operationsGenerator = createOperationsGenerator({ | ||
keyMap: { | ||
background: 'b', | ||
height: 'h', | ||
quality: 'q', | ||
width: 'w' | ||
}, | ||
joinWith: '&', | ||
formatter: (key, value) => `${key}=${value}` | ||
}) | ||
|
||
export const getImage: ProviderGetImage = (src, { modifiers = {}, projectId, dataset = 'production' } = {}) => { | ||
const operations = operationsGenerator(modifiers) | ||
|
||
const parts = src.split('-').slice(1) | ||
const format = parts.pop() | ||
|
||
const filenameAndQueries = parts.join('-') + '.' + format + (operations ? ('?' + operations) : '') | ||
|
||
return { | ||
url: joinURL(sanityCDN, projectId, dataset, filenameAndQueries) | ||
} | ||
} |