Some Sanity groq fragments

Some Sanity groq fragments

Create excerpt for a Sanity portable text:

*[_type == "post"] {
  "excerpt": array::join(string::split(
  (pt::text(yourContentField[_type == "block"][0...1])), "")
  [0..384], "") + "..."
}

Get LQIP placeholder and aspect ratio from Sanity image:

*[_type == "post"] {
  "image": {
    "url": imageField.asset->url,
    "alt": imageField.alt,
    "aspectRatio": imageField.asset->metadata.dimensions.aspectRatio,
    "lqip": imageField.asset->metadata.lqip,
  }
}