@x-wave/blog 0.1.0 → 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/README.md +52 -15
- package/index.js +707 -688
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,25 +140,13 @@ export const blog = createBlogUtils(mdxFiles)
|
|
|
140
140
|
|
|
141
141
|
```tsx
|
|
142
142
|
// src/App.tsx
|
|
143
|
-
import { BlogProvider,
|
|
144
|
-
import { Navigate, Route, HashRouter as Router, Routes
|
|
143
|
+
import { BlogProvider, DocumentationRoutes } from '@x-wave/blog'
|
|
144
|
+
import { Navigate, Route, HashRouter as Router, Routes } from 'react-router-dom'
|
|
145
145
|
import { blog } from './utils'
|
|
146
146
|
import { NAVIGATION_DATA } from './navigation'
|
|
147
147
|
|
|
148
148
|
const SUPPORTED_LANGUAGES = ['en', 'es', 'zh'] as const
|
|
149
149
|
|
|
150
|
-
function DocumentationWrapper() {
|
|
151
|
-
const { language } = useParams<{ language: string }>()
|
|
152
|
-
return (
|
|
153
|
-
<DocumentationLayout>
|
|
154
|
-
<Routes>
|
|
155
|
-
<Route path="/:slug" element={<ContentPage language={language!} />} />
|
|
156
|
-
<Route path="/" element={<Navigate to={`/${language}/welcome`} replace />} />
|
|
157
|
-
</Routes>
|
|
158
|
-
</DocumentationLayout>
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
150
|
export default function App() {
|
|
163
151
|
return (
|
|
164
152
|
<BlogProvider
|
|
@@ -180,7 +168,7 @@ export default function App() {
|
|
|
180
168
|
>
|
|
181
169
|
<Router>
|
|
182
170
|
<Routes>
|
|
183
|
-
<Route path="/:language/*" element={<
|
|
171
|
+
<Route path="/:language/*" element={<DocumentationRoutes />} />
|
|
184
172
|
<Route path="/" element={<Navigate to="/en/welcome" replace />} />
|
|
185
173
|
</Routes>
|
|
186
174
|
</Router>
|
|
@@ -189,6 +177,41 @@ export default function App() {
|
|
|
189
177
|
}
|
|
190
178
|
```
|
|
191
179
|
|
|
180
|
+
> **Router flexibility**: Swap `HashRouter` for `BrowserRouter` to use cleaner URLs without the hash (`/en/welcome` vs `/#/en/welcome`). BrowserRouter requires server configuration to fallback to `index.html` for all routes.
|
|
181
|
+
|
|
182
|
+
### Using a base path
|
|
183
|
+
|
|
184
|
+
To mount documentation under a subpath (e.g., `/blog` or `/docs`), set the `basePath` config option:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
export default function App() {
|
|
188
|
+
return (
|
|
189
|
+
<BlogProvider
|
|
190
|
+
config={{
|
|
191
|
+
title: 'My Documentation',
|
|
192
|
+
basePath: '/blog', // All routes will be prefixed with /blog
|
|
193
|
+
supportedLanguages: SUPPORTED_LANGUAGES,
|
|
194
|
+
navigationData: NAVIGATION_DATA,
|
|
195
|
+
}}
|
|
196
|
+
blog={blog}
|
|
197
|
+
>
|
|
198
|
+
<Router>
|
|
199
|
+
<Routes>
|
|
200
|
+
{/* Routes now mounted under /blog */}
|
|
201
|
+
<Route path="/blog/:language/*" element={<DocumentationRoutes />} />
|
|
202
|
+
<Route path="/blog" element={<Navigate to="/blog/en/welcome" replace />} />
|
|
203
|
+
|
|
204
|
+
{/* Your other app routes */}
|
|
205
|
+
<Route path="/" element={<HomePage />} />
|
|
206
|
+
</Routes>
|
|
207
|
+
</Router>
|
|
208
|
+
</BlogProvider>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
This ensures internal navigation (search, tags, language switching) uses the correct base path.
|
|
214
|
+
|
|
192
215
|
## Writing content
|
|
193
216
|
|
|
194
217
|
### File naming
|
|
@@ -254,6 +277,7 @@ All components are exported from `@x-wave/blog`:
|
|
|
254
277
|
```ts
|
|
255
278
|
import {
|
|
256
279
|
BlogProvider,
|
|
280
|
+
DocumentationRoutes,
|
|
257
281
|
DocumentationLayout,
|
|
258
282
|
ContentPage,
|
|
259
283
|
Header,
|
|
@@ -266,6 +290,7 @@ import {
|
|
|
266
290
|
| Component | Purpose |
|
|
267
291
|
|---|---|
|
|
268
292
|
| `BlogProvider` | Root context wrapper (required) |
|
|
293
|
+
| `DocumentationRoutes` | Pre-configured Routes for documentation pages (recommended) |
|
|
269
294
|
| `DocumentationLayout` | Page layout: header + sidebar + content |
|
|
270
295
|
| `ContentPage` | Loads and renders MDX pages |
|
|
271
296
|
| `Header` | Top navigation bar |
|
|
@@ -362,6 +387,7 @@ interface BlogConfig {
|
|
|
362
387
|
logo?: React.ComponentType<{ className?: string }> // Optional logo
|
|
363
388
|
supportedLanguages: readonly string[] // e.g. ['en', 'es', 'zh']
|
|
364
389
|
navigationData: NavigationEntry[] // Menu structure
|
|
390
|
+
basePath?: string // Base path for all routes (default: '')
|
|
365
391
|
header?: {
|
|
366
392
|
navLinks?: HeaderLink[] // Top-level nav links
|
|
367
393
|
dropdownItems?: HeaderDropdownItem[] // Support dropdown menu
|
|
@@ -369,6 +395,17 @@ interface BlogConfig {
|
|
|
369
395
|
}
|
|
370
396
|
```
|
|
371
397
|
|
|
398
|
+
**Key properties:**
|
|
399
|
+
|
|
400
|
+
| Property | Type | Required | Description |
|
|
401
|
+
|---|---|---|---|
|
|
402
|
+
| `title` | `string` | Yes | Site title displayed in header and sidebar |
|
|
403
|
+
| `supportedLanguages` | `string[]` | Yes | Array of language codes (e.g., `['en', 'es', 'zh']`) |
|
|
404
|
+
| `navigationData` | `NavigationEntry[]` | Yes | Sidebar navigation structure |
|
|
405
|
+
| `basePath` | `string` | No | Base path prefix for all routes. Use when mounting docs under a subpath like `/blog` or `/docs`. Default: `''` (root) |
|
|
406
|
+
| `logo` | `React.ComponentType` | No | SVG component for site logo |
|
|
407
|
+
| `header` | `object` | No | Header configuration with nav links and dropdown items |
|
|
408
|
+
|
|
372
409
|
## Browser support
|
|
373
410
|
|
|
374
411
|
- Chrome/Edge 90+
|