Skip to content

Instantly share code, notes, and snippets.

@ellismarte
Created May 22, 2023 17:11
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 ellismarte/10bfafe50c1465bcb89d645b82e74f6d to your computer and use it in GitHub Desktop.
Save ellismarte/10bfafe50c1465bcb89d645b82e74f6d to your computer and use it in GitHub Desktop.
export const getSuggestedPostsByTagsQuery = `{
"similarPosts": *[_type == "post" && slug.current != $slug && $tags in tags[].tag] | order(date desc, _updatedAt desc) [0...2] {
${postFields}
}
}`;
const { similarPosts } = await getClient(preview).fetch(
getSuggestedPostsByTagsQuery,
{
slug: params.slug,
tags: post.tags.map((tag) => tag.tag),
}
);
// 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