Describe your question/issue in detail
I'm looking at importing content using the beta migration API. It's mostly looking good however i have one issue. Currently the content has images wrapped in an a tag on our existing content. However when importing it these links get removed. Leaving just the image with no sorrounding a tag.
Impacted feature
The migration API
What steps have you taken to resolve this issue already?
I've tried several approaches, im using the htmlAsRichText serializer with the following config:
serializer: {
// This allows us to perform an action when it serializes this node type. E.g. image it will create the asset on Prismic' CDN
img: ({ node }) => {
const src = node.properties.src
const filename = src.split('/').pop()
const alt = node.properties.alt
return {
type: 'image',
id: migration.createAsset(src, filename, { alt }),
linkTo: {
link_type: 'Web',
url: 'https://www.google.com',
target: '_blank'
}
}
},
Does the migration API support adding links to images, i can do it from the writing room so it appears it should be possible. The format for the rich text (the result of the serializer) that is being passed to the migrator appears to match the content returned when fetching content from Prismic. I've checked it against the same article written manually through the writing room.
I've tried a few other things along the way. I started out with a serializer for a and a seperate serializer for images but this just imports the image and the a is missing (presumably because the a has no text content.
Steps to reproduce
The content before being passed through the serializer looks like this:
<a href=\"https://example.com\" title=\"Book winter activities\" rel=\"follow noopener\" target=\"_blank\"><img src=\"https://cdn.buttercms.com/fqkbwYTguY6Gyy4Rg4Iw\" alt=\"Donutting \" width=\"957\" height=\"638\"></a></p>
After running through the serializer i have the following content:
{ type: 'image', id: PrismicMigrationAsset { asset: undefined, config: [Object], originalField: undefined }, linkTo: { link_type: 'Web', url: 'https://example.com', target: '_blank' } }