|
| 1 | +--- |
| 2 | +name: docusaurus-conventions |
| 3 | +description: Docusaurus file naming, syntax, and structure conventions for RoboLearn platform |
| 4 | +domain: authoring |
| 5 | +version: 1.0.0 |
| 6 | +created: 2025-11-29 |
| 7 | +triggers: |
| 8 | + - Creating lesson files |
| 9 | + - Creating module/chapter structure |
| 10 | + - Writing MDX content |
| 11 | + - Fixing Docusaurus build errors |
| 12 | +learned_from: |
| 13 | + - Module 1 ROS 2 implementation (2025-11-29) |
| 14 | + - 8 file extension fixes, 10 mermaid removals, 3 MDX syntax errors |
| 15 | +--- |
| 16 | + |
| 17 | +# Docusaurus Conventions Skill |
| 18 | + |
| 19 | +## Persona |
| 20 | + |
| 21 | +Think like a Docusaurus expert who ensures all content builds successfully on the first attempt. You understand the quirks of MDX parsing, file naming conventions, and how Docusaurus resolves document IDs. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Pre-Flight Questions |
| 26 | + |
| 27 | +Before creating or modifying any Docusaurus content, ask yourself: |
| 28 | + |
| 29 | +### 1. File Naming |
| 30 | +- **Q**: What file extension should I use? |
| 31 | + - **A**: Always `.md` (NOT `.mdx`) |
| 32 | + - **Why**: The project doesn't use MDX components; `.mdx` causes unnecessary complexity |
| 33 | + |
| 34 | +- **Q**: What should chapter/module index files be named? |
| 35 | + - **A**: Always `README.md` (NOT `index.md`) |
| 36 | + - **Why**: Docusaurus resolves `README.md` as the index; `index.md` can cause duplicate ID errors |
| 37 | + |
| 38 | +- **Q**: What naming pattern for lesson files? |
| 39 | + - **A**: `NN-descriptive-name.md` (e.g., `01-digital-to-physical.md`) |
| 40 | + - **Why**: Numeric prefix ensures correct ordering; descriptive name aids navigation |
| 41 | + |
| 42 | +### 2. MDX Syntax Safety |
| 43 | +- **Q**: Does my content contain `<` characters outside of code blocks? |
| 44 | + - **A**: Replace with spelled-out alternatives |
| 45 | + - **Examples**: |
| 46 | + - `<2 seconds` → `less than 2 seconds` |
| 47 | + - `<10 hours` → `under 10 hours` |
| 48 | + - `[<10 hrs` → `[under 10 hrs` |
| 49 | + - **Why**: MDX parser interprets `<` as JSX tag start, causing build errors |
| 50 | + |
| 51 | +- **Q**: Am I using comparison operators in prose? |
| 52 | + - **A**: Use words instead of symbols |
| 53 | + - **Examples**: |
| 54 | + - `latency < 100ms` → `latency under 100ms` or use inline code: `latency < 100ms` |
| 55 | + - `if (x < 5)` in code block is fine (code blocks are not parsed as MDX) |
| 56 | + |
| 57 | +### 3. Diagrams |
| 58 | +- **Q**: Am I using Mermaid diagrams? |
| 59 | + - **A**: NO - Mermaid plugin is not configured |
| 60 | + - **Alternatives**: |
| 61 | + - ASCII text diagrams for simple flows |
| 62 | + - Image files for complex diagrams |
| 63 | + - Code blocks showing structure |
| 64 | + - **Example replacement**: |
| 65 | + ``` |
| 66 | + # Instead of mermaid: |
| 67 | + ```mermaid |
| 68 | + graph TD |
| 69 | + A --> B |
| 70 | + ``` |
| 71 | +
|
| 72 | + # Use ASCII: |
| 73 | + ``` |
| 74 | + A → B → C |
| 75 | + └── D |
| 76 | + ``` |
| 77 | + ``` |
| 78 | +
|
| 79 | +### 4. Internal Links |
| 80 | +- **Q**: How should I link to other lessons? |
| 81 | + - **A**: Use relative paths with `.md` extension |
| 82 | + - **Examples**: |
| 83 | + - Same chapter: `[Next](./02-next-lesson.md)` |
| 84 | + - Different chapter: `[Overview](../chapter-2-topic/README.md)` |
| 85 | + - Module root: `[Module](../README.md)` |
| 86 | + - **Never use**: `.mdx` extension or `index.md` |
| 87 | +
|
| 88 | +--- |
| 89 | +
|
| 90 | +## Principles |
| 91 | +
|
| 92 | +### Principle 1: Build-First Validation |
| 93 | +**Before committing any content, verify it builds.** |
| 94 | +
|
| 95 | +```bash |
| 96 | +npm run build 2>&1 | tail -30 |
| 97 | +``` |
| 98 | + |
| 99 | +Expected: `[SUCCESS] Generated static files in "build"` |
| 100 | + |
| 101 | +If errors: |
| 102 | +1. Check for duplicate doc IDs (two files with same `id` frontmatter) |
| 103 | +2. Check for MDX syntax errors (unexpected character errors) |
| 104 | +3. Check for broken links (file not found warnings) |
| 105 | + |
| 106 | +### Principle 2: Consistent File Structure |
| 107 | + |
| 108 | +**Module structure:** |
| 109 | +``` |
| 110 | +docs/module-N-name/ |
| 111 | +├── README.md # Module overview (NOT index.md) |
| 112 | +├── chapter-1-topic/ |
| 113 | +│ ├── README.md # Chapter overview |
| 114 | +│ ├── 01-first-lesson.md |
| 115 | +│ ├── 02-second-lesson.md |
| 116 | +│ └── ... |
| 117 | +├── chapter-2-topic/ |
| 118 | +│ └── ... |
| 119 | +└── ... |
| 120 | +``` |
| 121 | + |
| 122 | +### Principle 3: Frontmatter ID Uniqueness |
| 123 | + |
| 124 | +**Every lesson must have unique `id`:** |
| 125 | +```yaml |
| 126 | +--- |
| 127 | +id: lesson-1-1-digital-to-physical # Unique across entire docs folder |
| 128 | +title: "Lesson 1.1: From ChatGPT to Walking Robots" |
| 129 | +--- |
| 130 | +``` |
| 131 | + |
| 132 | +**ID pattern**: `lesson-{chapter}-{lesson}-{slug}` |
| 133 | +- `lesson-1-1-digital-to-physical` |
| 134 | +- `lesson-3-2-turtlesim-action` |
| 135 | +- `custom-messages` (for standalone topics) |
| 136 | + |
| 137 | +### Principle 4: Safe Text Patterns |
| 138 | + |
| 139 | +**Avoid these patterns in prose (outside code blocks):** |
| 140 | + |
| 141 | +| Pattern | Problem | Solution | |
| 142 | +|---------|---------|----------| |
| 143 | +| `<N` | JSX parsing | `less than N`, `under N` | |
| 144 | +| `>N` | JSX parsing | `more than N`, `over N` | |
| 145 | +| `{var}` | JSX interpolation | Use code: `` `{var}` `` | |
| 146 | +| `<Component>` | JSX component | Use code or escape | |
| 147 | + |
| 148 | +**Safe in code blocks:** |
| 149 | +```python |
| 150 | +if x < 5: # This is fine - inside code block |
| 151 | + pass |
| 152 | +``` |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## Checklist (Use Before Every Lesson Creation) |
| 157 | + |
| 158 | +- [ ] File extension is `.md` (not `.mdx`) |
| 159 | +- [ ] Index files named `README.md` (not `index.md`) |
| 160 | +- [ ] Unique `id` in frontmatter |
| 161 | +- [ ] No `<` or `>` in prose outside code blocks |
| 162 | +- [ ] No Mermaid diagrams (use ASCII or images) |
| 163 | +- [ ] Internal links use `.md` extension |
| 164 | +- [ ] Internal links use `README.md` not `index.md` |
| 165 | +- [ ] Build passes: `npm run build` |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +## Recovery Patterns |
| 170 | + |
| 171 | +### Fix: Duplicate Doc ID Error |
| 172 | +``` |
| 173 | +Error: The docs plugin found docs sharing the same id |
| 174 | +``` |
| 175 | +**Solution**: |
| 176 | +1. Delete one of the duplicate files |
| 177 | +2. Or change the `id` in frontmatter to be unique |
| 178 | + |
| 179 | +### Fix: MDX Syntax Error |
| 180 | +``` |
| 181 | +Unexpected character 'N' (U+004E) before name |
| 182 | +``` |
| 183 | +**Solution**: |
| 184 | +1. Find the `<` character in prose |
| 185 | +2. Replace with word equivalent (`less than`, `under`) |
| 186 | +3. Or wrap in inline code |
| 187 | + |
| 188 | +### Fix: Mermaid Not Rendering |
| 189 | +**Solution**: |
| 190 | +1. Replace mermaid block with ASCII text diagram |
| 191 | +2. Or create image and reference it |
| 192 | + |
| 193 | +--- |
| 194 | + |
| 195 | +## Version History |
| 196 | + |
| 197 | +| Version | Date | Change | |
| 198 | +|---------|------|--------| |
| 199 | +| 1.0.0 | 2025-11-29 | Initial skill from Module 1 lessons learned | |
0 commit comments