@x-wave/blog 0.1.0 → 1.0.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/README.md +0 -387
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-wave/blog",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/README.md DELETED
@@ -1,387 +0,0 @@
1
- # @x-wave/blog
2
-
3
- A responsive, multi-language documentation framework for React + Vite applications. Ships with TypeScript, i18n (i18next), MDX support, dark mode, and built-in navigation.
4
-
5
- ## Features
6
-
7
- - **Multi-language support**: Ship 3+ languages with a single codebase (en, es, zh included)
8
- - **MDX content**: Write docs in Markdown with React components
9
- - **Dark mode**: Built-in light/dark/system theme toggle with localStorage persistence
10
- - **Advanced mode**: Optional Simple/Advanced content variants for the same page
11
- - **Mobile responsive**: Automatic sidebar → mobile menu on small screens
12
- - **Headless**: No styling opinions—includes SCSS variables for full customization
13
- - **HMR-friendly**: Vite development with Hot Module Replacement for instant feedback
14
-
15
- ## Installation
16
-
17
- ### npm
18
-
19
- ```bash
20
- npm install @x-wave/blog
21
- ```
22
-
23
- ### pnpm
24
-
25
- ```bash
26
- pnpm add @x-wave/blog
27
- ```
28
-
29
- ### yarn
30
-
31
- ```bash
32
- yarn add @x-wave/blog
33
- ```
34
-
35
- ## Quick setup
36
-
37
- ### 1. Create your app structure
38
-
39
- ```
40
- src/
41
- ├── App.tsx # Your app component
42
- ├── main.tsx # Entry point
43
- ├── navigation.ts # Site navigation definition
44
- ├── utils.ts # Content loaders
45
- ├── logo.svg # Optional: your logo
46
- └── docs/
47
- ├── en/
48
- │ ├── welcome.mdx
49
- │ ├── glossary.mdx
50
- │ └── faq.mdx
51
- ├── es/
52
- │ ├── welcome.mdx
53
- │ ├── glossary.mdx
54
- │ └── faq.mdx
55
- └── zh/
56
- ├── welcome.mdx
57
- ├── glossary.mdx
58
- └── faq.mdx
59
- ```
60
-
61
- ### 2. Set up i18n and styles
62
-
63
- Import the i18n setup and framework styles in your app entry point:
64
-
65
- ```ts
66
- // src/main.tsx
67
- import '@x-wave/blog/locales' // Initialises i18next with en, es, zh
68
- import '@x-wave/blog/styles' // Framework styles (required)
69
- import { createRoot } from 'react-dom/client'
70
- import App from './App'
71
-
72
- createRoot(document.getElementById('root')!).render(<App />)
73
- ```
74
-
75
- > **The styles import is required** for the UI components and layout to render correctly.
76
-
77
- **Add custom translations:**
78
-
79
- ```ts
80
- // src/main.tsx
81
- import '@x-wave/blog/locales'
82
- import i18next from 'i18next'
83
-
84
- // Add French translations
85
- i18next.addResourceBundle('fr', 'translation', {
86
- language: 'Français',
87
- 'ui.simple': 'Simple',
88
- 'ui.advanced': 'Avancé',
89
- // ... other keys
90
- })
91
- ```
92
-
93
- ### 3. Define your navigation
94
-
95
- ```ts
96
- // src/navigation.ts
97
- import type { NavigationEntry } from '@x-wave/blog/types'
98
-
99
- export const NAVIGATION_DATA: NavigationEntry[] = [
100
- {
101
- title: 'docs.welcome',
102
- slug: 'welcome',
103
- },
104
- {
105
- title: 'Help',
106
- defaultOpen: true,
107
- items: [
108
- {
109
- title: 'docs.glossary',
110
- slug: 'glossary',
111
- showTableOfContents: true,
112
- },
113
- {
114
- title: 'docs.faq',
115
- slug: 'faq',
116
- },
117
- ],
118
- },
119
- ]
120
- ```
121
-
122
- ### 4. Create content loaders
123
-
124
- ```ts
125
- // src/utils.ts
126
- import { createBlogUtils } from '@x-wave/blog'
127
-
128
- // Vite glob import – resolved relative to this file
129
- const mdxFiles = import.meta.glob('./docs/**/*.mdx', {
130
- query: '?raw',
131
- import: 'default',
132
- eager: false,
133
- })
134
-
135
- // Export all blog utilities in a single object
136
- export const blog = createBlogUtils(mdxFiles)
137
- ```
138
-
139
- ### 5. Wrap your app with BlogProvider
140
-
141
- ```tsx
142
- // src/App.tsx
143
- import { BlogProvider, ContentPage, DocumentationLayout } from '@x-wave/blog'
144
- import { Navigate, Route, HashRouter as Router, Routes, useParams } from 'react-router-dom'
145
- import { blog } from './utils'
146
- import { NAVIGATION_DATA } from './navigation'
147
-
148
- const SUPPORTED_LANGUAGES = ['en', 'es', 'zh'] as const
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
- export default function App() {
163
- return (
164
- <BlogProvider
165
- config={{
166
- title: 'My Documentation',
167
- supportedLanguages: SUPPORTED_LANGUAGES,
168
- navigationData: NAVIGATION_DATA,
169
- header: {
170
- navLinks: [
171
- {
172
- label: 'Visit Site',
173
- url: 'https://example.com',
174
- target: '_blank',
175
- },
176
- ],
177
- },
178
- }}
179
- blog={blog}
180
- >
181
- <Router>
182
- <Routes>
183
- <Route path="/:language/*" element={<DocumentationWrapper />} />
184
- <Route path="/" element={<Navigate to="/en/welcome" replace />} />
185
- </Routes>
186
- </Router>
187
- </BlogProvider>
188
- )
189
- }
190
- ```
191
-
192
- ## Writing content
193
-
194
- ### File naming
195
-
196
- Place your MDX files in language-specific directories:
197
-
198
- ```
199
- src/docs/
200
- ├── en/welcome.mdx
201
- ├── es/welcome.mdx
202
- └── zh/welcome.mdx
203
- ```
204
-
205
- File names must match the `slug` field in your navigation definition.
206
-
207
- ### Frontmatter
208
-
209
- Optional YAML at the top of your MDX file:
210
-
211
- ```mdx
212
- ---
213
- title: Getting Started
214
- author: Jane Doe
215
- date: 2026-02-23
216
- hasAdvanced: true
217
- tags:
218
- - tutorial
219
- - beginner
220
- ---
221
-
222
- # Welcome!
223
-
224
- Regular content here.
225
- ```
226
-
227
- | Field | Type | Description |
228
- |---|---|---|
229
- | `title` | `string` | Document title (informational, not displayed by framework) |
230
- | `author` | `string` | Author name. Displayed below the page title with a user icon. |
231
- | `date` | `string` | Publication or update date. Displayed below the page title with "Last edited" label and calendar icon (i18n supported). |
232
- | `hasAdvanced` | `boolean` | Enables Simple/Advanced mode toggle. Requires a `-advanced.mdx` variant. |
233
- | `tags` | `string[]` | Array of tag strings for categorizing content. Tags are automatically indexed by the framework when you pass `mdxFiles` to BlogProvider. Tags are clickable and show search results. |
234
-
235
- ### Advanced mode variants
236
-
237
- Create `welcome-advanced.mdx` alongside `welcome.mdx`:
238
-
239
- ```
240
- src/docs/
241
- ├── en/
242
- │ ├── welcome.mdx
243
- │ └── welcome-advanced.mdx
244
- ```
245
-
246
- Set `hasAdvanced: true` in the simple version's frontmatter, and the framework automatically shows a toggle.
247
-
248
- ## API reference
249
-
250
- ### Components
251
-
252
- All components are exported from `@x-wave/blog`:
253
-
254
- ```ts
255
- import {
256
- BlogProvider,
257
- DocumentationLayout,
258
- ContentPage,
259
- Header,
260
- Sidebar,
261
- TableOfContents,
262
- AdvancedModeToggle
263
- } from '@x-wave/blog'
264
- ```
265
-
266
- | Component | Purpose |
267
- |---|---|
268
- | `BlogProvider` | Root context wrapper (required) |
269
- | `DocumentationLayout` | Page layout: header + sidebar + content |
270
- | `ContentPage` | Loads and renders MDX pages |
271
- | `Header` | Top navigation bar |
272
- | `Sidebar` | Left navigation panel |
273
- | `TableOfContents` | "On this page" anchor panel |
274
- | `AdvancedModeToggle` | Simple/Advanced tab switch |
275
-
276
- ### Hooks
277
-
278
- ```ts
279
- import { useTheme } from '@x-wave/blog'
280
-
281
- const { theme, setTheme, effectiveTheme } = useTheme()
282
- ```
283
- Manages light/dark/system theme preference.
284
-
285
- ### Utilities
286
-
287
- ```ts
288
- import { createBlogUtils } from '@x-wave/blog'
289
-
290
- const blog = createBlogUtils(mdxFiles)
291
- ```
292
- Creates all blog utilities from a Vite glob import. This is the recommended approach as it bundles everything together.
293
-
294
- Returns an object with:
295
- - **`mdxFiles`**: The glob import (used internally for automatic tag indexing)
296
- - **`loadContent(language, slug, advanced?)`**: Loads MDX content for a specific language and slug
297
- - **`loadEnglishContent(slug, advanced?)`**: Loads English content for heading ID generation
298
-
299
- Pass the entire `blog` object to BlogProvider:
300
-
301
- ```tsx
302
- <BlogProvider config={config} blog={blog}>
303
- ```
304
-
305
- **Alternative: Advanced usage**
306
-
307
- ```ts
308
- import { createContentLoaders } from '@x-wave/blog'
309
-
310
- const { loadMDXContent, loadEnglishContent, buildTagIndex } = createContentLoaders(mdxFiles)
311
- ```
312
- For advanced use cases where you need more control over content loading and tag indexing.
313
-
314
- ### Types
315
-
316
- All TypeScript types are exported from `@x-wave/blog/types`:
317
-
318
- ```ts
319
- import type { NavigationEntry, BlogConfig, HeaderLink } from '@x-wave/blog/types'
320
- ```
321
-
322
- ## Customization
323
-
324
- ### CSS variables
325
-
326
- The framework exports SCSS variable files. Import and override them in your own stylesheets:
327
-
328
- ```scss
329
- // In your app.scss
330
- @use '~@x-wave/blog/styles/_variables' as vars;
331
-
332
- // Override the color palette
333
- $color-primary: #007bff;
334
- $color-background: #fafafa;
335
-
336
- // Your custom styles here
337
- ```
338
-
339
- Or import directly from the framework package:
340
-
341
- ```scss
342
- @import 'node_modules/@x-wave/blog/dist/styles/_variables.scss';
343
-
344
- $color-primary: #007bff;
345
- $color-background: #fafafa;
346
- ```
347
-
348
- Available variables include:
349
- - `$color-primary`, `$color-secondary`
350
- - `$color-background`, `$color-text`
351
- - `$spacing-xs`, `$spacing-sm`, `$spacing-md`, `$spacing-lg`, `$spacing-xl`
352
- - `$font-family-sans`, `$font-family-mono`
353
- - And more—see [styles/_variables.scss](packages/styles/_variables.scss)
354
-
355
- ### Config options
356
-
357
- **BlogConfig** properties:
358
-
359
- ```ts
360
- interface BlogConfig {
361
- title: string // Site title
362
- logo?: React.ComponentType<{ className?: string }> // Optional logo
363
- supportedLanguages: readonly string[] // e.g. ['en', 'es', 'zh']
364
- navigationData: NavigationEntry[] // Menu structure
365
- header?: {
366
- navLinks?: HeaderLink[] // Top-level nav links
367
- dropdownItems?: HeaderDropdownItem[] // Support dropdown menu
368
- }
369
- }
370
- ```
371
-
372
- ## Browser support
373
-
374
- - Chrome/Edge 90+
375
- - Firefox 88+
376
- - Safari 14+
377
- - Mobile browsers (iOS Safari 14.5+, Chrome Android 90+)
378
-
379
- ## License
380
-
381
- See LICENSE file in this repository.
382
-
383
- ---
384
-
385
- ## For framework maintainers
386
-
387
- Contributing or maintaining this framework? See [DEVELOPMENT.md](./DEVELOPMENT.md) for setup, architecture, and build system details.