Skip to content

Instantly share code, notes, and snippets.

@mornir
Created October 28, 2021 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mornir/4905c0d9adaa8612d797f8e054764087 to your computer and use it in GitHub Desktop.
Save mornir/4905c0d9adaa8612d797f8e054764087 to your computer and use it in GitHub Desktop.
const blocks = `blocks[] {
...,
photos[] {
...,
"metadata": asset->metadata,
},
markDefs[] {
...,
_type == "internalLink" => {
"slug": @->slug.current,
"type": @->_type
},
_type == "pdf" => {
"file": @->pdf.asset->
},
}
}`
// NORMAL PAGE
const pageProjection = `{
...,
sections[] {
...,
"meta": asset->{ metadata {lqip, dimensions} },
people[]->{
_id,
"title": firstname + ' ' + lastname,
subtitle,
photo,
"lqip": photo.asset->metadata.lqip,
"slug": slug.current
},
${blocks}
}
}`
const getPage =
'*[_type == "page" && slug.current == $slug] | order(_updatedAt desc)[0]' +
pageProjection
// PERSON PAGE: TEAM + STUDENTS
const personProjection = `{
slug,
_type,
"title": firstname + ' ' + lastname,
subtitle,
photo,
"body": body.${blocks},
email
}`
const getPerson =
'*[(_type == "student" || _type == "employee") && slug.current == $slug]| order(_updatedAt desc)[0]' +
personProjection
const generate = `{
"pages": *[_type == "page"] ${pageProjection},
"employees": *[_type == "employee"] ${personProjection},
"students": *[_type == "student"] ${personProjection}
}`
export { getPage, getPerson, generate }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment