How to Count All Font Files Across Type Libraries

7 replies
Last updated: Aug 3, 2022
Hey, I need help with a
count
query again. I have the following structure:
*[_type == "typeLibrary"]{

fontFamily[]->{

fontFile[]

}

}

Please see the attached screenshot for how the return on the query looks like. What I'd like to do is count all the
fontFile
(Array) inside of
typeLibrary
which might contain a
fontFamily
Array itself. So in the attached screenshot, it should return 8.
Thanks in advance and I hope everything is clearly explained!
Aug 3, 2022, 8:18 AM
You want to count all font files across all type libraries, is that correct?
Aug 3, 2022, 8:24 AM
Could you try this:
count(*[ _ type == "typeLibrary"].fontFamily[]->fontFile[])
Aug 3, 2022, 8:24 AM
user F
Thanks so much for the swift reply! This is really close. However, I want to count for each of
typeLibraries
entry separately.
Again attached a screenshot. Entry
1
should return 12, entry
2
should return 8 and so on.
Aug 3, 2022, 8:35 AM
Ah, I see. πŸ™‚
Aug 3, 2022, 8:36 AM
*[ _type == "typeLibrary"] {
  "count": count(fontFamily[]->fontFile[])
}
Aug 3, 2022, 8:37 AM
OMG that did it!! Tysm <3
Aug 3, 2022, 8:40 AM
Yay, fantastic! πŸ’š
Aug 3, 2022, 8:43 AM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Categorized in