Skip to content

Commit feeb94f

Browse files
committed
feat: Sidebar enhancements
1 parent acb4c34 commit feeb94f

3 files changed

Lines changed: 167 additions & 17 deletions

File tree

src/generators/web/ui/components/SideBar/index.jsx

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Select from '@node-core/ui-components/Common/Select';
22
import SideBar from '@node-core/ui-components/Containers/Sidebar';
33

44
import styles from './index.module.css';
5-
import { STATIC_DATA } from '../../constants.mjs';
5+
import { STATIC_DATA, SIDEBAR_GROUPS } from '../../constants.mjs';
66

77
/**
88
* @typedef {Object} SideBarProps
@@ -18,32 +18,59 @@ import { STATIC_DATA } from '../../constants.mjs';
1818
*/
1919
const redirect = url => (window.location.href = url);
2020

21+
/**
22+
* Builds grouped sidebar navigation from flat docPages list.
23+
* Pages not matching any group are placed under "Other".
24+
* @param {Array<[string, string]>} docPages - [Title, URL] pairs
25+
* @returns {Array<{ groupName: string, items: Array<{ label: string, link: string }> }>}
26+
*/
27+
const buildSideBarGroups = docPages => {
28+
const linkMap = new Map(docPages.map(([label, link]) => [link, label]));
29+
const assigned = new Set();
30+
31+
const groups = SIDEBAR_GROUPS.map(({ groupName, items }) => ({
32+
groupName,
33+
items: items
34+
.filter(link => {
35+
if (linkMap.has(link)) {
36+
assigned.add(link);
37+
return true;
38+
}
39+
40+
return false;
41+
})
42+
.map(link => ({ label: linkMap.get(link), link })),
43+
})).filter(group => group.items.length > 0);
44+
45+
const otherItems = docPages
46+
.filter(([, link]) => !assigned.has(link))
47+
.map(([label, link]) => ({ label, link }));
48+
49+
if (otherItems.length > 0) {
50+
groups.push({ groupName: 'Other', items: otherItems });
51+
}
52+
53+
return groups;
54+
};
55+
2156
/**
2257
* Sidebar component for MDX documentation with version selection and page navigation
2358
* @param {SideBarProps} props - Component props
2459
*/
2560
export default ({ versions, pathname, currentVersion, docPages }) => (
2661
<SideBar
2762
pathname={pathname}
28-
groups={[
29-
{
30-
groupName: 'API Documentation',
31-
items: docPages.map(([label, link]) => ({ label, link })),
32-
},
33-
]}
63+
groups={buildSideBarGroups(docPages)}
3464
onSelect={redirect}
3565
as={props => <a {...props} rel="prefetch" />}
3666
title="Navigation"
3767
>
38-
<div>
39-
<Select
40-
label={`${STATIC_DATA.title} version`}
41-
values={versions}
42-
inline={true}
43-
className={styles.select}
44-
placeholder={currentVersion}
45-
onChange={redirect}
46-
/>
47-
</div>
68+
<Select
69+
label={`${STATIC_DATA.title} version`}
70+
values={versions}
71+
className={styles.select}
72+
placeholder={currentVersion}
73+
onChange={redirect}
74+
/>
4875
</SideBar>
4976
);
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,120 @@
11
// eslint-disable-next-line no-undef
22
export const STATIC_DATA = __STATIC_DATA__;
3+
4+
/**
5+
* Defines the sidebar navigation groups and their associated page URLs.
6+
* Pages not listed here will be placed under "Other".
7+
* @type {Array<{ groupName: string, items: Array<string> }>}
8+
*/
9+
export const SIDEBAR_GROUPS = [
10+
{
11+
groupName: 'Getting Started',
12+
items: [
13+
'documentation.html',
14+
'synopsis.html',
15+
'cli.html',
16+
'environment_variables.html',
17+
'globals.html',
18+
],
19+
},
20+
{
21+
groupName: 'Module System',
22+
items: [
23+
'modules.html',
24+
'esm.html',
25+
'module.html',
26+
'packages.html',
27+
'typescript.html',
28+
],
29+
},
30+
{
31+
groupName: 'Networking & Protocols',
32+
items: [
33+
'http.html',
34+
'http2.html',
35+
'https.html',
36+
'net.html',
37+
'dns.html',
38+
'dgram.html',
39+
],
40+
},
41+
{
42+
groupName: 'File System & I/O',
43+
items: [
44+
'fs.html',
45+
'path.html',
46+
'buffer.html',
47+
'stream.html',
48+
'string_decoder.html',
49+
'zlib.html',
50+
'readline.html',
51+
'tty.html',
52+
],
53+
},
54+
{
55+
groupName: 'Asynchronous Programming',
56+
items: [
57+
'async_context.html',
58+
'async_hooks.html',
59+
'events.html',
60+
'timers.html',
61+
'webstreams.html',
62+
],
63+
},
64+
{
65+
groupName: 'Process & Concurrency',
66+
items: [
67+
'process.html',
68+
'child_process.html',
69+
'cluster.html',
70+
'worker_threads.html',
71+
'os.html',
72+
],
73+
},
74+
{
75+
groupName: 'Security & Cryptography',
76+
items: ['crypto.html', 'webcrypto.html', 'permissions.html', 'tls.html'],
77+
},
78+
{
79+
groupName: 'Data & URL Utilities',
80+
items: ['url.html', 'querystring.html', 'punycode.html', 'util.html'],
81+
},
82+
{
83+
groupName: 'Debugging & Diagnostics',
84+
items: [
85+
'debugger.html',
86+
'inspector.html',
87+
'console.html',
88+
'report.html',
89+
'tracing.html',
90+
'diagnostics_channel.html',
91+
'errors.html',
92+
],
93+
},
94+
{
95+
groupName: 'Testing & Assertion',
96+
items: ['test.html', 'assert.html', 'repl.html'],
97+
},
98+
{
99+
groupName: 'Performance & Observability',
100+
items: ['perf_hooks.html', 'v8.html'],
101+
},
102+
{
103+
groupName: 'Runtime & Advanced APIs',
104+
items: [
105+
'vm.html',
106+
'wasi.html',
107+
'sqlite.html',
108+
'single-executable-applications.html',
109+
'intl.html',
110+
],
111+
},
112+
{
113+
groupName: 'Native & Low-level Extensions',
114+
items: ['addons.html', 'n-api.html', 'embedding.html'],
115+
},
116+
{
117+
groupName: 'Legacy & Deprecated',
118+
items: ['deprecations.html', 'domain.html'],
119+
},
120+
];

src/generators/web/ui/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,8 @@ main {
118118
}
119119
}
120120
}
121+
122+
/* Override the min-width of the select component used for version selection in the sidebar */
123+
[class*="select"] button[role="combobox"] {
124+
min-width: initial;
125+
}

0 commit comments

Comments
 (0)