Arkar Myat

Reading time for Sanity portable text contents

May 4, 2023Arkar
Sanity

Generate a reading time from sanity portable text

*[
  _type == "articles"
]{
  title,
  "numberOfCharacters": length(pt::text(body)),
  // assumes 5 characters as mean word length
  // https://ux.stackexchange.com/questions/22520/how-long-does-it-take-to-read-x-number-of-characters
  "estimatedWordCount": round(length(pt::text(body)) / 5),
  // Words per minute: 180
  "estimatedReadingTime": round(length(pt::text(body)) / 5 / 180 )
}