Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

sanity

/sanity

Pomaga w pracy z headless CMS Sanity.io: zapytania GROQ, Content Lake, definicje schematów i Sanity Studio.

Repozytorium
Agent-Skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
01.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 01.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga w pracy z headless CMS Sanity.io: zapytania GROQ, Content Lake, definicje schematów i Sanity Studio.

Oryginalny opis (EN)

Expert Sanity.io headless CMS assistance covering GROQ queries, Content Lake, schema definitions, and Sanity Studio. Use when building structured content platforms and headless digital experiences.

Jak działa

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Sekcje z nagłówków SKILL.md, w oryginale · 201 linii, 679 słów
Podgląd SKILL.md
---
name: sanity
description: Expert Sanity.io headless CMS assistance covering GROQ queries, Content Lake, schema definitions, and Sanity Studio. Use when building structured content platforms and headless digital experiences.
---

# Sanity

Sanity is "Content as Data". The **Studio v3** is a real-time React application that you host, giving you complete control over the editing experience.

## When to Use

- **Structured Content Platforms**: Headless CMS providing real-time collaboration and custom editing studios.
- **Multi-Channel Omnichannel Publishing**: Distributing content to websites, mobile apps, e-commerce, and signage.
- **Sanity Studio v3 Customization**: Customizing React-based editorial workspaces with schema-as-code.
- **Real-Time Visual Editing**: Combining GROQ queries with Vercel Visual Editing and live content previews.

## Quick Start

```typescript
// schemaTypes/post.ts
import { defineField, defineType } from "sanity";

export const postType = defineType({
  name: "post",
  title: "Blog Post",
  type: "document",
  fields: [
    defineField({
      name: "title",
      type: "string",
      validation: (rule) => rule.required(),
    }),
    defineField({ name: "slug", type: "slug", options: { source: "title" } }),
    defineField({ name: "publishedAt", type: "datetime" }),
  ],
});
```

## Core Concepts

### Declarative Schema-as-Code

Defining content types, fields, and validation rules:

```typescript
// schemas/post.ts
import { defineType, defineField } from "sanity";

export const postType = defineType({
  name: "post",
  title: "Blog Post",
  type: "document",
  fields: [
    defineField({
      name: "title",
      title: "Title",
      type: "string",
      validation: (Rule) => Rule.required().min(10).max(100),
    }),
    defineField({
      name: "slug",
      title: "Slug",
      type: "slug",
      options: { source: "title", maxLength: 96 },
      validation: (Rule) => Rule.required(),
    }),
    defineField({
      name: "publishedAt",
      title: "Published At",
      type: "datetime",
      initialValue: () => new Date().toISOString(),
    }),
    defineField({
      name: "content",
      title: "Body Content",
      type: "array",
      of: [{ type: "block" }, { type: "image" }],
    }),
  ],
});
```

### Type-Safe GROQ Queries with Sanity TypeGen

Querying structured content with filter and projection:

```typescript
import { createClient, groq } from "next-sanity";

export const client = createClient({
  projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
  dataset: process.env.NEXT_PUBLIC_SANITY_DATASET!,
  apiVersion: "2026-01-01",
  useCdn: false, // false for fresh drafts in preview mode
});

// GROQ query projection
export const POSTS_QUERY = groq`
  *[_type == "post" && defined(slug.current)] | order(publishedAt desc)[0...10] {
    _id,
    title,
    "slug": slug.current,
    publishedAt,
    "authorName": author->name
  }
`;
```

### Portable Text Rendering in React

Rendering structured block content with custom components:

```tsx
import { PortableText, PortableTextComponents } from "@portabletext/react";

const customComponents: PortableTextComponents = {
  types: {
    image: ({ value }) => (
      <img
        src={value.imageUrl}
        alt={value.alt || "Content image"}
        className="rounded-lg my-4"
      />
    ),
  },
  marks: {
    link: ({ children, value }) => {
      const target = (value?.href || "").startsWith("http")
        ? "_blank"
        : undefined;
      return (
        <a
          href={value?.href}
          target={target}
          rel="noopener noreferrer"
          className="text-blue-500 underline"
        >
          {children}
        </a>
      );
    },
  },
};

export function ArticleBody({ value }: { value: any }) {
  return <PortableText value={value} components={customComponents} />;
}
```

