|
| 1 | +# Block Documentation Guide |
| 2 | + |
| 3 | +Blocks require two types of documentation: developer-facing documentation for maintainers, and author-facing documentation for content creators using the CMS. |
| 4 | + |
| 5 | +## Developer Documentation |
| 6 | + |
| 7 | +Developer documentation helps future developers (including AI agents) understand, maintain, and modify block code. |
| 8 | + |
| 9 | +### When Code Comments Are Sufficient |
| 10 | + |
| 11 | +Most blocks are simple and self-contained. For these blocks, clear code comments are all you need: |
| 12 | + |
| 13 | +```javascript |
| 14 | +/** |
| 15 | + * decorate the block |
| 16 | + * @param {Element} block the block element |
| 17 | + */ |
| 18 | +export default async function decorate(block) { |
| 19 | + // Transform each row into a card |
| 20 | + const rows = block.querySelectorAll(':scope > div'); |
| 21 | + rows.forEach((row) => { |
| 22 | + row.classList.add('card'); |
| 23 | + }); |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +**Use code comments when:** |
| 28 | +- The block has straightforward decoration logic |
| 29 | +- The content model is simple and obvious from the code |
| 30 | +- There are 0-2 variants |
| 31 | +- No complex data fetching or external dependencies |
| 32 | + |
| 33 | +### When to Add a README.md |
| 34 | + |
| 35 | +For complex blocks, add a brief `README.md` in the block folder (`blocks/{block-name}/README.md`). |
| 36 | + |
| 37 | +**Add a README when:** |
| 38 | +- The block has many variants (3+) with different behaviors |
| 39 | +- Complex decoration logic that isn't immediately obvious |
| 40 | +- Special setup requirements |
| 41 | +- Non-obvious authoring patterns |
| 42 | + |
| 43 | +**Keep READMEs brief and scannable:** |
| 44 | +- One-line summary of what the block does |
| 45 | +- List of variants and what they do |
| 46 | +- Key authoring requirements (if non-obvious) |
| 47 | +- Links to related blocks or documentation |
| 48 | + |
| 49 | +**Example README structure:** |
| 50 | +```markdown |
| 51 | +# Gallery Block |
| 52 | + |
| 53 | +Displays images in a responsive grid layout. |
| 54 | + |
| 55 | +## Variants |
| 56 | +- `masonry` - Masonry-style layout with variable heights |
| 57 | +- `carousel` - Carousel with navigation arrows |
| 58 | +- `lightbox` - Opens images in a lightbox overlay |
| 59 | + |
| 60 | +## Content Model |
| 61 | +- Each row = one image |
| 62 | +- First column = image |
| 63 | +- Second column (optional) = caption |
| 64 | + |
| 65 | +## Notes |
| 66 | +- Images are lazy-loaded using Intersection Observer |
| 67 | +- Carousel variant requires at least 3 images |
| 68 | +``` |
| 69 | + |
| 70 | +## Author-Facing Documentation |
| 71 | + |
| 72 | +Author documentation helps content authors understand how to use the block in the CMS. This documentation typically exists as draft/library content in the CMS itself, not in the codebase. |
| 73 | + |
| 74 | +### When Author Documentation Is Needed |
| 75 | + |
| 76 | +Almost all blocks should have author-facing documentation. |
| 77 | + |
| 78 | +**Skip author documentation only for:** |
| 79 | +- Deprecated blocks that should no longer be used but can't be removed yet |
| 80 | +- Special-purpose blocks used very infrequently on a need-to-know basis |
| 81 | +- Auto-blocked blocks that shouldn't be used directly by authors |
| 82 | + |
| 83 | +### When to Update Author Documentation |
| 84 | + |
| 85 | +Author documentation must be kept in sync with the block implementation. Update whenever: |
| 86 | +- ✅ Variants are added, removed, or modified |
| 87 | +- ✅ The content structure changes |
| 88 | +- ✅ Block behavior or functionality changes |
| 89 | +- ✅ New authoring best practices are discovered |
| 90 | +- ✅ Common authoring mistakes are identified |
| 91 | + |
| 92 | +### Where Author Documentation Lives |
| 93 | + |
| 94 | +Different projects use different approaches for author documentation. Your project may use one of these: |
| 95 | + |
| 96 | +#### 1. Sidekick Library (Google Drive/SharePoint) |
| 97 | + |
| 98 | +Uses https://github.com/adobe/franklin-sidekick-library |
| 99 | + |
| 100 | +**How to detect:** |
| 101 | +- Check for `/tools/sidekick/library.html` in the codebase |
| 102 | +- Look for `.library.json` or library metadata |
| 103 | + |
| 104 | +**If present:** |
| 105 | +- Guide user to add/update block documentation in the library |
| 106 | +- Library content is typically maintained in Google Drive or SharePoint |
| 107 | +- Documentation includes block examples, variants, and usage guidance |
| 108 | + |
| 109 | +#### 2. Document Authoring (DA) Library |
| 110 | + |
| 111 | +Uses https://docs.da.live/administrators/guides/setup-library |
| 112 | + |
| 113 | +**How to detect:** |
| 114 | +- Different implementation than Sidekick Library |
| 115 | +- Check for DA-specific library configuration |
| 116 | +- Look for library paths in project configuration |
| 117 | + |
| 118 | +**If present:** |
| 119 | +- Guide user to update block documentation in DA library |
| 120 | +- DA Library has different authoring and management patterns |
| 121 | + |
| 122 | +#### 3. Universal Editor (UE) Projects |
| 123 | + |
| 124 | +**How to detect:** |
| 125 | +- Look for Universal Editor configuration |
| 126 | +- AEM as a Cloud Service project structure |
| 127 | + |
| 128 | +**Characteristics:** |
| 129 | +- Often skip dedicated author documentation libraries |
| 130 | +- May use inline help or other mechanisms |
| 131 | +- Documentation approach varies by project |
| 132 | + |
| 133 | +#### 4. Simple Documentation Pages |
| 134 | + |
| 135 | +Some projects maintain simple documentation under `/drafts` or `/docs`. |
| 136 | + |
| 137 | +**How to detect:** |
| 138 | +- Look for `/drafts/blocks/` or similar paths |
| 139 | +- Check for documentation pages in the project |
| 140 | + |
| 141 | +**If present:** |
| 142 | +- Pages contain authoring guides and block examples |
| 143 | +- Update the relevant documentation page for the block |
| 144 | + |
| 145 | +### What to Include in Author Documentation |
| 146 | + |
| 147 | +The specific content varies by project, but typically includes: |
| 148 | + |
| 149 | +**Essential information:** |
| 150 | +- Block name and purpose |
| 151 | +- When/where to use this block |
| 152 | +- Content structure (what goes in each row/column) |
| 153 | +- Available variants and what they do |
| 154 | +- Examples showing different use cases |
| 155 | + |
| 156 | +**Helpful additions:** |
| 157 | +- Screenshots of the block in action |
| 158 | +- Common mistakes to avoid |
| 159 | +- Best practices for content authoring |
| 160 | +- Tips for different screen sizes |
| 161 | + |
| 162 | +**Example author documentation content:** |
| 163 | + |
| 164 | +```markdown |
| 165 | +# Hero Block |
| 166 | + |
| 167 | +Creates a large, prominent banner at the top of a page. |
| 168 | + |
| 169 | +## When to Use |
| 170 | +- Homepage or landing page headers |
| 171 | +- Section introductions |
| 172 | +- Campaign announcements |
| 173 | + |
| 174 | +## Content Structure |
| 175 | +- Row 1, Column 1: Heading text |
| 176 | +- Row 1, Column 2: Hero image |
| 177 | +- Row 2 (optional): Body text |
| 178 | +- Row 3 (optional): Call-to-action link(s) |
| 179 | + |
| 180 | +## Variants |
| 181 | +- `dark` - Dark background with light text |
| 182 | +- `centered` - Center-aligned text (default is left-aligned) |
| 183 | +- `full-width` - Full viewport width (default is contained) |
| 184 | + |
| 185 | +## Examples |
| 186 | +[Include visual examples of the block with different variants] |
| 187 | + |
| 188 | +## Tips |
| 189 | +- Use high-quality images at least 1920px wide |
| 190 | +- Keep heading text under 60 characters |
| 191 | +- Limit to 1-2 call-to-action buttons |
| 192 | +``` |
| 193 | + |
| 194 | +### Process for Updating Author Documentation |
| 195 | + |
| 196 | +**As an agent, follow these steps:** |
| 197 | + |
| 198 | +1. **Identify the documentation approach:** |
| 199 | + ```bash |
| 200 | + # Check for Sidekick Library |
| 201 | + ls tools/sidekick/library.html 2>/dev/null |
| 202 | + |
| 203 | + # Check for docs/drafts |
| 204 | + ls drafts/blocks/ 2>/dev/null |
| 205 | + ls docs/blocks/ 2>/dev/null |
| 206 | + ``` |
| 207 | + |
| 208 | +2. **Determine what changed:** |
| 209 | + - New variants added/removed? |
| 210 | + - Content structure modified? |
| 211 | + - Behavior changes? |
| 212 | + - Best practices updated? |
| 213 | + |
| 214 | +3. **Guide the user:** |
| 215 | + - Explain what documentation needs updating |
| 216 | + - Identify which documentation approach the project uses |
| 217 | + - Provide specific guidance based on the approach |
| 218 | + - Help draft documentation content if requested |
| 219 | + |
| 220 | +4. **Example guidance for user:** |
| 221 | + ``` |
| 222 | + The block's content structure has changed. You'll need to update the |
| 223 | + author documentation in the Sidekick Library: |
| 224 | +
|
| 225 | + 1. Open the library in Google Drive/SharePoint |
| 226 | + 2. Find the existing documentation for the {block-name} block |
| 227 | + 3. Update the "Content Structure" section to reflect: |
| 228 | + - Row 1 now accepts an optional icon |
| 229 | + - Row 2 is no longer used |
| 230 | + 4. Update any examples showing the old structure |
| 231 | + ``` |
| 232 | + |
| 233 | +### Documentation Maintenance Checklist |
| 234 | + |
| 235 | +When completing a block implementation, verify: |
| 236 | + |
| 237 | +- [ ] Developer docs are clear (code comments or README) |
| 238 | +- [ ] Author documentation approach identified |
| 239 | +- [ ] Changes that require author docs updates documented |
| 240 | +- [ ] User guided on where/how to update author docs |
| 241 | +- [ ] Examples in author docs match current implementation |
| 242 | +- [ ] Variant documentation is complete and accurate |
| 243 | + |
| 244 | +## Common Documentation Mistakes to Avoid |
| 245 | + |
| 246 | +**❌ Don't create documentation that gets out of sync:** |
| 247 | +- Avoid duplicating implementation details in multiple places |
| 248 | +- Keep documentation close to the code when possible |
| 249 | +- Use automation where available |
| 250 | + |
| 251 | +**❌ Don't over-document simple blocks:** |
| 252 | +- Clear code is often better than comments |
| 253 | +- Don't explain what is obvious from the code |
| 254 | + |
| 255 | +**❌ Don't under-document complex blocks:** |
| 256 | +- Complex logic needs explanation |
| 257 | +- Variants need clear documentation |
| 258 | +- Non-obvious patterns need guidance |
| 259 | + |
| 260 | +**❌ Don't forget to update author docs:** |
| 261 | +- Author docs are often overlooked |
| 262 | +- Out-of-date docs confuse content authors |
| 263 | +- Always update when the content model changes |
0 commit comments