storyblok-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStoryblok Best Practices
Storyblok最佳实践
Comprehensive best practices guide for Storyblok CMS development, designed for AI agents and LLMs helping agency developers. Contains 40 rules across 24 categories, prioritized by impact to guide automated code generation and content architecture decisions.
面向AI代理和大语言模型的Storyblok CMS开发综合最佳实践指南,旨在帮助代理开发者。包含24个分类下的40条规则,按影响优先级排序,为自动化代码生成和内容架构决策提供指导。
When to Apply
适用场景
Reference these guidelines when:
- Designing Storyblok content models and component schemas
- Integrating Storyblok with React, Vue, Nuxt, or Next.js
- Configuring Visual Editor and real-time preview
- Building custom field plugins with @storyblok/field-plugin
- Implementing Content Delivery API or Management API
- Setting up internationalization (i18n) with field or folder translations
- Configuring webhooks for cache invalidation and automation
- Managing multi-space architectures and CI/CD workflows
- Handling rich text fields with custom resolvers
- Optimizing images and performance with Image Service
- Building tool plugins or space plugins (sidebar apps)
- Setting up preview/production environments
在以下场景中参考本指南:
- 设计Storyblok内容模型和组件架构
- 将Storyblok与React、Vue、Nuxt或Next.js集成
- 配置可视化编辑器和实时预览功能
- 使用@storyblok/field-plugin构建自定义字段插件
- 实现内容交付API(Content Delivery API)或管理API(Management API)
- 通过字段或文件夹翻译设置国际化(i18n)
- 配置Webhooks以实现缓存失效和自动化流程
- 管理多空间架构和CI/CD工作流
- 使用自定义解析器处理富文本字段
- 借助Image Service优化图片和性能
- 构建工具插件或空间插件(侧边栏应用)
- 设置预览/生产环境
Rule Categories by Priority
按优先级排序的规则分类
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Content Modeling | CRITICAL | |
| 2 | SDK Integration | CRITICAL | |
| 3 | Visual Editor | CRITICAL | |
| 4 | Performance & Caching | CRITICAL | |
| 5 | Security & Authentication | CRITICAL | |
| 6 | Field Plugins | HIGH | |
| 7 | API Development | HIGH | |
| 8 | Internationalization | HIGH | |
| 9 | Next.js Integration | HIGH | |
| 10 | Nuxt Integration | HIGH | |
| 11 | App Development | HIGH | |
| 12 | Space & Asset Management | HIGH | |
| 13 | Webhooks & Automation | MEDIUM-HIGH | |
| 14 | Workflows & Publishing | MEDIUM-HIGH | |
| 15 | CLI & DevOps | MEDIUM | |
| 16 | Testing & Quality | MEDIUM | |
| 17 | Rich Text & Media | MEDIUM | |
| 18 | Common Patterns | HIGH | |
| 19 | SEO & Structured Data | HIGH | |
| 20 | E-commerce Integration | HIGH | |
| 21 | Content Migration | MEDIUM-HIGH | |
| 22 | AI Features | MEDIUM | |
| 23 | Collaboration | MEDIUM | |
| 24 | Custom Apps | MEDIUM | |
| 优先级 | 分类 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 内容建模 | 关键 | |
| 2 | SDK集成 | 关键 | |
| 3 | 可视化编辑器 | 关键 | |
| 4 | 性能与缓存 | 关键 | |
| 5 | 安全与认证 | 关键 | |
| 6 | 字段插件 | 高 | |
| 7 | API开发 | 高 | |
| 8 | 国际化 | 高 | |
| 9 | Next.js集成 | 高 | |
| 10 | Nuxt集成 | 高 | |
| 11 | 应用开发 | 高 | |
| 12 | 空间与资产管理 | 高 | |
| 13 | Webhooks与自动化 | 中高 | |
| 14 | 工作流与发布 | 中高 | |
| 15 | CLI与DevOps | 中 | |
| 16 | 测试与质量 | 中 | |
| 17 | 富文本与媒体 | 中 | |
| 18 | 通用模式 | 高 | |
| 19 | SEO与结构化数据 | 高 | |
| 20 | 电商集成 | 高 | |
| 21 | 内容迁移 | 中高 | |
| 22 | AI功能 | 中 | |
| 23 | 协作功能 | 中 | |
| 24 | 自定义应用 | 中 | |
Quick Reference
快速参考
1. Content Modeling (CRITICAL)
1. 内容建模(关键)
- - Follow atomic design for components
model-component-structure - - Configure field types with validation
model-field-configuration - - Manage block nesting with restrictions
model-block-nesting - - Use consistent naming (snake_case)
model-naming-conventions
- - 遵循原子设计构建组件
model-component-structure - - 配置带验证规则的字段类型
model-field-configuration - - 通过限制规则管理块嵌套
model-block-nesting - - 使用统一命名规范(snake_case)
model-naming-conventions
2. SDK Integration (CRITICAL)
2. SDK集成(关键)
- - Always apply storyblokEditable() to components
sdk-storyblok-editable - - Register all components globally
sdk-component-registration - - Render rich text with custom resolvers
sdk-richtext-rendering
- - 始终为组件应用storyblokEditable()
sdk-storyblok-editable - - 全局注册所有组件
sdk-component-registration - - 使用自定义解析器渲染富文本
sdk-richtext-rendering
3. Visual Editor (CRITICAL)
3. 可视化编辑器(关键)
- - Configure Storyblok Bridge correctly
editor-bridge-setup - - Handle draft/published content properly
editor-draft-published
- - 正确配置Storyblok Bridge
editor-bridge-setup - - 妥善处理草稿/已发布内容
editor-draft-published
4. Performance & Caching (CRITICAL)
4. 性能与缓存(关键)
- - Use Image Service for optimized delivery
perf-image-optimization - - Implement proper cache invalidation with cv parameter
perf-cache-invalidation - - API and content performance monitoring
perf-monitoring
- - 使用Image Service实现优化交付
perf-image-optimization - - 结合cv参数实现合理的缓存失效
perf-cache-invalidation - - API与内容性能监控
perf-monitoring
5. Security & Authentication (CRITICAL)
5. 安全与认证(关键)
- - Secure API token management
security-token-handling - - RBAC and access control configuration
security-roles-permissions
- - 安全管理API令牌
security-token-handling - - 配置RBAC与访问控制
security-roles-permissions
6. Field Plugins (HIGH)
6. 字段插件(高)
- - Build field plugins with @storyblok/field-plugin SDK
plugin-field-development
- - 使用@storyblok/field-plugin SDK构建字段插件
plugin-field-development
7. API Development (HIGH)
7. API开发(高)
- - Use Content Delivery API correctly with pagination
api-content-delivery - - Use GraphQL API for optimized queries
api-graphql - - Use Management API for CRUD operations
api-management
- - 结合分页功能正确使用内容交付API
api-content-delivery - - 使用GraphQL API实现优化查询
api-graphql - - 使用管理API执行增删改查操作
api-management
8. Internationalization (HIGH)
8. 国际化(高)
- - Implement field-level translations correctly
i18n-field-translation - - Folder-level translations with Dimensions app
i18n-folder-level
- - 正确实现字段级翻译
i18n-field-translation - - 通过Dimensions应用实现文件夹级翻译
i18n-folder-level
9. Next.js Integration (HIGH)
9. Next.js集成(高)
- - Integrate with Next.js App Router and RSC
nextjs-app-router
- - 与Next.js App Router和RSC集成
nextjs-app-router
10. Nuxt Integration (HIGH)
10. Nuxt集成(高)
- - Configure @storyblok/nuxt module correctly
nuxt-integration
- - 正确配置@storyblok/nuxt模块
nuxt-integration
11. App Development (HIGH)
11. 应用开发(高)
- - Build tool and space plugins with App Bridge
app-tool-plugins
- - 使用App Bridge构建工具和空间插件
app-tool-plugins
12. Space & Asset Management (HIGH)
12. 空间与资产管理(高)
- - Organize assets and datasources
space-asset-management - - Multi-space architecture for enterprise
space-multi-environment
- - 管理资产与数据源
space-asset-management - - 面向企业的多空间架构
space-multi-environment
13. Webhooks & Automation (MEDIUM-HIGH)
13. Webhooks与自动化(中高)
- - Configure webhooks for content events
webhook-configuration
- - 为内容事件配置Webhooks
webhook-configuration
14. Workflows & Publishing (MEDIUM-HIGH)
14. 工作流与发布(中高)
- - Use Releases for scheduled publishing
workflow-releases - - Pipeline stages for content staging
workflow-pipelines
- - 使用Releases功能实现定时发布
workflow-releases - - 为内容 staging 设置流水线阶段
workflow-pipelines
15. CLI & DevOps (MEDIUM)
15. CLI与DevOps(中)
- - Use CLI for component schema management
cli-component-sync
- - 使用CLI管理组件架构
cli-component-sync
16. Testing & Quality (MEDIUM)
16. 测试与质量(中)
- - Set up preview and production environments
test-preview-environments - - Unit, integration, and E2E testing strategies
test-unit-integration
- - 设置预览与生产环境
test-preview-environments - - 单元测试、集成测试与E2E测试策略
test-unit-integration
17. Rich Text & Media (MEDIUM)
17. 富文本与媒体(中)
- - Handle rich text media correctly
richtext-media-handling
- - 正确处理富文本媒体
richtext-media-handling
18. Common Patterns (HIGH)
18. 通用模式(高)
- - Generate and use TypeScript types
pattern-typescript - - Implement robust error handling
pattern-error-handling - - Debugging and troubleshooting guide
pattern-debugging - - Story links, relations, and reference resolution
pattern-relations-references
- - 生成并使用TypeScript类型
pattern-typescript - - 实现健壮的错误处理机制
pattern-error-handling - - 调试与故障排除指南
pattern-debugging - - 故事链接、关联与引用解析
pattern-relations-references
19. SEO & Structured Data (HIGH)
19. SEO与结构化数据(高)
- - JSON-LD, Open Graph, and sitemap configuration
seo-structured-data
- - JSON-LD、Open Graph与站点地图配置
seo-structured-data
20. E-commerce Integration (HIGH)
20. 电商集成(高)
- - Commerce platform integration patterns
ecommerce-integration
- - 电商平台集成模式
ecommerce-integration
21. Content Migration (MEDIUM-HIGH)
21. 内容迁移(中高)
- - Content migration strategies and tooling
migration-patterns
- - 内容迁移策略与工具
migration-patterns
22. AI Features (MEDIUM)
22. AI功能(中)
- - Storyblok AI capabilities and RAG preparation
ai-content-features
- - Storyblok AI功能与RAG准备
ai-content-features
23. Collaboration (MEDIUM)
23. 协作功能(中)
- - Real-time editing, comments, and conflict resolution
collaboration-realtime
- - 实时编辑、评论与冲突解决
collaboration-realtime
24. Custom Apps (MEDIUM)
24. 自定义应用(中)
- - Sidebar apps and tool plugins beyond field plugins
app-custom-sidebar
- - 字段插件之外的侧边栏应用与工具插件
app-custom-sidebar
Core Principles
核心原则
Visual Editor First
优先考虑可视化编辑器
Storyblok's Visual Editor is the primary editing experience:
- Always apply to components
storyblokEditable() - Configure the Storyblok Bridge for live editing
- Test components in the Visual Editor, not just code
Storyblok的可视化编辑器是主要的编辑体验:
- 始终为组件应用
storyblokEditable() - 正确配置Storyblok Bridge以支持实时编辑
- 在可视化编辑器中测试组件,而不只是在代码中测试
Content Delivery vs Management API
内容交付API vs 管理API
| API | Purpose | Token | Cache |
|---|---|---|---|
| Content Delivery | Fetch content | Public/Preview | CDN |
| Management | CRUD operations | Personal/OAuth | None |
| GraphQL | Read-only queries | Public/Preview | CDN |
| API | 用途 | 令牌 | 缓存 |
|---|---|---|---|
| 内容交付API | 获取内容 | 公开/预览令牌 | CDN缓存 |
| 管理API | 增删改查操作 | 个人/OAuth令牌 | 无缓存 |
| GraphQL API | 只读查询 | 公开/预览令牌 | CDN缓存 |
Framework Integration
框架集成
| Framework | SDK | Special Features |
|---|---|---|
| React | | useStoryblokState, RSC support, StoryblokServerComponent |
| Vue | | v-editable directive |
| Nuxt | | Auto-registration, useAsyncStoryblok, deep option |
| Next.js | | Draft mode, ISR, App Router |
| Astro | | Hybrid rendering |
| 框架 | SDK | 特色功能 |
|---|---|---|
| React | | useStoryblokState、RSC支持、StoryblokServerComponent |
| Vue | | v-editable指令 |
| Nuxt | | 自动注册、useAsyncStoryblok、deep选项 |
| Next.js | | 草稿模式、ISR、App Router |
| Astro | | 混合渲染 |
Token Security
令牌安全
Never expose these in client-side code:
- Preview tokens (show draft content)
- Personal access tokens (full write access)
- OAuth tokens (scoped access)
Safe for client-side:
- Public tokens (read-only published content)
切勿在客户端代码中暴露以下令牌:
- 预览令牌(用于展示草稿内容)
- 个人访问令牌(拥有完整写入权限)
- OAuth令牌(权限范围受限)
可安全用于客户端的令牌:
- 公开令牌(仅能读取已发布内容)
How to Use
使用方法
Read individual rule files for detailed explanations and code examples:
rules/model-component-structure.md
rules/sdk-storyblok-editable.md
rules/editor-bridge-setup.md
rules/perf-image-optimization.md
rules/security-token-handling.mdEach rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Configuration tables and references
阅读单个规则文件获取详细说明和代码示例:
rules/model-component-structure.md
rules/sdk-storyblok-editable.md
rules/editor-bridge-setup.md
rules/perf-image-optimization.md
rules/security-token-handling.md每个规则文件包含:
- 简要说明该规则的重要性
- 错误代码示例及解释
- 正确代码示例及解释
- 配置表和参考资料