How would you structure something like this in the backend? It's part of an article, so there might be other types of formatting in the column, and images can be either left...

1 replies
Last updated: Jan 7, 2021

How would you structure something like this in the backend? It's part of an article, so there might be other types of formatting in the column, and images can be either left or right.

Jan 7, 2021, 11:01 AM

export default {
  name: 'textWithIllustration',
  type: 'object',
  title: 'Text with Illustation',
  fields: [
    {
      name: 'heading',
      type: 'string',
      title: 'Heading'
    },
    {
      name: 'text',
      type: 'richText', // or text, or simpleRichText depending on what you want to allow,
      title: 'Text'
    },
    {
      name: 'illustration',
      type: 'figure', // image field with alt and caption fields
      title: 'Illustration'
    }
    /*
        {
            name: 'alternate',
            type: 'boolean',
            title: 'Use alternative position'
        },
        */
  ]
}
I'd do something like this and let the frontend design system decide the formatting for what's best in terms of composition and alteration. If you do want editorial control you can add that as an agnostic option, or be more specific with a predefined string field for direction or such.

Jan 7, 2021, 11:14 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.