|
1 |
| -import { defineConfig } from 'vitepress' |
2 |
| -import { useSidebar } from 'vitepress-openapi' |
3 |
| -import { loadSpec } from '../swagger/load' |
4 |
| -import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs' |
5 |
| -import { pagefindPlugin } from 'vitepress-plugin-pagefind' |
| 1 | +import path from 'path'; |
| 2 | +import fs from 'fs'; |
| 3 | +import yaml from 'js-yaml'; |
| 4 | +import { defineConfig } from 'vitepress'; |
| 5 | +import { useSidebar } from 'vitepress-openapi'; |
| 6 | +import { loadSpec } from '../swagger/load'; |
| 7 | +import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'; |
| 8 | +import { pagefindPlugin } from 'vitepress-plugin-pagefind'; |
6 | 9 |
|
7 |
| -const sidebarSpec1 = useSidebar({ spec: loadSpec(1) }) |
8 |
| -const sidebarSpec2 = useSidebar({ spec: loadSpec(2) }) |
| 10 | +// Load protocol messages from YAML file |
| 11 | +const protocolYamlPath = path.resolve(__dirname, '../public/files/protocol-v3.yaml'); |
| 12 | +const protocolYaml = fs.readFileSync(protocolYamlPath, 'utf8'); |
| 13 | +const protocolData = yaml.load(protocolYaml); |
| 14 | + |
| 15 | +// Generate menu items for protocol messages grouped by their respective groups |
| 16 | +const protocolMessages = protocolData.messages; |
| 17 | +const protocolGroups = protocolData.groups; |
| 18 | +const protocolMenuItems = Object.keys(protocolGroups) |
| 19 | + .filter(groupKey => !protocolGroups[groupKey].hidden) |
| 20 | + .map(groupKey => { |
| 21 | + const group = protocolGroups[groupKey]; |
| 22 | + const items = Object.keys(protocolMessages) |
| 23 | + .filter(key => protocolMessages[key].group === groupKey) |
| 24 | + .map(key => ({ |
| 25 | + text: `${key}: ${protocolMessages[key].name}`, |
| 26 | + link: `/devices/api/messages/${key}-${protocolMessages[key].name.toLowerCase().replace(/ /g, '-')}` |
| 27 | + })); |
| 28 | + return { |
| 29 | + text: group.name || groupKey, |
| 30 | + collapsed: true, |
| 31 | + items: items |
| 32 | + }; |
| 33 | + }); |
| 34 | + |
| 35 | +const sidebarSpec1 = useSidebar({ spec: loadSpec(1) }); |
| 36 | +const sidebarSpec2 = useSidebar({ spec: loadSpec(2) }); |
9 | 37 |
|
10 | 38 | // Function to make a sidebar group be collapsed
|
11 | 39 | function collapse(group) {
|
12 |
| - group.collapsed = true |
13 |
| - return group |
| 40 | + group.collapsed = true; |
| 41 | + return group; |
14 | 42 | }
|
15 | 43 |
|
16 | 44 | function reorder(group: { items: { link: string }[] }, orderedLinks: string[]) {
|
@@ -224,48 +252,7 @@ export default defineConfig({
|
224 | 252 | {
|
225 | 253 | text: 'Messages',
|
226 | 254 | link: '/devices/api/messages/',
|
227 |
| - items: [ |
228 |
| - { |
229 |
| - text: 'Generic', |
230 |
| - collapsed: true, |
231 |
| - items: [ |
232 |
| - { text: '5: ACK', link: '/devices/api/messages/5-ack' }, |
233 |
| - { text: '6: Keepalive', link: '/devices/api/messages/6-keepalive' }, |
234 |
| - ] |
235 |
| - }, |
236 |
| - { |
237 |
| - text: 'Device Services', |
238 |
| - collapsed: true, |
239 |
| - link: '/devices/api/messages/device-services', |
240 |
| - items: [ |
241 |
| - { text: '30: Transmit Now', link: '/devices/api/messages/30-device-transmit-now' }, |
242 |
| - { text: '31: GSM CFUN', link: '/devices/api/messages/31-device-gsm-cfun' }, |
243 |
| - { text: '32: GSM IMEI', link: '/devices/api/messages/32-device-gsm-imei' }, |
244 |
| - { text: '33: GSM ICCID', link: '/devices/api/messages/33-device-gsm-iccid' }, |
245 |
| - { text: '34: Status', link: '/devices/api/messages/34-device-status' }, |
246 |
| - { text: '35: ID', link: '/devices/api/messages/35-device-id' }, |
247 |
| - { text: '36: Time', link: '/devices/api/messages/36-device-time' }, |
248 |
| - { text: '37: Last Position', link: '/devices/api/messages/37-device-last-position' }, |
249 |
| - { text: '39: RTK', link: '/devices/api/messages/39-device-rtk' }, |
250 |
| - { text: '40: Haptics', link: '/devices/api/messages/40-device-haptics' }, |
251 |
| - { text: '41: Temperature', link: '/devices/api/messages/41-device-temperature' }, |
252 |
| - { text: '42: Buzzer', link: '/devices/api/messages/42-device-buzzer' }, |
253 |
| - { text: '44: Pressure', link: '/devices/api/messages/44-device-pressure' }, |
254 |
| - ] |
255 |
| - }, |
256 |
| - { |
257 |
| - text: 'Device UX', |
258 |
| - collapsed: true, |
259 |
| - // link: '/devices/api/messages/device-ux', |
260 |
| - items: [ |
261 |
| - { text: '10009: Text Page', link: '/devices/api/messages/10009-ux-text-page' }, |
262 |
| - { text: '10010: Menu Page', link: '/devices/api/messages/10010-ux-menu-page' }, |
263 |
| - { text: '10011: Bitmap', link: '/devices/api/messages/10011-ux-bitmap' }, |
264 |
| - { text: '10013: Button Press', link: '/devices/api/messages/10013-ux-button-press' }, |
265 |
| - { text: '10014: Screen Refresh', link: '/devices/api/messages/10014-ux-screen-refresh' }, |
266 |
| - ] |
267 |
| - }, |
268 |
| - ] |
| 255 | + items: protocolMenuItems, |
269 | 256 | },
|
270 | 257 | {
|
271 | 258 | text: 'Generate',
|
|
0 commit comments