{"id":41312733,"url":"https://github.com/bhargav-bkpatel/sanity-plugin-seo","last_synced_at":"2026-01-23T05:26:37.596Z","repository":{"id":247348390,"uuid":"825604910","full_name":"bhargav-bkpatel/sanity-plugin-seo","owner":"bhargav-bkpatel","description":"Sanity SEO Plugin – Easily optimize your Sanity content with built-in SEO features like meta tags, structured data, ensuring your content performs better on search engines.","archived":false,"fork":false,"pushed_at":"2025-09-09T10:32:40.000Z","size":8467,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-22T10:41:15.419Z","etag":null,"topics":["nextjs-sanity-seo","sanity-metadata","sanity-plugin-seo","sanity-seo","sanity-seo-fields","sanity-seo-plugin","sanity-v3","seo-feedback","seo-fields-generator","seo-plugin"],"latest_commit_sha":null,"homepage":"https://www.sanity.io/plugins/sanity-seo-plugin","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bhargav-bkpatel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-08T07:01:27.000Z","updated_at":"2025-09-09T10:33:21.000Z","dependencies_parsed_at":"2024-10-17T15:59:56.313Z","dependency_job_id":"2545b975-a338-4b69-ba6a-3cf7b19193c5","html_url":"https://github.com/bhargav-bkpatel/sanity-plugin-seo","commit_stats":null,"previous_names":["bhargav-bkpatel/sanity-plugin-seo"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/bhargav-bkpatel/sanity-plugin-seo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhargav-bkpatel%2Fsanity-plugin-seo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhargav-bkpatel%2Fsanity-plugin-seo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhargav-bkpatel%2Fsanity-plugin-seo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhargav-bkpatel%2Fsanity-plugin-seo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhargav-bkpatel","download_url":"https://codeload.github.com/bhargav-bkpatel/sanity-plugin-seo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhargav-bkpatel%2Fsanity-plugin-seo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28680692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T04:33:33.518Z","status":"ssl_error","status_checked_at":"2026-01-23T04:33:30.433Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nextjs-sanity-seo","sanity-metadata","sanity-plugin-seo","sanity-seo","sanity-seo-fields","sanity-seo-plugin","sanity-v3","seo-feedback","seo-fields-generator","seo-plugin"],"created_at":"2026-01-23T05:26:37.138Z","updated_at":"2026-01-23T05:26:37.590Z","avatar_url":"https://github.com/bhargav-bkpatel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Alt Text](https://github.com/bhargav-bkpatel/sanity-plugin-seo/blob/main/public/assets/background.png)\n\n## ⚡ Sanity Plugin SEO\n\n\u003cblockquote\u003e\n  🚀 \u003cb\u003eSanity Studio Plugin\u003c/b\u003e – Compatible with \u003cb\u003ev3\u003c/b\u003e and \u003cb\u003ev4\u003c/b\u003e\n\u003c/blockquote\u003e\n\n[![npm version](https://img.shields.io/badge/npm-v9.3.1-blue)](https://www.npmjs.com/package/sanity-plugin-seo)\n[![npm downloads](https://img.shields.io/badge/downloads-22k-brightgreen)](https://www.npmjs.com/package/sanity-plugin-seo)\n[![TypeScript](https://img.shields.io/badge/types-TypeScript-blue)](https://www.typescriptlang.org/)\n[![Built with Sanity](https://img.shields.io/badge/Built%20With-Sanity-8a2be2?logo=sanity\u0026logoColor=white)](https://www.sanity.io/)\n[![Sanity V3](https://img.shields.io/badge/Sanity%20V3%20Plugin-4e5452)](https://www.sanity.io/)\n[![Sanity V4](https://img.shields.io/badge/Sanity%20V4%20Plugin-4e5452)](https://www.sanity.io/)\n\nThe `sanity-plugin-seo` Plugin is designed to simplify the process of generating SEO fields for various types of content. This plugin is particularly useful for enhancing the structured data of your content, making it more accessible and understandable for search engines. By integrating seamlessly with Sanity Studio, it provides an easy way to add and configure SEO fields within your document schemas, ensuring your content is fully optimized for search visibility.\n\n![Alt Text](https://github.com/bhargav-bkpatel/sanity-plugin-seo/blob/main/public/assets/demo-1.gif)\n\n## ✨ Key Features\n\n- 🔍 **Customizable SEO Fields:** Easily add and configure essential SEO fields such as title, description, keywords, and more within your document schemas.\n\n- 🔌 **Sanity Studio Integration:** Effortlessly incorporate SEO field creation into your Sanity Studio workflow, ensuring that SEO optimization becomes an integral part of your content development process.\n\n- 🔗 **Compatibility:** Fully compatible with Sanity v3 and v4, it integrates seamlessly with your existing schemas and plugins. It also works well with Next.js and React, ensuring smooth integration with modern web development frameworks.\n\n## 🌐 Demo links for sanity with Next.js plugin integration\n\n🧑‍💻 Here is the frontend.\n[Frontend Demo](https://sanity-nextjs-seo-boilerplate.vercel.app/) \n\n💻 Here is the frontend with NextJs app router.\n[Frontend Demo With NextJs App Router](https://sanity-nextjs-with-app-router-seo-boilerplate.vercel.app/)\n\n🎨 Here is the sanity studio.\n[Studio Demo](https://sanity-nextjs-seo-boilerplate.vercel.app/studio/)\n\n## 📦 Installation\n\nTo get started, install the plugin using npm:\n\n```sh\nnpm install sanity-plugin-seo\n```\n\n## 📋 Usage in Sanity Studio\n\nAdd it as a plugin in `sanity.config.ts` (or .js):\n\n```ts\nimport { defineConfig } from \"sanity\";\nimport { seoMetaFields } from \"sanity-plugin-seo\";\n\nexport default defineConfig({\n  plugins: [seoMetaFields()],\n});\n```\n\nYou can then add the `schemaMarkup` field to any Sanity Document you want it to be in.\n\n```javascript\nconst myDocument = {\n  type: \"page\",\n  name: \"page\",\n  fields: [\n    {\n      title: \"Seo\",\n      name: \"seo\",\n      type: \"seoMetaFields\",\n    },\n  ],\n  preview: {\n    select: {\n      metaTitle: \"seo\",\n    },\n    prepare(selection) {\n      const { metaTitle } = selection?.metaTitle || \"\";\n      return {\n        title: metaTitle || \"seo\",\n      };\n    },\n  },\n};\n```\n\n## ⚛️ Usage with Next.js and React.js\n\nCreate query for SEO fields in `/lib/sanity/queries/demo.ts` frontend (Typescript or Javascript)\n\n```Typescript\nconst groqQuery = groq`*[_type == \"page\"]{\n_type,\n\"slug\":slug.current,\n${seo},\n}`;\n\nexport const seo = /* groq */ `seo{\n${seofields}\n}`;\n\nexport const seofields = /* groq */ `\n_type,\nmetaTitle,\nnofollowAttributes,\nseoKeywords,\nmetaDescription,\nopenGraph{\n${openGraphQuery}\n},\ntwitter{\n${twitterQuery}\n},\nadditionalMetaTags[]{\n_type,\nmetaAttributes[]{\n${metaAttributesQuery}\n}\n}\n`;\n\nexport const twitterQuery = /* groq */ `\n_type,\nsite,\ncreator,\ncardType,\nhandle\n`;\n\nexport const openGraphQuery = /* groq */ `\n_type,\nsiteName,\nurl,\ndescription,\ntitle,\nimage{\n${imageFields}\n}\n`;\n\nexport const metaAttributesQuery = /* groq */ `\n_type,\nattributeValueString,\nattributeType,\nattributeKey,\nattributeValueImage{\n${imageFields}\n}\n`;\n\nexport const imageFields = /* groq */ `\n_type,\ncrop{\n_type,\nright,\ntop,\nleft,\nbottom\n},\nhotspot{\n_type,\nx,\ny,\nheight,\nwidth,\n},\nasset-\u003e{...}\n`;\n```\n\nCreate type for all the fields `/lib/sanity/queries/demo.d.ts` (Typescript)\n\n``` Typescript\n\nexport type SeoType = {\n  _type?: \"seo\";\n  nofollowAttributes?: boolean\n  metaDescription?: string;\n  additionalMetaTags?: MetaTagType[];\n  metaTitle?: string;\n  seoKeywords?: string[]\n  openGraph?: OpenGraphType;\n  twitter?: Twitter;\n};\n\nexport type MetaTagType = {\n  _type: \"metaTag\";\n  metaAttributes?: MetaAttributeType[];\n};\n\nexport type MetaAttributeType = {\n  _type: \"metaAttribute\";\n  attributeKey?: string;\n  attributeType?: string;\n  attributeValueString?: string;\n  attributeValueImage?: CustomImageType;\n};\n\n\nexport type OpenGraphType = {\n  _type: \"openGraph\";\n  title: string;\n  url?: string\n  siteName?: string\n  description: string;\n  image: CustomImageType;\n};\n\nexport type Twitter = {\n  _type: \"twitter\";\n  handle?: string;\n  creator?: string\n  site?: string;\n  cardType?: string;\n};\n\nexport type CustomImageType = {\n  _type: \"customImage\";\n  asset?: SanityImageAssetType;\n  crop?: {\n    _type: \"SanityImageCrop\";\n    right: number;\n    top: number;\n    left: number;\n    bottom: number;\n  };\n  hotspot?: {\n    x: number;\n    y: number;\n    height: number;\n    _type: \"SanityImageHotspot\";\n    width?: number;\n  };\n};\n\nexport type SanityImageAssetType = {\n  _type?: \"SanityImageAsset\";\n  _id?: string;\n  path?: string;\n  url?: string;\n  metadata?: {\n    _type?: \"SanityImageMetadata\";\n    dimensions?: {\n      _type?: \"SanityImageDimensions\";\n      height?: number;\n      width?: number;\n    };\n  };\n};\n\n```\n\nCall MetaData on CustomNextSeo (Typescript or Javascript)\n\n```Typescript (or js)\n\nimport React, { useMemo } from \"react\";\nimport type { PropsWithChildren } from \"react\";\nimport { NextSeo } from \"next-seo\";\nimport { MetaTag as NextSeoMetaTag, OpenGraph as NextSeoOpenGraph } from 'next-seo/lib/types'\nimport { CustomImageType, MetaAttributeType, MetaTagType, OpenGraphType, SeoType } from \"../../../lib/sanity/types\";\n\n\nexport const getOpenGraph = (args: OpenGraphType) =\u003e {\n  const { description, image, title, _type, siteName, url } = args\n  const getImage = image ? resolveImage(image) : null\n  const values = {\n    _type,\n    description,\n    siteName,\n    url,\n    title,\n    images: [{ url: getImage ?? '' }],\n  }\n  return values as NextSeoOpenGraph\n}\n\nexport const getMetaObjects = (tags: MetaTagType[], allowIndexing?: boolean) =\u003e {\n  const tagArray: NextSeoMetaTag[] = []\n  tags.map(tag =\u003e {\n    const excludeTag =\n      !allowIndexing \u0026\u0026\n      !!tag.metaAttributes?.find(\n        i =\u003e\n          i?.attributeValueString?.includes('noindex') ||\n          i?.attributeValueString?.includes('nofollow'),\n      )\n    if (!excludeTag) {\n      const metaTag = getMetaAttribute(tag?.metaAttributes)\n      if (metaTag) {\n        tagArray.push(metaTag)\n      }\n    }\n  })\n  return tagArray\n}\n\nexport const resolveImage = (image?: CustomImageType) =\u003e {\n  return image?.asset?.url ?? \"\";\n};\n\nexport const getMetaAttribute = (attrs: MetaAttributeType[] | undefined) =\u003e {\n  if (!attrs) {\n    return null\n  }\n  const obj: Record\u003cstring, string\u003e = {}\n  attrs.map((i) =\u003e {\n    Object.assign(obj, {\n      [i?.attributeKey as string]:\n        i.attributeType == \"image\"\n          ? resolveImage(i?.attributeValueImage)\n          : i.attributeValueString,\n    })\n  })\n  return obj as unknown as NextSeoMetaTag\n}\n\n\ninterface CustomNextSeoProps {\n  seo: SeoType | null;\n  slug: string;\n}\n\nconst CustomNextSeo: React.FC\u003cPropsWithChildren\u003cCustomNextSeoProps\u003e\u003e = ({\n  seo,\n    children,\n  slug,\n}) =\u003e {\n\n  const { additionalMetaTags, metaDescription, metaTitle, twitter, nofollowAttributes, seoKeywords } = seo || {};\n\n  const tags = useMemo(\n    () =\u003e (additionalMetaTags ? getMetaObjects(additionalMetaTags) : []),\n    [additionalMetaTags]\n  );\n  const openGraph = useMemo(\n    () =\u003e (seo?.openGraph ? getOpenGraph(seo?.openGraph) : undefined),\n    [seo]\n  );\n  const url = (process.env.NEXT_PUBLIC_APP_URL ?? \"\") + (slug?.startsWith(\"/\") ? slug : `/${slug}`);\n\n  return (\n       \u003c\u003e\n    \u003cNextSeo\n      themeColor=\"\"\n      twitter={{\n        handle: twitter?.creator,\n        site: twitter?.site,\n        cardType: twitter?.cardType,\n      }}\n      nofollow={nofollowAttributes}\n      noindex={nofollowAttributes}\n      openGraph={openGraph}\n      canonical={url || \"\"}\n      additionalMetaTags={((seoKeywords \u0026\u0026 seoKeywords?.length \u003e 0\n        ? [{ name: \"keywords\", content: seoKeywords?.join(\", \") }]\n        : []) as NextSeoMetaTag[]).concat(tags ?? [])}\n      title={metaTitle ?? \"\"}\n      description={metaDescription ?? \"\"}\n    /\u003e\n       {children}\n    \u003c/\u003e\n  );\n};\n\nexport default CustomNextSeo;\n\n\n```\n\n## 💼 Explore my personal work and projects:\n\nVisit my portfolio at [Bhargav Patel](https://bkpatel.com/) to explore my work, projects, and what I’ve been building lately.\n\n## 🪪 License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhargav-bkpatel%2Fsanity-plugin-seo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhargav-bkpatel%2Fsanity-plugin-seo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhargav-bkpatel%2Fsanity-plugin-seo/lists"}