|
| 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 | +}) |
0 commit comments