sanity-best-practices

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Sanity Best Practices

Sanity最佳实践

Comprehensive best practices guide for Sanity development, maintained by Sanity. Contains rules across 10 categories, prioritized by impact to guide schema design, query optimization, and frontend integration.
由Sanity维护的Sanity开发综合最佳实践指南。包含10个类别的规则,按影响优先级排序,用于指导Schema设计、查询优化和前端集成。

When to Apply

适用场景

Reference these guidelines when:
  • Writing GROQ queries or optimizing performance
  • Designing content schemas
  • Implementing Visual Editing and live preview
  • Working with images, Portable Text, or page builders
  • Configuring Sanity Studio structure
  • Setting up TypeGen for type safety
  • Implementing localization
  • Migrating content from other systems
在以下场景中参考本指南:
  • 编写GROQ查询或优化性能
  • 设计内容Schema
  • 实现Visual Editing和实时预览
  • 处理图片、Portable Text或页面构建器
  • 配置Sanity Studio结构
  • 设置TypeGen以实现类型安全
  • 实现本地化
  • 从其他系统迁移内容

Rule Categories by Priority

按优先级划分的规则类别

PriorityCategoryImpactPrefix
1GROQ PerformanceCRITICAL
groq-
2Schema DesignHIGH
schema-
3Visual EditingHIGH
visual-
4ImagesHIGH
image-
5Portable TextHIGH
pte-
6Page BuilderMEDIUM
pagebuilder-
7Studio ConfigurationMEDIUM
studio-
8TypeGenMEDIUM
typegen-
9LocalizationMEDIUM
i18n-
10MigrationLOW-MEDIUM
migration-
优先级类别影响程度前缀
1GROQ性能关键
groq-
2Schema设计
schema-
3Visual Editing
visual-
4图片
image-
5Portable Text
pte-
6页面构建器
pagebuilder-
7Studio配置
studio-
8TypeGen
typegen-
9本地化
i18n-
10迁移低-中
migration-

How to Use

使用方法

Read individual rule files for detailed explanations and code examples:
rules/groq-optimizable-filters.md
rules/schema-data-over-presentation.md
rules/_sections.md
Each rule file contains:
  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references
  • Framework-specific notes (when applicable)
阅读单个规则文件以获取详细说明和代码示例:
rules/groq-optimizable-filters.md
rules/schema-data-over-presentation.md
rules/_sections.md
每个规则文件包含:
  • 规则重要性的简要说明
  • 错误代码示例及解释
  • 正确代码示例及解释
  • 额外背景信息和参考资料
  • 特定框架说明(如适用)

Framework Integration

框架集成

Framework-specific guidance (Next.js, Astro, Remix, etc.) is available via the Sanity MCP server using
list_sanity_rules
and
get_sanity_rules
tool calls when available. If the MCP server is not configured, run
npx sanity@latest mcp configure
to set it up.
特定框架指南(Next.js、Astro、Remix等)可通过Sanity MCP服务器使用
list_sanity_rules
get_sanity_rules
工具调用获取(如可用)。如果未配置MCP服务器,请运行
npx sanity@latest mcp configure
进行设置。