Skip to content

Commit a1fdc71

Browse files
committed
fixup!
1 parent 1f72d82 commit a1fdc71

2 files changed

Lines changed: 43 additions & 14 deletions

File tree

components/Sidebar/index.jsx

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,58 @@
11
import SideBar from '@node-core/ui-components/Containers/Sidebar';
22
import { relative } from '@node-core/doc-kit/src/utils/url.mjs';
3-
43
import { pages } from '#theme/config';
54

6-
/**
7-
* Redirect to a URL
8-
* @param {string} url URL
9-
*/
5+
/** @type {Array<[string, string]>} */
6+
const categories = [
7+
['getting-started', 'Getting Started'],
8+
['command-line', 'Command Line'],
9+
['http', 'HTTP'],
10+
['file-system', 'File System'],
11+
['asynchronous-work', 'Asynchronous Work'],
12+
['typescript', 'TypeScript'],
13+
['package-management', 'Package Management'],
14+
['diagnostics', 'Diagnostics'],
15+
['testing', 'Testing'],
16+
['security', 'Security'],
17+
];
18+
19+
/** @type {Map<string, Array<{ heading: string, path: string }>>} */
20+
const byDir = new Map();
21+
for (const [heading, path] of pages) {
22+
const dir = path.split('/')[1];
23+
if (!byDir.has(dir)) byDir.set(dir, []);
24+
byDir.get(dir).push({ heading, path });
25+
}
26+
27+
/** @param {string} url */
1028
const redirect = url => (window.location.href = url);
1129

30+
const PrefetchLink = props => <a {...props} rel="prefetch" />;
31+
1232
/**
1333
* Sidebar component for MDX documentation with page navigation
1434
*/
1535
export default ({ metadata }) => {
16-
const items = pages.map(([heading, path]) => ({
17-
label: heading,
18-
link:
19-
metadata.path === path
20-
? `${metadata.basename}.html`
21-
: `${relative(path, metadata.path)}.html`,
36+
const { path: currentPath, basename } = metadata;
37+
const pathname = `${basename}.html`;
38+
39+
const groups = categories.map(([dir, title]) => ({
40+
groupName: title,
41+
items: byDir.get(dir).map(({ heading, path }) => ({
42+
label: heading,
43+
link:
44+
currentPath === path
45+
? pathname
46+
: `${relative(path, currentPath)}.html`,
47+
})),
2248
}));
2349

2450
return (
2551
<SideBar
26-
pathname={`${metadata.basename}.html`}
27-
groups={[{ groupName: 'Learn Articles', items }]}
52+
pathname={pathname}
53+
groups={groups}
2854
onSelect={redirect}
29-
as={props => <a {...props} rel="prefetch" />}
55+
as={PrefetchLink}
3056
title="Navigation"
3157
/>
3258
);

package-lock.json

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

0 commit comments

Comments
 (0)