## Common Patterns

### GROQ Query with Projection and Filter

**Problem**: Fetching complete nested documents when only a few fields are needed by the frontend.

**Solution**:
Use GROQ projections:

```typescript
import { createClient } from "@sanity/client";

const client = createClient({
  projectId: "your-project-id",
  dataset: "production",
  useCdn: true,
  apiVersion: "2024-01-01",
});

const query = `*[_type == "post" && defined(slug.current)] | order(publishedAt desc)[0...10] {
  _id,
  title,
  "slug": slug.current,
  "authorName": author->name
}`;

const posts = await client.fetch(query);
```

## Best Practices

**Do**:

- Use Sanity TypeGen (`sanity typegen generate`) to generate TypeScript types from GROQ queries automatically.
- Configure fine-grained webhook listeners for On-Demand Revalidation in Next.js / Nuxt / Remix.
- Pin the `apiVersion` parameter (`'2026-01-01'`) to prevent breaking changes.
- Use Portable Text for rich editorial content rather than raw HTML or Markdown.

**Don't**:

- Use `*[]` without type constraints in GROQ; always specify `_type == "..."` for indexing.
- Expose write tokens (`SANITY_API_WRITE_TOKEN`) to client-side bundles.
- Query entire document trees without projections; project only the fields required by the UI.

## Troubleshooting

| Error                                    | Cause                                                                      | Solution                                                                    |
| :--------------------------------------- | :------------------------------------------------------------------------- | :-------------------------------------------------------------------------- |
| `ClientError: Project ID not configured` | Missing `projectId` in client options or environment variables.            | Provide valid `projectId` in `createClient(...)`.                           |
| `Unknown type "..." in schema`           | Referenced schema type not imported or exported in `schemaTypes/index.ts`. | Add missing type definition to the `schemaTypes` array in sanity.config.ts. |
| `CORS Error: Origin not allowed`         | Frontend domain not added to Sanity API Allowed Origins.                   | Add domain in Sanity management dashboard under API settings.               |

## References

- [Sanity Documentation](https://www.sanity.io/)

Wersje

RepozytoriumWynikLicencja
Ta strona · G1Joshi/Agent-Skills100MIT
TerminalSkills/skills100Apache-2.0

Migawka bazy z 13.11.2026 · wersja paczki f0866d85e53f (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 1 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95cms
    Wspiera integrację headless CMS (Sanity, Strapi, Contentful): zapytania GROQ, Portable Text, draft mode, kolekcje treści i podgląd z rewalidacją.
  • 100sanity-webhooks
    Odbiera i weryfikuje webhooki Sanity oparte na GROQ, sprawdzając nagłówek sanity-webhook-signature, i obsługuje zdarzenia dokumentów do rewalidacji cache i reindeksacji wyszukiwania.
  • 100local-cms-52e4ef01
    Podpowiada, jak zintegrować headless CMS, takie jak Sanity, Contentful, DatoCMS, Storyblok lub Builder.io, z Vercelem.
  • 100sanity-best-practices
    Zbiera dobre praktyki pracy z Sanity: schematy, zapytania GROQ, TypeGen, Visual Editing, obrazy, Portable Text, Studio, lokalizacja, migracje i integracje z Next.js, Nuxt czy Astro.
  • 100add-cms
    Dodaje headless CMS, np. Sanity, Payload lub Strapi, z modelem treści, podglądem i odświeżaniem po webhooku.
  • 100sanity-best-practices
    Podaje dobre praktyki pracy z Sanity: schematy, zapytania GROQ, TypeGen, Visual Editing, obrazy, Portable Text, migracje i integracje z frameworkami, takimi jak Next.js czy Astro.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.