cloudcannon-snippets
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloudCannon Snippets
CloudCannon Snippets
Snippets let editors insert and edit complex markup (components, shortcodes, embeds) inside CloudCannon's rich text Content Editor. This skill covers both the SSG layer (how components are imported/built) and the CloudCannon layer ( config that teaches the editor the syntax).
_snippetsSnippets 让编辑者能够在 CloudCannon 的富文本 Content Editor 中插入和编辑复杂标记(组件、shortcode、嵌入内容)。该 skill 涵盖 SSG 层(组件的导入/构建方式)以及 CloudCannon 层(通过 配置让编辑器识别语法)。
_snippetsWhen to use
何时使用
- Adding snippet support to a new or existing CloudCannon site
- Configuring MDX components, Hugo shortcodes or Eleventy shortcodes and includes for the Content Editor
- Adding inline HTML snippets (figure, video, details) to markdown content
- Debugging snippet parsing, round-trip, or toolbar issues
- 为新的或现有 CloudCannon 站点添加 snippet 支持
- 配置 MDX 组件、Hugo shortcode 或 Eleventy shortcode 与 include,以供 Content Editor 使用
- 向 markdown 内容中添加内联 HTML snippet(figure、video、details)
- 调试 snippet 解析、往返或工具栏问题
When not to use
何时不应使用
- The component should be a page-builder block, not inline content — editors pick blocks from a structure, not from the rich text toolbar. See and the migration skill's page-building guide.
cloudcannon-configuration - Making an existing rendered element editable in place — that is . Snippets insert new markup; editable regions edit markup already on the page.
cloudcannon-visual-editing - Plain markdown content with no components or inline HTML — no snippet configuration is needed
- 组件应当是 page-builder block,而不是内联内容——编辑器从结构中选择 block,而不是从富文本工具栏中选择。请参阅 和迁移 skill 的页面构建指南。
cloudcannon-configuration - 让现有的已渲染元素支持原地编辑——这属于 。Snippet 会插入新标记;可编辑区域用于编辑页面上的现有标记。
cloudcannon-visual-editing - 不含组件或内联 HTML 的纯 markdown 内容——无需配置 snippet
Contents
目录
| Doc | When to read |
|---|---|
| snippets.md | Start here. Overview of both layers, configuration hierarchy, which approach to use, snippet properties, toolbar setup, raw HTML snippets in |
| template-based.md | Component syntax matches a built-in template (most common path) |
| raw.md | Component needs custom syntax (e.g. |
| built-in-templates.md | Understanding built-in MDX, Hugo and Eleventy templates, the import bundle, parser internals |
| gotchas.md | Preventative rules — the pitfalls and their workarounds |
| troubleshooting.md | Symptom index — start here when something is already broken, it routes to the rule |
SSG-specific:
| SSG | Doc |
|---|---|
| Astro | astro/overview.md — MDX stack, |
| Hugo | hugo/overview.md — shortcodes, built-in shortcode imports, picking a Hugo template |
| Eleventy | eleventy/overview.md — shortcodes and includes, picking a Liquid or Nunjucks template, |
| 文档 | 阅读时机 |
|---|---|
| snippets.md | 从这里开始。概述两个层、配置层级、应采用哪种方式、snippet 属性、工具栏设置,以及 |
| template-based.md | 组件语法与内置模板匹配(最常用路径) |
| raw.md | 组件需要自定义语法(例如 |
| built-in-templates.md | 了解内置的 MDX、Hugo 和 Eleventy 模板、导入 bundle 与 parser 内部机制 |
| gotchas.md | 预防性规则——常见陷阱及其解决方法 |
| troubleshooting.md | 症状索引——当已有功能出现问题时从这里开始,它会将你引导至对应规则 |
SSG 专用:
| SSG | 文档 |
|---|---|
| Astro | astro/overview.md——MDX stack、 |
| Hugo | hugo/overview.md——shortcode、内置 shortcode 导入、选择 Hugo 模板 |
| Eleventy | eleventy/overview.md——shortcode 和 include、选择 Liquid 或 Nunjucks 模板、 |
Quick decision
快速决策
| Case | Approach |
|---|---|
| Component syntax matches a built-in template | Template-based — see template-based.md |
| Extra syntax, SSG directives, custom parsing | Raw — see raw.md |
Inline HTML in | Raw snippets — see snippets.md § Raw snippets for inline HTML |
| Same component at the start or end of 3+ files in a collection | Maybe a layout field — apply the tests in snippets.md § Snippet or layout field? and ask the user |
Most setups use template-based for simple components and raw for anything with SSG-specific directives.
| 场景 | 方式 |
|---|---|
| 组件语法与内置模板匹配 | 基于模板——请参阅 template-based.md |
| 额外语法、SSG 指令、自定义解析 | Raw——请参阅 raw.md |
| Raw snippet——请参阅 snippets.md § .md 文件中的原始 HTML snippet |
| 同一组件出现在某个 collection 的 3 个及以上文件的开头或结尾 | 可能是 layout 字段——请应用 snippets.md § Snippet 还是 layout 字段? 中的测试并询问用户 |
大多数设置对于简单组件使用基于模板的方式,对于包含 SSG 专用指令的内容使用 raw。
Checklist
检查清单
Read this before starting and verify every item when done.
- Every component used in content files has a entry
_snippets - includes
_editableson relevant content blockssnippet: true - Each snippet round-trips correctly (insert via editor, save, reopen — markup unchanged)
- are configured for snippet fields (image fields get
_inputs, etc.)type: image - Snippet previews are configured (for image-bearing snippets)
view: gallery - uses static values (not
picker_previewlookups, which don't resolve in picker context)key:
开始前请阅读本文,并在完成后逐项验证。
- 内容文件中使用的每个组件都有 条目
_snippets - 在相关内容块中包含
_editablessnippet: true - 每个 snippet 都能正确往返(通过编辑器插入、保存、重新打开——标记保持不变)
- 已为 snippet 字段配置 (图片字段使用
_inputs,等等)type: image - 已配置 snippet 预览(包含图片的 snippet 使用 )
view: gallery - 使用静态值(不要使用
picker_preview查找,因为它们在 picker 上下文中无法解析)key:
Common mistakes
常见错误
| Excuse | Reality |
|---|---|
| "The built-in templates handle this" | Verify the round-trip. Built-in templates have known edge cases — see gotchas.md. |
| "I'll configure the snippet toolbar later" | No toolbar means editors can't insert snippets. Add |
| "This component is too niche for a snippet" | If editors encounter it in content, they need to be able to edit it. Configure it. |
| "Import statements in content are fine" | Use auto-import (Astro: |
"I can use | Don't. It loads catchall matchers that can match incorrectly. Write explicit |
"I configured | Without |
| "Inline image grid in MDX is fine as raw HTML" | Editors can't safely edit raw |
| 常见说法 | 实际情况 |
|---|---|
| “内置模板会处理这个问题” | 验证往返行为。内置模板存在已知的边缘情况——请参阅 gotchas.md。 |
| “我稍后会配置 snippet 工具栏” | 没有工具栏,编辑者就无法插入 snippet。现在就在 |
| “这个组件太冷门,不适合做 snippet” | 如果编辑者会在内容中遇到它,就需要能够编辑它。请进行配置。 |
| “内容中的 import 语句没问题” | 使用 auto-import(Astro: |
“这个我可以使用 | 不要这样做。它会加载 catchall matcher,可能会错误匹配。请编写显式的 |
“我配置了 | 如果没有在 |
| “MDX 中的内联图片网格使用原始 HTML 没问题” | 编辑者无法安全地编辑原始 |