✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Adding a word counter to a content block in Sanity.io

3 replies
Last updated: Jul 9, 2020
Hey! I'm attempting to add a small word counter to a content block. I suppose this means getting the content and having a field to display the value. Is it best to create a custom field for this kind of thing?
Jul 9, 2020, 8:52 AM
This is the current setup for the content:
      name: 'content',
      title: 'Content',
      type: 'array',
      of: [
          type: 'block',
          styles: [
            { title: 'Normal', value: 'normal' },
            { title: 'H2', value: 'h2' },
            { title: 'H3', value: 'h3' },
            { title: 'H4', value: 'h4' },
            { title: 'Quote', value: 'blockquote' },
          marks: {
            decorators: [
              { 'title': 'Strong', 'value': 'strong' },
              { 'title': 'Emphasis', 'value': 'em' },
              { 'title': 'Underline', 'value': 'underline' },
              { 'title': 'Strike', 'value': 'strike-through' }
Jul 9, 2020, 8:54 AM
Check out this gist: https://gist.github.com/kmelve/5c8eb803382d44ddc5e6c91d28e99551
Used with the
property on the field config
Jul 9, 2020, 9:03 AM
Thanks! That looks very manageable
Jul 9, 2020, 9:14 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?