hexo-renderer-mdx 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +162 -162
- package/LICENSE +21 -21
- package/README.md +377 -377
- package/index.js +134 -134
- package/package.json +38 -38
- package/test-mdx.js +47 -47
package/README.md
CHANGED
|
@@ -1,378 +1,378 @@
|
|
|
1
|
-
# hexo-renderer-mdx
|
|
2
|
-
|
|
3
|
-
A [Hexo](https://hexo.io/) renderer plugin for [MDX](https://mdxjs.com/) - Markdown with JSX support. This plugin allows you to write Hexo posts and pages using MDX, enabling you to embed React components directly in your markdown content.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🚀 Full MDX support with JSX syntax
|
|
8
|
-
- ⚛️ React component integration
|
|
9
|
-
- 📝 Markdown compatibility
|
|
10
|
-
- 🎨 Custom component support
|
|
11
|
-
- 🔥 Fast compilation with @mdx-js/mdx
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install hexo-renderer-mdx --save
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
or with yarn:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn add hexo-renderer-mdx
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## How to Use
|
|
26
|
-
|
|
27
|
-
### Quick Start
|
|
28
|
-
|
|
29
|
-
1. **Install the plugin** in your Hexo blog directory:
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install hexo-renderer-mdx --save
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
2. **Create your first MDX post** in `source/_posts/my-first-mdx-post.mdx`:
|
|
36
|
-
|
|
37
|
-
```mdx
|
|
38
|
-
---
|
|
39
|
-
title: My First MDX Post
|
|
40
|
-
date: 2026-01-06
|
|
41
|
-
tags: [hexo, mdx]
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
# Hello from MDX!
|
|
45
|
-
|
|
46
|
-
This is regular markdown **with bold text**.
|
|
47
|
-
|
|
48
|
-
<div style={{
|
|
49
|
-
padding: '20px',
|
|
50
|
-
backgroundColor: '#e3f2fd',
|
|
51
|
-
borderRadius: '8px',
|
|
52
|
-
marginTop: '20px'
|
|
53
|
-
}}>
|
|
54
|
-
🎉 This is a styled JSX element!
|
|
55
|
-
</div>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
3. **Generate your site**:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
hexo generate
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
4. **Preview locally**:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
hexo server
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
5. **View your post** at `http://localhost:4000`
|
|
71
|
-
|
|
72
|
-
That's it! The plugin automatically processes all `.mdx` files in your Hexo blog.
|
|
73
|
-
|
|
74
|
-
### Step-by-Step Guide
|
|
75
|
-
|
|
76
|
-
#### 1. Setting Up a New Hexo Blog (Optional)
|
|
77
|
-
|
|
78
|
-
If you don't have a Hexo blog yet:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
npm install -g hexo-cli
|
|
82
|
-
hexo init my-blog
|
|
83
|
-
cd my-blog
|
|
84
|
-
npm install
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
#### 2. Installing the Plugin
|
|
88
|
-
|
|
89
|
-
In your Hexo blog directory:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
npm install hexo-renderer-mdx --save
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
No additional configuration is needed - the plugin registers automatically!
|
|
96
|
-
|
|
97
|
-
#### 3. Creating MDX Files
|
|
98
|
-
|
|
99
|
-
MDX files work just like regular Markdown files, but with JSX support. Create files in:
|
|
100
|
-
- `source/_posts/` for blog posts
|
|
101
|
-
- `source/` for pages
|
|
102
|
-
|
|
103
|
-
**File naming**: Use `.mdx` extension (e.g., `my-post.mdx`)
|
|
104
|
-
|
|
105
|
-
**Front matter**: Same as regular Hexo posts:
|
|
106
|
-
|
|
107
|
-
```mdx
|
|
108
|
-
---
|
|
109
|
-
title: Post Title
|
|
110
|
-
date: 2026-01-06
|
|
111
|
-
categories:
|
|
112
|
-
- Technology
|
|
113
|
-
tags:
|
|
114
|
-
- hexo
|
|
115
|
-
- mdx
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
Your content here...
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
#### 4. Using MDX Features
|
|
122
|
-
|
|
123
|
-
**Standard Markdown** - All markdown features work:
|
|
124
|
-
|
|
125
|
-
```mdx
|
|
126
|
-
# Heading 1
|
|
127
|
-
## Heading 2
|
|
128
|
-
|
|
129
|
-
**Bold**, *italic*, ~~strikethrough~~
|
|
130
|
-
|
|
131
|
-
- List item 1
|
|
132
|
-
- List item 2
|
|
133
|
-
|
|
134
|
-
[Link text](https://example.com)
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Inline JSX** - Add HTML/JSX elements anywhere:
|
|
138
|
-
|
|
139
|
-
```mdx
|
|
140
|
-
<div className="custom-class" style={{ color: 'blue' }}>
|
|
141
|
-
Custom styled content
|
|
142
|
-
</div>
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
**Custom Components** - Define and use React components:
|
|
146
|
-
|
|
147
|
-
```mdx
|
|
148
|
-
export const Alert = ({ children, type = 'info' }) => (
|
|
149
|
-
<div style={{
|
|
150
|
-
padding: '15px',
|
|
151
|
-
backgroundColor: type === 'warning' ? '#fff3cd' : '#d1ecf1',
|
|
152
|
-
borderRadius: '5px',
|
|
153
|
-
margin: '20px 0'
|
|
154
|
-
}}>
|
|
155
|
-
{children}
|
|
156
|
-
</div>
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
<Alert type="warning">
|
|
160
|
-
This is a custom alert component!
|
|
161
|
-
</Alert>
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
**Dynamic Content** - Use JavaScript expressions:
|
|
165
|
-
|
|
166
|
-
```mdx
|
|
167
|
-
<div>
|
|
168
|
-
{['React', 'Vue', 'Angular'].map(framework => (
|
|
169
|
-
<p key={framework}>I ❤️ {framework}</p>
|
|
170
|
-
))}
|
|
171
|
-
</div>
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
#### 5. Building and Deploying
|
|
175
|
-
|
|
176
|
-
Build your site as usual:
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
# Generate static files
|
|
180
|
-
hexo generate
|
|
181
|
-
|
|
182
|
-
# Deploy (if configured)
|
|
183
|
-
hexo deploy
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
The MDX files are compiled to static HTML - no JavaScript runtime needed on your site!
|
|
187
|
-
|
|
188
|
-
## Usage
|
|
189
|
-
|
|
190
|
-
After installation, you can create `.mdx` files in your `source/_posts` or `source` directory.
|
|
191
|
-
|
|
192
|
-
### Basic Example
|
|
193
|
-
|
|
194
|
-
Create a file `source/_posts/hello-mdx.mdx`:
|
|
195
|
-
|
|
196
|
-
```mdx
|
|
197
|
-
---
|
|
198
|
-
title: Hello MDX
|
|
199
|
-
date: 2026-01-06
|
|
200
|
-
tags:
|
|
201
|
-
- mdx
|
|
202
|
-
- react
|
|
203
|
-
---
|
|
204
|
-
|
|
205
|
-
# Hello MDX!
|
|
206
|
-
|
|
207
|
-
This is a regular markdown paragraph.
|
|
208
|
-
|
|
209
|
-
You can use JSX directly:
|
|
210
|
-
|
|
211
|
-
<div style={{ padding: '20px', backgroundColor: '#f0f0f0' }}>
|
|
212
|
-
<h2>Custom Component</h2>
|
|
213
|
-
<p>This is rendered using JSX!</p>
|
|
214
|
-
</div>
|
|
215
|
-
|
|
216
|
-
And back to markdown...
|
|
217
|
-
|
|
218
|
-
## Features
|
|
219
|
-
|
|
220
|
-
- List item 1
|
|
221
|
-
- List item 2
|
|
222
|
-
- List item 3
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Advanced Example
|
|
226
|
-
|
|
227
|
-
You can use more complex JSX:
|
|
228
|
-
|
|
229
|
-
```mdx
|
|
230
|
-
---
|
|
231
|
-
title: Advanced MDX
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
export const Button = ({ children, color = 'blue' }) => (
|
|
235
|
-
<button style={{
|
|
236
|
-
backgroundColor: color,
|
|
237
|
-
color: 'white',
|
|
238
|
-
padding: '10px 20px',
|
|
239
|
-
border: 'none',
|
|
240
|
-
borderRadius: '5px',
|
|
241
|
-
cursor: 'pointer'
|
|
242
|
-
}}>
|
|
243
|
-
{children}
|
|
244
|
-
</button>
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
# Advanced MDX Example
|
|
248
|
-
|
|
249
|
-
Here's a custom button component:
|
|
250
|
-
|
|
251
|
-
<Button color="red">Click Me!</Button>
|
|
252
|
-
|
|
253
|
-
You can use any valid JSX expression:
|
|
254
|
-
|
|
255
|
-
<div>
|
|
256
|
-
{['apple', 'banana', 'cherry'].map(fruit => (
|
|
257
|
-
<p key={fruit}>I love {fruit}s!</p>
|
|
258
|
-
))}
|
|
259
|
-
</div>
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
## Configuration
|
|
263
|
-
|
|
264
|
-
The plugin works out of the box with no configuration required. However, you can customize MDX compilation options if needed.
|
|
265
|
-
|
|
266
|
-
### Advanced Configuration
|
|
267
|
-
|
|
268
|
-
If you need to customize the MDX compiler options, you can create a `hexo-renderer-mdx` configuration in your Hexo `_config.yml`:
|
|
269
|
-
|
|
270
|
-
```yaml
|
|
271
|
-
# _config.yml
|
|
272
|
-
mdx:
|
|
273
|
-
# Enable development mode for better error messages
|
|
274
|
-
development: false
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
Note: The current version uses sensible defaults optimized for static site generation.
|
|
278
|
-
|
|
279
|
-
The plugin:
|
|
280
|
-
1. Compiles MDX files to JavaScript functions
|
|
281
|
-
2. Executes them with a React runtime
|
|
282
|
-
3. Renders the result to static HTML
|
|
283
|
-
4. Passes the HTML to Hexo for page generation
|
|
284
|
-
|
|
285
|
-
## Requirements
|
|
286
|
-
|
|
287
|
-
- Node.js >= 14.0.0
|
|
288
|
-
- Hexo >= 5.0.0
|
|
289
|
-
|
|
290
|
-
## Dependencies
|
|
291
|
-
|
|
292
|
-
This plugin uses:
|
|
293
|
-
- `@mdx-js/mdx` - MDX compiler
|
|
294
|
-
- `react` & `react-dom` - React runtime for server-side rendering
|
|
295
|
-
|
|
296
|
-
## Notes
|
|
297
|
-
|
|
298
|
-
- MDX files are compiled to static HTML at build time
|
|
299
|
-
- Interactive React components will not be interactive in the final output (server-side rendering only)
|
|
300
|
-
- For interactive components, consider using a different approach or client-side hydration
|
|
301
|
-
|
|
302
|
-
## Troubleshooting
|
|
303
|
-
|
|
304
|
-
### MDX Compilation Errors
|
|
305
|
-
|
|
306
|
-
If you encounter compilation errors, check:
|
|
307
|
-
- Your JSX syntax is valid
|
|
308
|
-
- All tags are properly closed
|
|
309
|
-
- You're not using unsupported JSX features
|
|
310
|
-
|
|
311
|
-
### Missing Dependencies
|
|
312
|
-
|
|
313
|
-
Make sure all peer dependencies are installed:
|
|
314
|
-
|
|
315
|
-
```bash
|
|
316
|
-
npm install react react-dom @mdx-js/mdx --save
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## Publishing
|
|
320
|
-
|
|
321
|
-
### For Maintainers
|
|
322
|
-
|
|
323
|
-
This package uses automated publishing to npm via GitHub Actions with **Trusted Publishing** (OIDC).
|
|
324
|
-
|
|
325
|
-
**To publish a new version:**
|
|
326
|
-
|
|
327
|
-
1. Update the version in `package.json`:
|
|
328
|
-
```bash
|
|
329
|
-
npm version patch # or minor, or major
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
2. Push the changes and tags:
|
|
333
|
-
```bash
|
|
334
|
-
git push && git push --tags
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
3. Create a new release on GitHub:
|
|
338
|
-
- Go to the repository's "Releases" page
|
|
339
|
-
- Click "Create a new release"
|
|
340
|
-
- Select the tag you just created
|
|
341
|
-
- Add release notes
|
|
342
|
-
- Click "Publish release"
|
|
343
|
-
|
|
344
|
-
4. The GitHub Action will automatically:
|
|
345
|
-
- Run tests
|
|
346
|
-
- Publish to npm with provenance using Trusted Publishing
|
|
347
|
-
- Make the package publicly available
|
|
348
|
-
|
|
349
|
-
**First-time setup:**
|
|
350
|
-
|
|
351
|
-
Before publishing, you need to configure Trusted Publishing on npm:
|
|
352
|
-
|
|
353
|
-
1. Go to https://www.npmjs.com/package/hexo-renderer-mdx/access
|
|
354
|
-
2. Click "Publishing" → "Trusted Publishers"
|
|
355
|
-
3. Add a new trusted publisher with:
|
|
356
|
-
- **Provider**: GitHub Actions
|
|
357
|
-
- **Repository owner**: Bryan0324
|
|
358
|
-
- **Repository name**: hexo-renderer-mdx
|
|
359
|
-
- **Workflow file**: `publish.yml`
|
|
360
|
-
- **Environment name**: (leave empty)
|
|
361
|
-
|
|
362
|
-
No npm tokens required! Trusted Publishing uses OpenID Connect (OIDC) for secure authentication.
|
|
363
|
-
|
|
364
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed publishing instructions.
|
|
365
|
-
|
|
366
|
-
## Contributing
|
|
367
|
-
|
|
368
|
-
Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
|
|
369
|
-
|
|
370
|
-
## License
|
|
371
|
-
|
|
372
|
-
MIT
|
|
373
|
-
|
|
374
|
-
## Related
|
|
375
|
-
|
|
376
|
-
- [Hexo](https://hexo.io/)
|
|
377
|
-
- [MDX](https://mdxjs.com/)
|
|
1
|
+
# hexo-renderer-mdx
|
|
2
|
+
|
|
3
|
+
A [Hexo](https://hexo.io/) renderer plugin for [MDX](https://mdxjs.com/) - Markdown with JSX support. This plugin allows you to write Hexo posts and pages using MDX, enabling you to embed React components directly in your markdown content.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 Full MDX support with JSX syntax
|
|
8
|
+
- ⚛️ React component integration
|
|
9
|
+
- 📝 Markdown compatibility
|
|
10
|
+
- 🎨 Custom component support
|
|
11
|
+
- 🔥 Fast compilation with @mdx-js/mdx
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install hexo-renderer-mdx --save
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
or with yarn:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add hexo-renderer-mdx
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## How to Use
|
|
26
|
+
|
|
27
|
+
### Quick Start
|
|
28
|
+
|
|
29
|
+
1. **Install the plugin** in your Hexo blog directory:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install hexo-renderer-mdx --save
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. **Create your first MDX post** in `source/_posts/my-first-mdx-post.mdx`:
|
|
36
|
+
|
|
37
|
+
```mdx
|
|
38
|
+
---
|
|
39
|
+
title: My First MDX Post
|
|
40
|
+
date: 2026-01-06
|
|
41
|
+
tags: [hexo, mdx]
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
# Hello from MDX!
|
|
45
|
+
|
|
46
|
+
This is regular markdown **with bold text**.
|
|
47
|
+
|
|
48
|
+
<div style={{
|
|
49
|
+
padding: '20px',
|
|
50
|
+
backgroundColor: '#e3f2fd',
|
|
51
|
+
borderRadius: '8px',
|
|
52
|
+
marginTop: '20px'
|
|
53
|
+
}}>
|
|
54
|
+
🎉 This is a styled JSX element!
|
|
55
|
+
</div>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
3. **Generate your site**:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
hexo generate
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
4. **Preview locally**:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
hexo server
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
5. **View your post** at `http://localhost:4000`
|
|
71
|
+
|
|
72
|
+
That's it! The plugin automatically processes all `.mdx` files in your Hexo blog.
|
|
73
|
+
|
|
74
|
+
### Step-by-Step Guide
|
|
75
|
+
|
|
76
|
+
#### 1. Setting Up a New Hexo Blog (Optional)
|
|
77
|
+
|
|
78
|
+
If you don't have a Hexo blog yet:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install -g hexo-cli
|
|
82
|
+
hexo init my-blog
|
|
83
|
+
cd my-blog
|
|
84
|
+
npm install
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### 2. Installing the Plugin
|
|
88
|
+
|
|
89
|
+
In your Hexo blog directory:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm install hexo-renderer-mdx --save
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
No additional configuration is needed - the plugin registers automatically!
|
|
96
|
+
|
|
97
|
+
#### 3. Creating MDX Files
|
|
98
|
+
|
|
99
|
+
MDX files work just like regular Markdown files, but with JSX support. Create files in:
|
|
100
|
+
- `source/_posts/` for blog posts
|
|
101
|
+
- `source/` for pages
|
|
102
|
+
|
|
103
|
+
**File naming**: Use `.mdx` extension (e.g., `my-post.mdx`)
|
|
104
|
+
|
|
105
|
+
**Front matter**: Same as regular Hexo posts:
|
|
106
|
+
|
|
107
|
+
```mdx
|
|
108
|
+
---
|
|
109
|
+
title: Post Title
|
|
110
|
+
date: 2026-01-06
|
|
111
|
+
categories:
|
|
112
|
+
- Technology
|
|
113
|
+
tags:
|
|
114
|
+
- hexo
|
|
115
|
+
- mdx
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
Your content here...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### 4. Using MDX Features
|
|
122
|
+
|
|
123
|
+
**Standard Markdown** - All markdown features work:
|
|
124
|
+
|
|
125
|
+
```mdx
|
|
126
|
+
# Heading 1
|
|
127
|
+
## Heading 2
|
|
128
|
+
|
|
129
|
+
**Bold**, *italic*, ~~strikethrough~~
|
|
130
|
+
|
|
131
|
+
- List item 1
|
|
132
|
+
- List item 2
|
|
133
|
+
|
|
134
|
+
[Link text](https://example.com)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Inline JSX** - Add HTML/JSX elements anywhere:
|
|
138
|
+
|
|
139
|
+
```mdx
|
|
140
|
+
<div className="custom-class" style={{ color: 'blue' }}>
|
|
141
|
+
Custom styled content
|
|
142
|
+
</div>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Custom Components** - Define and use React components:
|
|
146
|
+
|
|
147
|
+
```mdx
|
|
148
|
+
export const Alert = ({ children, type = 'info' }) => (
|
|
149
|
+
<div style={{
|
|
150
|
+
padding: '15px',
|
|
151
|
+
backgroundColor: type === 'warning' ? '#fff3cd' : '#d1ecf1',
|
|
152
|
+
borderRadius: '5px',
|
|
153
|
+
margin: '20px 0'
|
|
154
|
+
}}>
|
|
155
|
+
{children}
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
<Alert type="warning">
|
|
160
|
+
This is a custom alert component!
|
|
161
|
+
</Alert>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Dynamic Content** - Use JavaScript expressions:
|
|
165
|
+
|
|
166
|
+
```mdx
|
|
167
|
+
<div>
|
|
168
|
+
{['React', 'Vue', 'Angular'].map(framework => (
|
|
169
|
+
<p key={framework}>I ❤️ {framework}</p>
|
|
170
|
+
))}
|
|
171
|
+
</div>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### 5. Building and Deploying
|
|
175
|
+
|
|
176
|
+
Build your site as usual:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Generate static files
|
|
180
|
+
hexo generate
|
|
181
|
+
|
|
182
|
+
# Deploy (if configured)
|
|
183
|
+
hexo deploy
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The MDX files are compiled to static HTML - no JavaScript runtime needed on your site!
|
|
187
|
+
|
|
188
|
+
## Usage
|
|
189
|
+
|
|
190
|
+
After installation, you can create `.mdx` files in your `source/_posts` or `source` directory.
|
|
191
|
+
|
|
192
|
+
### Basic Example
|
|
193
|
+
|
|
194
|
+
Create a file `source/_posts/hello-mdx.mdx`:
|
|
195
|
+
|
|
196
|
+
```mdx
|
|
197
|
+
---
|
|
198
|
+
title: Hello MDX
|
|
199
|
+
date: 2026-01-06
|
|
200
|
+
tags:
|
|
201
|
+
- mdx
|
|
202
|
+
- react
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
# Hello MDX!
|
|
206
|
+
|
|
207
|
+
This is a regular markdown paragraph.
|
|
208
|
+
|
|
209
|
+
You can use JSX directly:
|
|
210
|
+
|
|
211
|
+
<div style={{ padding: '20px', backgroundColor: '#f0f0f0' }}>
|
|
212
|
+
<h2>Custom Component</h2>
|
|
213
|
+
<p>This is rendered using JSX!</p>
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
And back to markdown...
|
|
217
|
+
|
|
218
|
+
## Features
|
|
219
|
+
|
|
220
|
+
- List item 1
|
|
221
|
+
- List item 2
|
|
222
|
+
- List item 3
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Advanced Example
|
|
226
|
+
|
|
227
|
+
You can use more complex JSX:
|
|
228
|
+
|
|
229
|
+
```mdx
|
|
230
|
+
---
|
|
231
|
+
title: Advanced MDX
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
export const Button = ({ children, color = 'blue' }) => (
|
|
235
|
+
<button style={{
|
|
236
|
+
backgroundColor: color,
|
|
237
|
+
color: 'white',
|
|
238
|
+
padding: '10px 20px',
|
|
239
|
+
border: 'none',
|
|
240
|
+
borderRadius: '5px',
|
|
241
|
+
cursor: 'pointer'
|
|
242
|
+
}}>
|
|
243
|
+
{children}
|
|
244
|
+
</button>
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
# Advanced MDX Example
|
|
248
|
+
|
|
249
|
+
Here's a custom button component:
|
|
250
|
+
|
|
251
|
+
<Button color="red">Click Me!</Button>
|
|
252
|
+
|
|
253
|
+
You can use any valid JSX expression:
|
|
254
|
+
|
|
255
|
+
<div>
|
|
256
|
+
{['apple', 'banana', 'cherry'].map(fruit => (
|
|
257
|
+
<p key={fruit}>I love {fruit}s!</p>
|
|
258
|
+
))}
|
|
259
|
+
</div>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Configuration
|
|
263
|
+
|
|
264
|
+
The plugin works out of the box with no configuration required. However, you can customize MDX compilation options if needed.
|
|
265
|
+
|
|
266
|
+
### Advanced Configuration
|
|
267
|
+
|
|
268
|
+
If you need to customize the MDX compiler options, you can create a `hexo-renderer-mdx` configuration in your Hexo `_config.yml`:
|
|
269
|
+
|
|
270
|
+
```yaml
|
|
271
|
+
# _config.yml
|
|
272
|
+
mdx:
|
|
273
|
+
# Enable development mode for better error messages
|
|
274
|
+
development: false
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Note: The current version uses sensible defaults optimized for static site generation.
|
|
278
|
+
|
|
279
|
+
The plugin:
|
|
280
|
+
1. Compiles MDX files to JavaScript functions
|
|
281
|
+
2. Executes them with a React runtime
|
|
282
|
+
3. Renders the result to static HTML
|
|
283
|
+
4. Passes the HTML to Hexo for page generation
|
|
284
|
+
|
|
285
|
+
## Requirements
|
|
286
|
+
|
|
287
|
+
- Node.js >= 14.0.0
|
|
288
|
+
- Hexo >= 5.0.0
|
|
289
|
+
|
|
290
|
+
## Dependencies
|
|
291
|
+
|
|
292
|
+
This plugin uses:
|
|
293
|
+
- `@mdx-js/mdx` - MDX compiler
|
|
294
|
+
- `react` & `react-dom` - React runtime for server-side rendering
|
|
295
|
+
|
|
296
|
+
## Notes
|
|
297
|
+
|
|
298
|
+
- MDX files are compiled to static HTML at build time
|
|
299
|
+
- Interactive React components will not be interactive in the final output (server-side rendering only)
|
|
300
|
+
- For interactive components, consider using a different approach or client-side hydration
|
|
301
|
+
|
|
302
|
+
## Troubleshooting
|
|
303
|
+
|
|
304
|
+
### MDX Compilation Errors
|
|
305
|
+
|
|
306
|
+
If you encounter compilation errors, check:
|
|
307
|
+
- Your JSX syntax is valid
|
|
308
|
+
- All tags are properly closed
|
|
309
|
+
- You're not using unsupported JSX features
|
|
310
|
+
|
|
311
|
+
### Missing Dependencies
|
|
312
|
+
|
|
313
|
+
Make sure all peer dependencies are installed:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
npm install react react-dom @mdx-js/mdx --save
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Publishing
|
|
320
|
+
|
|
321
|
+
### For Maintainers
|
|
322
|
+
|
|
323
|
+
This package uses automated publishing to npm via GitHub Actions with **Trusted Publishing** (OIDC).
|
|
324
|
+
|
|
325
|
+
**To publish a new version:**
|
|
326
|
+
|
|
327
|
+
1. Update the version in `package.json`:
|
|
328
|
+
```bash
|
|
329
|
+
npm version patch # or minor, or major
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
2. Push the changes and tags:
|
|
333
|
+
```bash
|
|
334
|
+
git push && git push --tags
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
3. Create a new release on GitHub:
|
|
338
|
+
- Go to the repository's "Releases" page
|
|
339
|
+
- Click "Create a new release"
|
|
340
|
+
- Select the tag you just created
|
|
341
|
+
- Add release notes
|
|
342
|
+
- Click "Publish release"
|
|
343
|
+
|
|
344
|
+
4. The GitHub Action will automatically:
|
|
345
|
+
- Run tests
|
|
346
|
+
- Publish to npm with provenance using Trusted Publishing
|
|
347
|
+
- Make the package publicly available
|
|
348
|
+
|
|
349
|
+
**First-time setup:**
|
|
350
|
+
|
|
351
|
+
Before publishing, you need to configure Trusted Publishing on npm:
|
|
352
|
+
|
|
353
|
+
1. Go to https://www.npmjs.com/package/hexo-renderer-mdx/access
|
|
354
|
+
2. Click "Publishing" → "Trusted Publishers"
|
|
355
|
+
3. Add a new trusted publisher with:
|
|
356
|
+
- **Provider**: GitHub Actions
|
|
357
|
+
- **Repository owner**: Bryan0324
|
|
358
|
+
- **Repository name**: hexo-renderer-mdx
|
|
359
|
+
- **Workflow file**: `publish.yml`
|
|
360
|
+
- **Environment name**: (leave empty)
|
|
361
|
+
|
|
362
|
+
No npm tokens required! Trusted Publishing uses OpenID Connect (OIDC) for secure authentication.
|
|
363
|
+
|
|
364
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for detailed publishing instructions.
|
|
365
|
+
|
|
366
|
+
## Contributing
|
|
367
|
+
|
|
368
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
|
|
369
|
+
|
|
370
|
+
## License
|
|
371
|
+
|
|
372
|
+
MIT
|
|
373
|
+
|
|
374
|
+
## Related
|
|
375
|
+
|
|
376
|
+
- [Hexo](https://hexo.io/)
|
|
377
|
+
- [MDX](https://mdxjs.com/)
|
|
378
378
|
- [React](https://reactjs.org/)
|