|
1
|
# MDX Patterns |
|
2
|
|
|
3
|
Exact syntax used across `book`, `resources`, `ui`, and `user-guide` projects. |
|
4
|
|
|
5
|
## Page Metadata |
|
6
|
|
|
7
|
Every MDX page exports a `metadata` object as the first line: |
|
8
|
|
|
9
|
```mdx |
|
10
|
export const metadata = { |
|
11
|
title: `Page Title`, |
|
12
|
} |
|
13
|
|
|
14
|
# {metadata.title} |
|
15
|
``` |
|
16
|
|
|
17
|
In the `book` project, titles use the auto-generated `${pageNumber}` variable — always keep it: |
|
18
|
|
|
19
|
```mdx |
|
20
|
export const metadata = { |
|
21
|
title: `${pageNumber} Workflows`, |
|
22
|
} |
|
23
|
|
|
24
|
# {metadata.title} |
|
25
|
``` |
|
26
|
|
|
27
|
> **CRITICAL:** Never remove `${pageNumber}` from book titles. It is injected by the prep script. |
|
28
|
|
|
29
|
Pages whose content is dynamically injected, such as from a React component, must have the `generate_toc` frontmatter enabled to generate their table of content items. |
|
30
|
|
|
31
|
```mdx |
|
32
|
--- |
|
33
|
generate_toc: true |
|
34
|
--- |
|
35
|
|
|
36
|
import Content from "./content" |
|
37
|
|
|
38
|
export const metadata = { |
|
39
|
title: `Product Module`, |
|
40
|
} |
|
41
|
|
|
42
|
<Content /> |
|
43
|
``` |
|
44
|
|
|
45
|
## Code Blocks |
|
46
|
|
|
47
|
### Basic code block |
|
48
|
|
|
49
|
~~~mdx |
|
50
|
```ts title="src/workflows/my-workflow.ts" |
|
51
|
import { createWorkflow } from "@medusajs/framework/workflows-sdk" |
|
52
|
// ... |
|
53
|
``` |
|
54
|
~~~ |
|
55
|
|
|
56
|
### Code block with highlights |
|
57
|
|
|
58
|
Highlights draw attention to specific lines. Define them before the code block: |
|
59
|
|
|
60
|
~~~mdx |
|
61
|
export const highlights = [ |
|
62
|
["3", "greetingJob", "The function executed at the scheduled interval."], |
|
63
|
["4", "container", "Receive the Medusa container as a parameter."], |
|
64
|
["10", "name", "A unique name for the job."], |
|
65
|
] |
|
66
|
|
|
67
|
```ts title="src/jobs/hello-world.ts" highlights={highlights} |
|
68
|
import { MedusaContainer } from "@medusajs/framework/types" |
|
69
|
|
|
70
|
export default async function greetingJob(container: MedusaContainer) { |
|
71
|
const logger = container.resolve("logger") |
|
72
|
logger.info("Greeting!") |
|
73
|
} |
|
74
|
|
|
75
|
export const config = { |
|
76
|
name: "greeting-every-minute", |
|
77
|
schedule: "* * * * *", |
|
78
|
} |
|
79
|
``` |
|
80
|
~~~ |
|
81
|
|
|
82
|
The highlights array entries are `[lineNumber, variableName, explanation]`. |
|
83
|
|
|
84
|
### Multi-language tabs |
|
85
|
|
|
86
|
Use `<CodeTabs>` and `<CodeTab>` for npm/yarn/pnpm examples: |
|
87
|
|
|
88
|
~~~mdx |
|
89
|
import { CodeTabs, CodeTab } from "docs-ui" |
|
90
|
|
|
91
|
<CodeTabs group="npm2yarn"> |
|
92
|
<CodeTab label="npm" value="npm"> |
|
93
|
|
|
94
|
```bash |
|
95
|
npm run dev |
|
96
|
``` |
|
97
|
|
|
98
|
</CodeTab> |
|
99
|
<CodeTab label="yarn" value="yarn"> |
|
100
|
|
|
101
|
```bash |
|
102
|
yarn dev |
|
103
|
``` |
|
104
|
|
|
105
|
</CodeTab> |
|
106
|
</CodeTabs> |
|
107
|
~~~ |
|
108
|
|
|
109
|
For bash commands that have npm/yarn equivalents, use the shorthand: |
|
110
|
|
|
111
|
~~~mdx |
|
112
|
```bash npm2yarn |
|
113
|
npm run dev |
|
114
|
``` |
|
115
|
~~~ |
|
116
|
|
|
117
|
## Note Components |
|
118
|
|
|
119
|
```mdx |
|
120
|
<Note> |
|
121
|
|
|
122
|
General informational note. |
|
123
|
|
|
124
|
</Note> |
|
125
|
|
|
126
|
<Note title="Tip"> |
|
127
|
|
|
128
|
A helpful tip or shortcut. |
|
129
|
|
|
130
|
</Note> |
|
131
|
|
|
132
|
<Note title="Warning" type="warning"> |
|
133
|
|
|
134
|
Something to be careful about. |
|
135
|
|
|
136
|
</Note> |
|
137
|
|
|
138
|
<Note title="Don't use this if" type="error"> |
|
139
|
|
|
140
|
- A condition where this approach is wrong |
|
141
|
- Another condition |
|
142
|
|
|
143
|
</Note> |
|
144
|
``` |
|
145
|
|
|
146
|
## Version Notes |
|
147
|
|
|
148
|
When documenting a new option, method, parameter, or behavior change, add a version note so readers know when it became available. |
|
149
|
|
|
150
|
**Get the current version** from `www/packages/docs-ui/src/global-config.ts` → `version.number`. The next version is the patch increment (e.g. `2.13.5` → `2.13.6`). Use the next version when the change is being introduced now (i.e. not yet released). |
|
151
|
|
|
152
|
**Release URL pattern:** `https://github.com/medusajs/medusa/releases/tag/v{version}` |
|
153
|
|
|
154
|
### New option/method/parameter — `<Note>` block |
|
155
|
|
|
156
|
Place immediately after the heading for the new item: |
|
157
|
|
|
158
|
```mdx |
|
159
|
### myNewOption |
|
160
|
|
|
161
|
<Note> |
|
162
|
|
|
163
|
This option is available since Medusa [v2.13.6](https://github.com/medusajs/medusa/releases/tag/v2.13.6). |
|
164
|
|
|
165
|
</Note> |
|
166
|
|
|
167
|
Description of the option... |
|
168
|
``` |
|
169
|
|
|
170
|
### Changed behavior — "Before Medusa v..." inside `<Note>` |
|
171
|
|
|
172
|
Use when existing behavior changed and users may have old code: |
|
173
|
|
|
174
|
```mdx |
|
175
|
<Note> |
|
176
|
|
|
177
|
Before [Medusa v2.13.6](https://github.com/medusajs/medusa/releases/tag/v2.13.6), you did X. Now, you must do Y instead. |
|
178
|
|
|
179
|
</Note> |
|
180
|
``` |
|
181
|
|
|
182
|
### Table cell — inline version annotation |
|
183
|
|
|
184
|
For new or deprecated entries in `<Table>` components, annotate inside the cell: |
|
185
|
|
|
186
|
```mdx |
|
187
|
<Table.Cell> |
|
188
|
|
|
189
|
`myOption` (v2.13.6+) |
|
190
|
|
|
191
|
</Table.Cell> |
|
192
|
``` |
|
193
|
|
|
194
|
For deprecated entries: |
|
195
|
|
|
196
|
```mdx |
|
197
|
<Table.Cell> |
|
198
|
|
|
199
|
`oldOption` (Deprecated v2.13.6+, use `newOption` instead) |
|
200
|
|
|
201
|
</Table.Cell> |
|
202
|
``` |
|
203
|
|
|
204
|
## Prerequisites Component |
|
205
|
|
|
206
|
Use at the top of pages that require existing knowledge or setup: |
|
207
|
|
|
208
|
```mdx |
|
209
|
import { Prerequisites } from "docs-ui" |
|
210
|
|
|
211
|
<Prerequisites |
|
212
|
items={[ |
|
213
|
{ |
|
214
|
text: "Medusa application set up", |
|
215
|
link: "!docs!/learn/installation", |
|
216
|
}, |
|
217
|
{ |
|
218
|
text: "pnpm installed", |
|
219
|
link: "https://pnpm.io/installation", |
|
220
|
}, |
|
221
|
]} |
|
222
|
/> |
|
223
|
``` |
|
224
|
|
|
225
|
## Cross-Project Links |
|
226
|
|
|
227
|
Never use absolute URLs for cross-project links. Use the special link syntax: |
|
228
|
|
|
229
|
```mdx |
|
230
|
[text](!docs!/learn/fundamentals/workflows) → book |
|
231
|
[text](!resources!/commerce-modules/product) → resources |
|
232
|
[text](!user-guide!/products) → user-guide |
|
233
|
``` |
|
234
|
|
|
235
|
Internal links within the same project use relative paths: |
|
236
|
|
|
237
|
```mdx |
|
238
|
[text](./other-page/page.mdx) |
|
239
|
[text](../sibling/page.mdx) |
|
240
|
``` |
|
241
|
|
|
242
|
## Section Dividers |
|
243
|
|
|
244
|
Use `---` to separate major sections: |
|
245
|
|
|
246
|
```mdx |
|
247
|
## First Section |
|
248
|
|
|
249
|
Content here. |
|
250
|
|
|
251
|
--- |
|
252
|
|
|
253
|
## Second Section |
|
254
|
|
|
255
|
Content here. |
|
256
|
``` |
|
257
|
|
|
258
|
## Imports |
|
259
|
|
|
260
|
Import components at the top of the file, after frontmatter and before metadata export: |
|
261
|
|
|
262
|
```mdx |
|
263
|
--- |
|
264
|
generate_toc: true |
|
265
|
--- |
|
266
|
|
|
267
|
import { Prerequisites } from "docs-ui" |
|
268
|
import { CodeTabs, CodeTab } from "docs-ui" |
|
269
|
|
|
270
|
export const metadata = { |
|
271
|
title: `My Page`, |
|
272
|
} |
|
273
|
``` |
|
274
|
|
|
275
|
## Images |
|
276
|
|
|
277
|
Use standard markdown image syntax with a Cloudinary URL for user-guide screenshots: |
|
278
|
|
|
279
|
```mdx |
|
280
|
 |
|
281
|
``` |
|
282
|
|
|
283
|
If you don't have the URL, leave a placeholder comment: |
|
284
|
|
|
285
|
```mdx |
|
286
|
<!-- TODO: add screenshot of <description> --> |
|
287
|
``` |
|
288
|
|
|
289
|
Never invent a Cloudinary URL. |
|
290
|
|
|
291
|
## Keyboard Shortcuts |
|
292
|
|
|
293
|
### Keys to press — `Kbd` component |
|
294
|
|
|
295
|
Wrap any key name the user must press in the `Kbd` component from `docs-ui`: |
|
296
|
|
|
297
|
```mdx |
|
298
|
import { Kbd } from "docs-ui" |
|
299
|
|
|
300
|
Press <Kbd>Enter</Kbd> to confirm, or <Kbd>Escape</Kbd> to cancel. |
|
301
|
``` |
|
302
|
|
|
303
|
### OS-dependent shortcuts (CMD vs CTRL) — `getOsShortcut` |
|
304
|
|
|
305
|
When a shortcut differs between macOS (⌘ Cmd) and Windows/Linux (Ctrl), use the `getOsShortcut` utility from `docs-ui` so the correct key is shown automatically based on the user's OS: |
|
306
|
|
|
307
|
```mdx |
|
308
|
import { Kbd, getOsShortcut } from "docs-ui" |
|
309
|
|
|
310
|
Press <Kbd>{getOsShortcut()}</Kbd>+<Kbd>S</Kbd> to save. |
|
311
|
``` |
|
312
|
|
|
313
|
`getOsShortcut()` returns `"Cmd"` on macOS and `"Ctrl"` on other platforms. |
|
314
|
|
|
315
|
> **Rule:** Never hard-code `Cmd` or `Ctrl` alone. If the shortcut uses the primary modifier key, always use `getOsShortcut()` so both platforms are covered. |