Skip to content

Commit 6cb3c8a

Browse files
jesserockzclaude
andauthored
Create Claude instructions for ESPHome docs (#5641)
Co-authored-by: Claude <[email protected]>
1 parent 1aae596 commit 6cb3c8a

File tree

1 file changed

+300
-0
lines changed

1 file changed

+300
-0
lines changed

.claude/instructions.md

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
# ESPHome Documentation Instructions
2+
3+
## Documentation Style & Formatting
4+
5+
### Language and Text Formatting
6+
- **Always use English** for all documentation
7+
- **Section titles**: Use Title Case formatting (e.g., "Configuration Variables", "Getting Started")
8+
- **Line length**: Wrap lines at **maximum 120 characters** for readability
9+
- **Tone**: Be clear, concise, and technical. Use present tense and active voice where possible
10+
11+
### Content Guidelines
12+
13+
#### Component Documentation
14+
- Provide **minimal examples** that exclude optional configuration variables
15+
- Examples should focus on the essential configuration only
16+
- When components have dependencies:
17+
- Include a sentence explaining the dependency
18+
- Provide a link to the dependency's documentation
19+
- Do NOT include the dependent component's configuration in the example
20+
21+
#### Pin References
22+
- **ALWAYS use the literal string `GPIOXX`** in documentation examples
23+
- The `XX` is literal - do NOT replace with actual numbers like `GPIO16`
24+
- **Exception**: Only use specific pin numbers when documenting hardware with fixed pins
25+
- This ensures examples work across different boards and users replace with their actual pins
26+
27+
## File Structure & Format
28+
29+
### Frontmatter Requirements
30+
Every documentation page **must** start with YAML frontmatter:
31+
32+
```yaml
33+
---
34+
title: Component Name
35+
description: Brief description of the component
36+
---
37+
```
38+
39+
**Important**:
40+
- The `title` field becomes the H1 heading automatically
41+
- **Do NOT** repeat the title as a `# Heading` in the markdown content
42+
- The description should be concise (1-2 sentences)
43+
44+
### Heading Hierarchy
45+
- **Start with H2 (`##`)** for main sections
46+
- Never use H1 (`#`) in the content (it's generated from frontmatter)
47+
- Use proper nesting: H2 → H3 → H4
48+
- Examples:
49+
```markdown
50+
## Configuration Variables
51+
52+
### Required Options
53+
54+
#### Advanced Settings
55+
```
56+
57+
## Markdown Syntax Standards
58+
59+
### Code Formatting
60+
61+
#### Inline Code
62+
- Use single backticks for inline code: `variable_name`, `sensor`, `GPIOXX`
63+
- Use for: component names, variable names, short code snippets, pin numbers
64+
65+
#### Code Blocks
66+
- Use triple backticks with language identifier:
67+
68+
```yaml
69+
sensor:
70+
- platform: dht
71+
pin: GPIOXX
72+
temperature:
73+
name: "Living Room Temperature"
74+
```
75+
76+
- Common language identifiers: `yaml`, `cpp`, `python`, `bash`
77+
78+
### Configuration Variables
79+
80+
Use special formatting to indicate parameter requirements:
81+
82+
- **Config key**: Always bold
83+
- **Required** label: Bold
84+
- *Optional* label: Italics
85+
86+
Example:
87+
```markdown
88+
- **pin** (**Required**, Pin): The pin where the sensor is connected.
89+
- **update_interval** (*Optional*, Time): The interval to check the sensor. Defaults to `60s`.
90+
```
91+
92+
### Links
93+
94+
#### External Links
95+
Standard markdown syntax:
96+
```markdown
97+
[ESP32 Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
98+
```
99+
100+
#### Internal Documentation Links
101+
Use **relative paths** starting with `/`:
102+
```markdown
103+
- See [WiFi](/components/wifi) for WiFi configuration
104+
- Configure [I²C](/components/i2c) first
105+
- Check out the [Deep Sleep](/components/deep_sleep) component
106+
```
107+
108+
#### Custom Anchors
109+
Use Hugo shortcodes for custom anchor points:
110+
```markdown
111+
{{< anchor "custom-section-name" >}}
112+
```
113+
114+
Reference them with:
115+
```markdown
116+
See [this section](#custom-section-name) for details.
117+
```
118+
119+
### Visual Elements
120+
121+
#### Images
122+
123+
**Optimization Requirements:**
124+
- **ALWAYS optimize images** before adding (use TinyPNG/TinyJPG)
125+
- **Maximum size**: ~1000x800 pixels
126+
- All images must be as small as possible to minimize page load times
127+
128+
**Directory Structure:**
129+
- **Component images**: Store in section-specific directories:
130+
- General components: `content/components/images/`
131+
- Sensor components: `content/components/sensor/images/`
132+
- Display components: `content/components/display/images/`
133+
- Binary sensors: `content/components/binary_sensor/images/`
134+
- Guides: `content/guides/images/`
135+
- Cookbook: `content/cookbook/images/`
136+
- And so on for each major section
137+
- **Global/shared images and thumbnails**: Store in `static/images/`
138+
139+
**Referencing Images:**
140+
141+
**Default**: Use standard markdown syntax:
142+
```markdown
143+
![Alt text](filename.png)
144+
```
145+
146+
The filename (no path) references the image in the section's images directory.
147+
148+
**When shortcode features are needed**: Use Hugo `img` shortcode for captions, width control, or alignment:
149+
```markdown
150+
{{< img src="filename.png" alt="Image description" caption="Optional caption text" width="75%" class="align-center" >}}
151+
```
152+
153+
Shortcode parameters:
154+
- `src`: Just the filename (no path) - looks in the section's images directory
155+
- `alt`: Alternative text for accessibility
156+
- `caption`: Descriptive caption (only available in shortcode)
157+
- `width`: Percentage control like "75%", "50%" (only available in shortcode)
158+
- `class`: Usually "align-center" for centering (only available in shortcode)
159+
160+
Examples:
161+
```markdown
162+
![Debug output](debug.png)
163+
164+
{{< img src="debug.png" alt="Debug component output" caption="Example debug component output." class="align-center" >}}
165+
```
166+
167+
#### Component Thumbnails
168+
- **Aspect ratio**: 8:10 or 10:8 (portrait or landscape orientation)
169+
- **Format**: SVG (heavily compressed) or JPG (max 300x300px)
170+
- **Location**: `static/images/` directory
171+
- **Reference**: Use `/images/filename` path in frontmatter or links
172+
- Used in component listings and cards
173+
174+
### Alerts and Callouts
175+
176+
Use GitHub-style alert syntax:
177+
178+
```markdown
179+
> [!NOTE]
180+
> This is an informational note for users.
181+
182+
> [!WARNING]
183+
> This warns users about potential issues or breaking changes.
184+
185+
> [!TIP]
186+
> This provides helpful tips and best practices.
187+
```
188+
189+
**When to use**:
190+
- `NOTE`: General information, clarifications, important context
191+
- `WARNING`: Potential issues, breaking changes, compatibility notes
192+
- `TIP`: Optimization suggestions, best practices, pro tips
193+
194+
## Git Workflow
195+
196+
### Branch Strategy
197+
- **Bug fixes and documentation corrections**: Target the `current` branch
198+
- **New features and new component docs**: Target the `next` branch
199+
- **Create separate branches** for each pull request (one PR per feature/fix)
200+
201+
### Commit Messages
202+
- Use clear, descriptive commit messages
203+
- Format: `[component] Brief description of change`
204+
- Examples:
205+
- `[dht] Fix temperature sensor example`
206+
- `[wifi] Add WPA3 configuration documentation`
207+
- `[docs] Update contributing guidelines`
208+
209+
### Pull Request Process
210+
1. Ensure all changes are committed to the feature branch
211+
2. Push to origin: `git push -u origin <branch-name>`
212+
3. All automated tests must pass before review
213+
4. Follow retry logic for network failures (exponential backoff: 2s, 4s, 8s, 16s)
214+
215+
## Testing and Preview
216+
217+
### Local Preview with Docker
218+
To preview documentation locally:
219+
```bash
220+
docker run --rm -v "${PWD}/":/workspaces/esphome-docs -p 8000:8000 -it ghcr.io/esphome/esphome-docs
221+
```
222+
223+
Then access the preview at `http://<HOST_IP>:8000`
224+
225+
### Before Submitting
226+
- [ ] Check that all links work (internal and external)
227+
- [ ] Verify code examples are syntactically correct
228+
- [ ] Ensure images are optimized and properly sized
229+
- [ ] Confirm line length is ≤120 characters
230+
- [ ] Validate YAML frontmatter is present and correct
231+
- [ ] Test that headings follow proper hierarchy (H2→H3→H4)
232+
- [ ] Verify no H1 headings in content (title comes from frontmatter)
233+
234+
## Common Patterns
235+
236+
### Component Page Structure
237+
A typical component page should follow this structure:
238+
239+
```markdown
240+
---
241+
title: Component Name
242+
description: One-line description of what the component does
243+
---
244+
245+
Brief introduction paragraph explaining what the component is and what it does.
246+
247+
## Configuration
248+
249+
Minimal configuration example here.
250+
251+
## Configuration Variables
252+
253+
List of all configuration variables with proper formatting.
254+
255+
## Examples
256+
257+
Additional examples showing common use cases.
258+
259+
## See Also
260+
261+
- Related components and guides
262+
```
263+
264+
### Writing Configuration Examples
265+
266+
**Good example** (minimal, focused):
267+
```yaml
268+
sensor:
269+
- platform: dht
270+
pin: GPIOXX
271+
temperature:
272+
name: "Temperature"
273+
```
274+
275+
**Bad example** (includes unnecessary optional parameters):
276+
```yaml
277+
sensor:
278+
- platform: dht
279+
pin: GPIOXX
280+
model: AUTO_DETECT
281+
update_interval: 60s
282+
temperature:
283+
name: "Temperature"
284+
id: temp_sensor
285+
unit_of_measurement: "°C"
286+
accuracy_decimals: 1
287+
```
288+
289+
## Key Reminders
290+
291+
1. **Never duplicate the title** - it's automatically generated from frontmatter
292+
2. **Start with H2**, not H1
293+
3. **Wrap at 120 characters** maximum
294+
4. **Use Title Case** for section headings
295+
5. **Optimize images** before adding them
296+
6. **Keep examples minimal** - only essential configuration
297+
7. **Use literal `GPIOXX`** - the XX is literal, don't replace with numbers (unless fixed hardware)
298+
8. **Link to dependencies** instead of including their config
299+
9. **Target correct branch** (current vs next)
300+
10. **GitHub CLI not available** - ask user for GitHub information if needed

0 commit comments

Comments
 (0)