By default, Transform will change the value of every target field in place using a set operation.
Image description
Targeting image fields
Images can be transformed to a textual description by targeting a string, text or Portable Text field (array with block)
with operation: {type: 'image-description'}.
Custom instructions for image description targets will be used to generate the description.
Such targets must be a descendant field of an image object.
target: {path: ['array', {_key: 'abc'}, 'alt'], operation: {type: 'image-description'} } //assuming the item in the array on the key-ed path is an image
target: {path: ['image'], include: ['portableTextField'], operation: {type: 'image-description'}, instruction: 'Use formatting and headings to describe the image in great detail' }
Targeting non-image fields
If the target image description lives outside an image object, use the sourcePath option to specify the path to the image field.
sourcePath must be an image or image asset field.
target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }
Targeting images outside the document (URL)
If the source image is available on a https URL outside the target document, it is possible to get a description for it using imageUrl.
set
by defaultBy default, Transform will change the value of every target field in place using a set operation.
Image description
Targeting image fields
Images can be transformed to a textual description by targeting a
string
,text
or Portable Text field (array
withblock
) withoperation: {type: 'image-description'}
.Custom instructions for image description targets will be used to generate the description.
Such targets must be a descendant field of an image object.
For example:
target: {path: ['image', 'description'], operation: {type: 'image-description'} }
target: {path: ['array', {_key: 'abc'}, 'alt'], operation: {type: 'image-description'} } //assuming the item in the array on the key-ed path is an image
target: {path: ['image'], include: ['portableTextField'], operation: {type: 'image-description'}, instruction: 'Use formatting and headings to describe the image in great detail' }
Targeting non-image fields
If the target image description lives outside an image object, use the
sourcePath
option to specify the path to the image field.sourcePath
must be an image or image asset field.For example:
target: {path: ['description'], operation: operation: {type: 'image-description', sourcePath: ['image', 'asset'] }
target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }
target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }
Targeting images outside the document (URL)
If the source image is available on a https URL outside the target document, it is possible to get a description for it using
imageUrl
.Example:
target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }