Skip to content

Commit d52a600

Browse files
committed
feat: add VitePress documentation for mqttkit
- Initialize VitePress configuration in `docs/.vitepress/config.ts`. - Create main documentation pages including `index.md`, `getting-started.md`, `aedes.md`, `events.md`, `kafka-bridge.md`, `rpc.md`, `schema.md`, `service-push.md`, `testing.md` with English and Chinese translations. - Add Cloudflare headers configuration in `docs/public/_headers`. - Include favicon in `docs/public/favicon.svg`. - Update `package.json` to include documentation scripts for development, building, and previewing. - Remove Chinese links from individual documentation pages.
1 parent 2c6f27f commit d52a600

26 files changed

Lines changed: 622 additions & 37 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules/
22
dist/
33
.vite/
44
.DS_Store
5-
legacy
5+
legacy
6+
docs/.vitepress/dist
7+
docs/.vitepress/cache

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ bun run --cwd examples/aedes-basic dev
298298

299299
## Documentation
300300

301-
- [Getting Started](docs/getting-started.md) / [简体中文](docs/getting-started.zh-CN.md)
302-
- [Aedes adapter](docs/aedes.md) / [简体中文](docs/aedes.zh-CN.md)
303-
- [Events](docs/events.md) / [简体中文](docs/events.zh-CN.md)
304-
- [Service Push](docs/service-push.md) / [简体中文](docs/service-push.zh-CN.md)
305-
- [Kafka bridge](docs/kafka-bridge.md) / [简体中文](docs/kafka-bridge.zh-CN.md)
301+
- [Getting Started](docs/getting-started.md) / [简体中文](docs/zh/getting-started.md)
302+
- [Aedes adapter](docs/aedes.md) / [简体中文](docs/zh/aedes.md)
303+
- [Events](docs/events.md) / [简体中文](docs/zh/events.md)
304+
- [Service Push](docs/service-push.md) / [简体中文](docs/zh/service-push.md)
305+
- [Kafka bridge](docs/kafka-bridge.md) / [简体中文](docs/zh/kafka-bridge.md)
306306

307307
## Development
308308

README.zh-CN.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ bun run --cwd examples/aedes-basic dev
298298

299299
## 文档
300300

301-
- [快速开始](docs/getting-started.zh-CN.md) / [English](docs/getting-started.md)
302-
- [Aedes adapter](docs/aedes.zh-CN.md) / [English](docs/aedes.md)
303-
- [事件监听](docs/events.zh-CN.md) / [English](docs/events.md)
304-
- [Service Push](docs/service-push.zh-CN.md) / [English](docs/service-push.md)
305-
- [Kafka bridge](docs/kafka-bridge.zh-CN.md) / [English](docs/kafka-bridge.md)
301+
- [快速开始](docs/zh/getting-started.md) / [English](docs/getting-started.md)
302+
- [Aedes adapter](docs/zh/aedes.md) / [English](docs/aedes.md)
303+
- [事件监听](docs/zh/events.md) / [English](docs/events.md)
304+
- [Service Push](docs/zh/service-push.md) / [English](docs/service-push.md)
305+
- [Kafka bridge](docs/zh/kafka-bridge.md) / [English](docs/kafka-bridge.md)
306306

307307
## 开发
308308

bun.lock

