πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Create an excerpt for a block field

By Carl Topham

Truncate block content into a shorter value to use as an excerpt

GROQ query

*[_type == "article" && draft != true ] | order(publishedOn desc)[0..5] {
     "excerpt": array::join(string::split((pt::text(body)), "")[0..255], "") + "..."
}

This query takes a block field and creates an excerpt of the required length so that truncation doesn't need to be done on the client side.

Contributor