Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

sanity-singletons

БесплатноБез исполняемых скриптовНе проверен

Configure singleton documents in a Sanity Studio using the document.singletons registry. Use when a developer wants a fixed-id document (settings, navigation…

sanity-ioот sanity-io★ 203 звезды на GitHub

Об этом скилле

Sanity Singletons

A "singleton" is a document with a fixed id that can be created exactly once. Common examples: site settings, navigation, footer content. Studio supports singletons as a first-class primitive via the document.singletons configuration registry plus a small set of Structure Tool helpers.

Requires sanity 6.17.0 or later. Check the installed version in the lockfile before using this API. On older Studios, either upgrade first or use the userland pattern (fixed documentId in a custom structure, plus manual newDocumentOptions and duplicate filtering) described in sanity-best-practices → studio-structure.

When to use this skill

  • A developer asks how to create a "settings document" or "singleton".
  • A studio configuration needs a document.singletons registry entry.
  • Structure Tool needs to render a singleton as a list item or document pane.
  • You're migrating an existing userland singleton implementation to the first-class API.
  • You're migrating from a third-party singleton plugin such as sanity-plugin-singleton-management (or its predecessor sanity-plugin-singleton-tools).

Registering a singleton

Singletons are registered in configuration, not on the schema type. A singleton definition binds a definition id to a document id and a schema type:

import {defineConfig, defineSingleton} from 'sanity'

export default defineConfig({
  schema: {
    types: [/* siteSettings and campaign are ordinary document types */],
  },
  document: {
    singletons: [
      // String shorthand — expands to
      // {id: 'siteSettings', documentId: 'siteSettings', schemaType: 'siteSettings'}
      'siteSettings',

      // Definition object. `defineSingleton` is an optional typed identity
      // helper; a plain object literal works too. `id` is omitted here, so it
      // inherits each `documentId`.
      defineSingleton({
        documentId: 'springCampaign',
        schemaType: 'campaign',
        title: 'Spring campaign', // optional display metadata
        initialValue: {season: 'spring'}, // optional per-singleton initial value
      }),
      defineSingleton({
        documentId: 'summerCampaign',
        schemaType: 'campaign',
        title: 'Summer campaign',
        initialValue: {season: 'summer'},
      }),
    ],
  },
})

Key facts:

  • defineSingleton produces a singleton definition, not a document schema. The schema type it references is defined separately with defineType and needs no singleton-specific configuration.
  • Multiple singletons may share a schema type (like the two campaigns above), each with its own title, icon, and initialValue (falling back to the schema type's), and a shared schema type may also back ordinary documents.
  • The definition id is the singleton's stable identity, and it is optional — it inherits documentId when omitted. Structure code references it (S.listItem().singleton('springCampaign')). Set it explicitly only to be verbose, to guard against future collisions, or to address a singleton universally when different workspaces or environments map it to different document ids.
  • A resolver function is also accepted: singletons: (prev, context) => [...prev, ...]. Resolvers only ever receive fully resolved definitions (string shorthands are expanded first).

Validation at config-resolution time (all failures aggregate into one ConfigResolutionError):

  • id: non-empty, unique across definitions (inherited ids count — an explicit id may not collide with another definition's inherited one). Used verbatim as a Structure Tool node id, so it is limited to [a-zA-Z0-9._-] and may not start with __edit__. It also may not match the name of a document type that no singleton claims, since the default content list keys both by id (the string shorthand never trips this — the type it names is claimed by the definition itself). A type claimed by a singleton with allowNonSingletonDocuments: true keeps its own list item, so it counts as unclaimed for this check.
  • documentId: non-empty, unique, published-id shaped (no drafts. / versions. prefix, only [a-zA-Z0-9._-]).
  • schemaType: must name an existing document type. Need not be unique.
  • Templates: an untagged template must not reuse a definition id (the generated singleton template claims it); at most one template may carry a given singleton tag; tags must reference registered definitions.

What Studio does automatically

  1. Generates a dedicated initial value template per singleton — tagged with the definition id via ResolvedTemplate.singleton, value from definition.initialValue ?? schemaType.initialValue — instead of the plain per-type template (unless the type opts in with allowNonSingletonDocuments), and removes tagged templates from every "create new" surface (global create menu, structure panes, reference inputs). The tagged template stays in source.templates, so opening the singleton before it exists s
Полный SKILL.md на GitHub

Установить sanity-singletons в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл sanity-singletons?

Configure singleton documents in a Sanity Studio using the document.singletons registry. Use when a developer wants a fixed-id document (settings, navigation, footer) edited in place, hidden from the default content list, with no "create new" or "duplicate" affordances — or when migrating a userland singleton implementation or a third-party singleton plugin (e.g. sanity-plugin-singleton-management) to the first-class API.

Как установить скилл sanity-singletons?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл sanity-singletons запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить sanity-singletons с