Lines changed: 287 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/.vitepress/config.ts

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import { defineConfig } from 'vitepress'
2+
3+
const GITHUB_REPO = 'https://github.com/keyp/mqttkit'
4+
5+
// Runs in <head> before body parsing so the browser starts navigating
6+
// before the English landing renders. Only fires on the landing path.
7+
// `document.referrer` check lets users click the langSwitcher back to
8+
// English from /zh/ without bouncing them in a loop.
9+
const browserLanguageRedirect = `(function(){
10+
if (typeof window === 'undefined') return;
11+
var path = location.pathname;
12+
if (path !== '/' && path !== '/index.html') return;
13+
try {
14+
if (document.referrer) {
15+
var ref = new URL(document.referrer);
16+
if (ref.host === location.host && ref.pathname.indexOf('/zh') === 0) return;
17+
}
18+
} catch (e) {}
19+
var langs = navigator.languages && navigator.languages.length
20+
? navigator.languages
21+
: [navigator.language || ''];
22+
for (var i = 0; i < langs.length; i++) {
23+
var l = (langs[i] || '').toLowerCase();
24+
if (l.indexOf('zh') === 0) {
25+
location.replace('/zh/');
26+
return;
27+
}
28+
}
29+
})();`
30+
31+
type SidebarTopic = {
32+
id: string
33+
en: string
34+
zh: string
35+
}
36+
37+
// Single source of truth for the guide sidebar order (matches plan R3).
38+
const GUIDE_TOPICS: SidebarTopic[] = [
39+
{ id: 'getting-started', en: 'Getting Started', zh: '快速开始' },
40+
{ id: 'aedes', en: 'Aedes Adapter', zh: 'Aedes 适配器' },
41+
{ id: 'schema', en: 'Schema Validation', zh: 'Schema 校验' },
42+
{ id: 'rpc', en: 'RPC', zh: 'RPC' },
43+
{ id: 'events', en: 'Events', zh: '事件监听' },
44+
{ id: 'service-push', en: 'Service Push', zh: 'Service Push' },
45+
{ id: 'kafka-bridge', en: 'Kafka Bridge', zh: 'Kafka Bridge' },
46+
{ id: 'testing', en: 'Testing', zh: '测试' },
47+
]
48+
49+
const enSidebarItems = GUIDE_TOPICS.map((topic) => ({
50+
text: topic.en,
51+
link: `/${topic.id}`,
52+
}))
53+
54+
const zhSidebarItems = GUIDE_TOPICS.map((topic) => ({
55+
text: topic.zh,
56+
link: `/zh/${topic.id}`,
57+
}))
58+
59+
export default defineConfig({
60+
title: 'mqttkit',
61+
description:
62+
'Elysia-style MQTT application framework. Compose broker adapters, middleware, topic routers, validation, and services.',
63+
lastUpdated: true,
64+
cleanUrls: true,
65+
head: [
66+
['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }],
67+
['meta', { name: 'theme-color', content: '#3eaf7c' }],
68+
['script', {}, browserLanguageRedirect],
69+
],
70+
themeConfig: {
71+
socialLinks: [{ icon: 'github', link: GITHUB_REPO }],
72+
search: {
73+
provider: 'local',
74+
options: {
75+
locales: {
76+
zh: {
77+
translations: {
78+
button: {
79+
buttonText: '搜索文档',
80+
buttonAriaLabel: '搜索文档',
81+
},
82+
modal: {
83+
noResultsText: '无法找到相关结果',
84+
resetButtonTitle: '清除查询条件',
85+
footer: {
86+
selectText: '选择',
87+
navigateText: '切换',
88+
closeText: '关闭',
89+
},
90+
},
91+
},
92+
},
93+
},
94+
},
95+
},
96+
},
97+
locales: {
98+
root: {
99+
label: 'English',
100+
lang: 'en-US',
101+
themeConfig: {
102+
nav: [
103+
{ text: 'Guide', link: '/getting-started' },
104+
{ text: 'Packages', link: `${GITHUB_REPO}/tree/main/packages` },
105+
{ text: 'Examples', link: `${GITHUB_REPO}/tree/main/examples` },
106+
{ text: 'Changelog', link: `${GITHUB_REPO}/blob/main/CHANGELOG.md` },
107+
],
108+
sidebar: [
109+
{
110+
text: 'Guide',
111+
items: enSidebarItems,
112+
},
113+
],
114+
editLink: {
115+
pattern: `${GITHUB_REPO}/edit/main/docs/:path`,
116+
text: 'Edit this page on GitHub',
117+
},
118+
footer: {
119+
message: 'Released under the MIT License.',
120+
},
121+
},
122+
},
123+
zh: {
124+
label: '简体中文',
125+
lang: 'zh-CN',
126+
link: '/zh/',
127+
themeConfig: {
128+
nav: [
129+
{ text: '指南', link: '/zh/getting-started' },
130+
{ text: '包', link: `${GITHUB_REPO}/tree/main/packages` },
131+
{ text: '示例', link: `${GITHUB_REPO}/tree/main/examples` },
132+
{ text: '更新日志', link: `${GITHUB_REPO}/blob/main/CHANGELOG.md` },
133+
],
134+
sidebar: {
135+
'/zh/': [
136+
{
137+
text: '指南',
138+
items: zhSidebarItems,
139+
},
140+
],
141+
},
142+
outline: { label: '本页目录' },
143+
docFooter: { prev: '上一页', next: '下一页' },
144+
darkModeSwitchLabel: '主题',
145+
lightModeSwitchTitle: '切换到浅色模式',
146+
darkModeSwitchTitle: '切换到深色模式',
147+
sidebarMenuLabel: '菜单',
148+
returnToTopLabel: '回到顶部',
149+
langMenuLabel: '切换语言',
150+
editLink: {
151+
pattern: `${GITHUB_REPO}/edit/main/docs/:path`,
152+
text: '在 GitHub 上编辑此页',
153+
},
154+
footer: {
155+
message: '基于 MIT 协议发布',
156+
},
157+
},
158+
},
159+
},
160+
})

docs/aedes.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Aedes Adapter
22

3-
[简体中文](aedes.zh-CN.md)
4-
53
`@mqttkit/aedes` connects an Aedes broker to `MqttApp`. Aedes keeps owning MQTT protocol behavior, while mqttkit owns application routes, middleware, policies, service injection, and events.
64

75
## TCP MQTT

docs/events.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Events
22

3-
[简体中文](events.zh-CN.md)
4-
53
Use `app.on()` to listen to broker lifecycle events. With `@mqttkit/aedes`, events come from Aedes.
64

75
## Supported Events

docs/getting-started.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Getting Started
22

3-
[简体中文](getting-started.zh-CN.md)
4-
53
mqttkit organizes MQTT applications with `MqttApp`, ordered `use()` middleware, and `router().topic()`. Broker adapters own connections, QoS, retain, sessions, and persistence.
64

75
## Install

docs/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
layout: home
3+
4+
hero:
5+
name: mqttkit
6+
text: Elysia-style MQTT framework
7+
tagline: Compose broker adapters, middleware, topic routers, schema validation, and services with one fluent API.
8+
actions:
9+
- theme: brand
10+
text: Get Started
11+
link: /getting-started
12+
- theme: alt
13+
text: View on GitHub
14+
link: https://github.com/keyp/mqttkit
15+
16+
features:
17+
- title: Routing & Middleware
18+
details: Ordered <code>use()</code> middleware, <code>router().topic()</code> declarations, and topic params extracted directly into <code>ctx.params</code>.
19+
- title: Schema & RPC
20+
details: Any Standard Schema validator (zod, valibot, arktype) plugs in via <code>topic({ schema })</code>. MQTT 5 RPC round-trips through <code>app.request()</code> and <code>ctx.reply()</code>.
21+
- title: AsyncAPI Docs
22+
details: Generate AsyncAPI 3.0 documents directly from your routes with <code>@mqttkit/asyncapi</code>, with JSON Schema flow from TypeBox or zod.
23+
---

docs/kafka-bridge.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Kafka Bridge
22

3-
[简体中文](kafka-bridge.zh-CN.md)
4-
53
mqttkit does not include a Kafka client. The recommended approach is to inject Kafka producers and consumers as business services, then connect both sides with MQTT topic routes.
64

75
## MQTT -> Kafka

0 commit comments

Comments
 (0)