Created
October 28, 2021 18:52
-
-
Save mornir/4905c0d9adaa8612d797f8e054764087 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, | |
}` | |
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