Unlock seamless workflows and faster delivery with our latest releases – get the details

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