Skip to content

Commit

Permalink
feat: breaking, update configuration values to be camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Kjelkenes committed Oct 17, 2023
1 parent 36cb217 commit 8b55031
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@ There are many ways to configure the interface for image selection.

| Configuration key | Description | Type | Default value |
| ------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---------------- | ----------------- |
| IMAGE_MAX_SIZE | Max size of the image returned from imageshop to sanity. Format: WxH | string | 2048x2048 |
| IMAGE_ALIAS | Imageshop alias for permalink of image | string | "Large" |
| IMAGESHOPINTERFACENAME | Standard interface used when searching images. | string | |
| IMAGESHOPDOCUMENTPREFIX | Standard document code prefix used when uploading images. | string | |
| CULTURE | Language for the client. Supports en-US and nb-NO. Norwegian is default (nb-NO) | string | "nb-NO" |
| PROFILEID | Name of a profile, which has to be created by Imageshop, which will return several different sizes and aspect ratios. IMAGESHOPSIZE can not be used together with a profile, and showing size dialogue or crop dialogue doesn't make sense when using profiles. | string | |
| REQUIREDUPLOADFIELDS | String indicating upload fields which are required, separated by comma. Possible values: name, description, rights, credits, tags | string | |
| UPLOADFIELDLANGUAGES | List of languages which should be shown for name, description etc. Default = no,en. | string | |
| SANITY_ASSET_TEXT_LANGUAGE | What language to store in sanity, from the title, description and credit fields | string | "no" |
| IMAGE_FIELDS_MAPPING | A mapping of IMAGE_SHOP_FIELD_NAME: SANITY_FIELD_NAME. Example: `{"description": "altText", "credits": "credits"}`. Fields will be imported on the image object as extra fields. Useful for e.g. altText. | object:{ string: string } | {} |

| imageMaxSize | Max size of the image returned from imageshop to sanity. Format: WxH | string | 2048x2048 |
| imageAlias | Imageshop alias for permalink of image | string | "Large" |
| imageShopInterfaceName | Standard interface used when searching images. | string | |
| imageShopDocumentPrefix | Standard document code prefix used when uploading images. | string | |
| culture | Language for the client. Supports en-US and nb-NO. Norwegian is default (nb-NO) | string | "nb-NO" |
| profileId | Name of a profile, which has to be created by Imageshop, which will return several different sizes and aspect ratios. IMAGESHOPSIZE can not be used together with a profile, and showing size dialogue or crop dialogue doesn't make sense when using profiles. | string | |
| requiredUploadFields | String indicating upload fields which are required, separated by comma. Possible values: name, description, rights, credits, tags | string | |
| uploadFieldLanguages | List of languages which should be shown for name, description etc. Default = no,en. | string | |
| sanityAssetTextLanguage | What language to store in sanity, from the title, description and credit fields | string | "no" |


## Enable multi batch upload
Expand Down
35 changes: 33 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ export const imageShopAssetSource: AssetSource = {
icon: Icon,
}

export interface ExternalImageShopPluginConfig {
sanityAssetTextLanguage?: string
imageShopInterfaceName?: string
imageShopDocumentPrefix?: string
culture?: string
profileId?: string
requiredUploadFields?: string
uploadFieldLanguages?: string
imageAlias?: string
imageMaxSize?: string
// custom hooks
languageResolver?: LanguageResolver
fieldMapper?: FieldMapper
}

export interface ImageShopPluginConfig {
SANITY_ASSET_TEXT_LANGUAGE?: string
IMAGESHOPINTERFACENAME?: string
Expand All @@ -35,16 +50,32 @@ export interface ImageShopPluginConfig {
languageResolver?: LanguageResolver
fieldMapper?: FieldMapper
}

const mapExternalConfigToInternal = (
external: ExternalImageShopPluginConfig,
): ImageShopPluginConfig => ({
SANITY_ASSET_TEXT_LANGUAGE: external.sanityAssetTextLanguage,
IMAGESHOPINTERFACENAME: external.imageShopInterfaceName,
IMAGESHOPDOCUMENTPREFIX: external.imageShopDocumentPrefix,
CULTURE: external.culture,
PROFILEID: external.profileId,
REQUIREDUPLOADFIELDS: external.requiredUploadFields,
IMAGE_ALIAS: external.imageAlias,
IMAGE_MAX_SIZE: external.imageMaxSize,
languageResolver: external.languageResolver,
fieldMapper: external.fieldMapper,
})
/**
* @public
*/
export const imageShopAsset = definePlugin<ImageShopPluginConfig>((config = {}) => {
export const imageShopAsset = definePlugin<ExternalImageShopPluginConfig>((config = {}) => {
const mappedConfig = mapExternalConfigToInternal(config)
return {
name: 'sanity-plugin-asset-source-imageshop',

studio: {
components: {
layout: (props) => layoutResolver(props, config),
layout: (props) => layoutResolver(props, mappedConfig),
},
},
form: {
Expand Down

0 comments on commit 8b55031

Please sign in to comment.