Replies: 1 comment 5 replies
-
I am doing something similar to get height/width, at the schema-level. It's a bit of a hack, but it works for me. It should be noted, this is all client-side, so it may not work directly with your node script. First, I add this to the templates for my richtext editor schema, so it will add export const templateImage = {
name: 'Image',
label: 'Image',
fields: [
{
name: 'src',
label: 'Image',
type: 'image',
ui: {
validate: (value, allValues, meta, field) => {
if (value) {
const i = new Image()
i.onload = () => {
allValues.width = i.naturalWidth
allValues.height = i.naturalHeight
}
i.src = value
}
}
}
},
{
name: 'width',
label: 'Width',
type: 'number',
ui: {
component: () => null
}
},
{
name: 'height',
label: 'Height',
type: 'number',
ui: {
component: () => null
}
},
{
name: 'alt',
label: 'Alt Text (for screen-readers and SEO)',
type: 'string'
},
{
name: 'title',
label: 'Title (shows on hover)',
type: 'string'
}
]
}
// ...
{
type: 'rich-text',
label: 'Body',
name: 'body',
isBody: true,
required: true,
templates: [
templateImage,
// put whatever other embeds you want here
]
},
This hides height/width inputs and computes the dimensions, client-side when the image changes. When I render the content: <TinaMarkdown components={componentsRow} content={block.body} /> I add export const Image = ({ type, ...props }) => <img className='mb-4' {...props} /> Now, in the mdx, I get things like this: <Image height={200} width={100} alt='alt text' /> and since it knows how to do /* XXX: hide the image button to force use of the embed menu */
.with-toolbar > .sticky > .grid > .grid > span:nth-child(3) {
display: none !important;
} |
Beta Was this translation helpful? Give feedback.
-
When a user uploads an image through the media manager, I'm looking for a way to execute a node.js metadata processing script. Any insight as to how this can be done?
Beta Was this translation helpful? Give feedback.
All reactions