Remi Sture
Frontend lead @ Eviny.no
Remi is located at Kleppestø, Norway
This snippet can be used to fetch current, previous and next articles based on publication date and related tags.
*[_type == $type && slug.current == $slug]{
"current": {
"slug": slug.current, title, publicReleaseDate, "tags": tags[]->tag
},
"previous": *[_type == $type && count((tags[]->tag)[@ in ^.^.tags[]->tag]) > 0 && ^.publicReleaseDate > publicReleaseDate]|order(publicReleaseDate desc)[0]{
"slug": slug.current, title, publicReleaseDate, "tags": tags[]->tag
},
"next": *[_type == $type && count((tags[]->tag)[@ in ^.^.tags[]->tag]) > 0 && ^.publicReleaseDate < publicReleaseDate]|order(publicReleaseDate asc)[0]{
"slug": slug.current, title, publicReleaseDate, "tags": tags[]->tag
},
}|order(publicReleaseDate)[0]
{
type: "news_article",
slug: "my-article-slug",
}
{
"current": {
"slug": "current-article",
"title": "Current article"
"publicReleaseDate": "2022-09-22",
"tags": ["news"],
},
"next": {
"slug": "next-article",
"title": "Next article"
"publicReleaseDate": "2022-10-11",
"tags": ["news"],
},
"previous": {
"slug": "previous-article",
"title": "Previous article"
"publicReleaseDate": "2022-08-31",
"tags": ["news"],
}
}
Inspired by this snippet by Knut Melvær.
Frontend lead @ Eviny.no
Runs Support @ Sanity.io
Support Engineer at Sanity.io
GROQ doesn't yet include a function to match the end of a string, but we can simulate it by splitting our string on our term.
Go to Matching the end of a string in GROQSimplify your Studio experience by hiding deprecated fields when you create new documents.
Go to Hide a deprecated field in new documentsIf you want to pass a parameter to a query that might not always be defined
Go to Handle Certain Values To Be TrueEver wondered where and if your content types are used?
Go to Search for object types across document types