-
-
Save ellismarte/10bfafe50c1465bcb89d645b82e74f6d to your computer and use it in GitHub Desktop.
This file contains 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
export const getSuggestedPostsByTagsQuery = `{ | |
"similarPosts": *[_type == "post" && slug.current != $slug && $tags in tags[].tag] | order(date desc, _updatedAt desc) [0...2] { | |
${postFields} | |
} | |
}`; |
This file contains 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 { similarPosts } = await getClient(preview).fetch( | |
getSuggestedPostsByTagsQuery, | |
{ | |
slug: params.slug, | |
tags: post.tags.map((tag) => tag.tag), | |
} | |
); |
This file contains 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
// tag | |
// post -- line 19 | |
export const tag = { | |
name: "tag", | |
title: "Tag", | |
type: "document", | |
fields: [ | |
{ | |
name: "tag", | |
title: "Tag", | |
type: "string", | |
validation: (Rule) => Rule.required(), | |
}, | |
], | |
}; | |
export const post = { | |
name: "post", | |
title: "Post", | |
type: "document", | |
fields: [ | |
{ | |
name: "title", | |
title: "Title", | |
type: "string", | |
validation: (Rule) => Rule.required(), | |
}, | |
{ | |
name: "slug", | |
title: "Slug", | |
type: "slug", | |
options: { | |
source: "title", | |
maxLength: 96, | |
}, | |
validation: (Rule) => Rule.required(), | |
}, | |
{ | |
name: "content", | |
title: "Content", | |
type: "array", | |
of: [ | |
{ | |
type: "block", | |
marks: { | |
annotations: [ | |
{ | |
name: "footnote", | |
type: "object", | |
title: "Footnote", | |
fields: [ | |
{ | |
name: "text", | |
type: "array", | |
of: [{ type: "block" }], | |
}, | |
], | |
}, | |
], | |
}, | |
lists: [ | |
{ title: "Bullet", value: "bullet" }, | |
{ title: "Numbered", value: "number" }, | |
], // yes please, both bullet and numbered | |
}, | |
{ | |
type: "image", | |
}, | |
{ type: "youtubeOrVimeo" }, | |
], | |
}, | |
{ | |
name: "excerpt", | |
title: "Excerpt", | |
type: "string", | |
}, | |
{ | |
name: "coverImage", | |
title: "Cover Image", | |
type: "image", | |
options: { | |
hotspot: true, | |
}, | |
}, | |
{ | |
name: "date", | |
title: "Date", | |
type: "datetime", | |
}, | |
{ | |
name: "author", | |
title: "Author", | |
type: "reference", | |
to: [{ type: "author" }], | |
}, | |
{ | |
name: "tags", | |
title: "Tags", | |
type: "array", | |
of: [ | |
{ | |
type: "reference", | |
to: [{ type: "tag" }], | |
}, | |
], | |
}, | |
], | |
preview: { | |
select: { | |
title: "title", | |
author: "author.name", | |
media: "coverImage", | |
}, | |
prepare(selection) { | |
const { author } = selection; | |
return { ...selection, subtitle: author && `by ${author}` }; | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment