Frikk Jarl
Digital Agent | UI/UX, Marketing & Development
This is a quick tip on how to truncate a Sanity block field to create an excerpt using GROQ.
*[_type == "article"] {
"excerpt": array::join(string::split((pt::text(body)), "")[0..255], "") + "..."
}
When querying the field using a Sanity Client and GROQ, there is no inbuilt excerpt function, or even a truncate function, so we need to do the steps ourselves.
All credits to Carl Topham
Please read his deeper explanation here:
Digital Agent | UI/UX, Marketing & Development