Skip to content

Commit ce9a5fb

Browse files
authored
feat(docs): use doc-kit 1.3.0 (#11)
1 parent 448fb68 commit ce9a5fb

75 files changed

Lines changed: 269 additions & 526 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node_modules
22
out
3-
components/config.json

.remarkrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"plugins": ["@node-core/remark-lint"]
2+
"plugins": ["remark-frontmatter", "@node-core/remark-lint"]
33
}

components/Metabar/index.jsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,25 @@ import MetaBar from '@node-core/ui-components/Containers/MetaBar';
22
import AvatarGroup from '@node-core/ui-components/Common/AvatarGroup';
33
import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
44

5-
import { authors } from '../config.json' with { type: 'json' };
5+
import { editURL } from '#theme/config';
66

7-
/**
8-
* @typedef MetaBarProps
9-
* @property {Array<import('@vcarl/remark-headings').Heading>} headings
10-
* @property {string} readingTime
11-
* @property {Array<[string, string]>} viewAs
12-
* @property {string} editThisPage
13-
*/
14-
15-
/** @param {MetaBarProps} props */
16-
export default ({ headings = [], readingTime, viewAs = [], editThisPage }) => {
17-
const pageAuthors = authors[editThisPage];
7+
export default ({ metadata, headings = [], readingTime }) => {
8+
const editThisPage = editURL.replace('{path}', metadata.path);
9+
const authors = metadata.authors?.split(',').map(id => ({
10+
image: `https://avatars.githubusercontent.com/${id.trim()}`,
11+
url: `https://github.com/${id.trim()}`,
12+
nickname: id,
13+
}));
1814

1915
return (
2016
<MetaBar
2117
heading="Table of Contents"
2218
headings={{ items: headings }}
2319
items={{
2420
'Reading Time': readingTime,
25-
...(CLIENT && pageAuthors?.length
21+
...(CLIENT && authors?.length
2622
? {
27-
Authors: (
28-
<AvatarGroup avatars={pageAuthors} as="a" clickable limit={5} />
29-
),
23+
Authors: <AvatarGroup avatars={authors} as="a" limit={5} />,
3024
}
3125
: {}),
3226
Contribute: (

components/Navigation/index.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import SearchBox from '@node-core/doc-kit/src/generators/web/ui/components/Searc
77
import { useTheme } from '@node-core/doc-kit/src/generators/web/ui/hooks/useTheme.mjs';
88

99
import Logo from '#theme/Logo';
10-
import { topNav } from '../config.json' with { type: 'json' };
1110

1211
/**
1312
* NavBar component that displays the headings, search, etc.
@@ -19,7 +18,23 @@ export default () => {
1918
<NavBar
2019
Logo={Logo}
2120
sidebarItemTogglerAriaLabel="Toggle navigation menu"
22-
navItems={topNav}
21+
navItems={[
22+
{ link: '/learn', text: 'Learn' },
23+
{ link: '/about', text: 'About' },
24+
{ link: '/download', text: 'Download' },
25+
{ link: '/blog', text: 'Blog' },
26+
{ link: 'https://nodejs.org/docs/latest/api/', text: 'Docs' },
27+
{
28+
link: 'https://github.com/nodejs/node/blob/main/CONTRIBUTING.md',
29+
text: 'Contribute',
30+
target: '_blank',
31+
},
32+
{
33+
link: 'https://training.linuxfoundation.org/openjs/',
34+
text: 'Courses',
35+
target: '_blank',
36+
},
37+
]}
2338
>
2439
<SearchBox />
2540
<ThemeToggle

components/Sidebar/index.jsx

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
11
import SideBar from '@node-core/ui-components/Containers/Sidebar';
2+
import { relative } from '@node-core/doc-kit/src/utils/url.mjs';
3+
import { pages } from '#theme/config';
24

3-
import { sideNav } from '../config.json' with { type: 'json' };
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+
];
418

5-
/**
6-
* Redirect to a URL
7-
* @param {string} url URL
8-
*/
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 */
928
const redirect = url => (window.location.href = url);
1029

30+
const PrefetchLink = props => <a {...props} rel="prefetch" />;
31+
1132
/**
1233
* Sidebar component for MDX documentation with page navigation
13-
* @param {{ pathname: string }} props
1434
*/
15-
export default ({ pathname }) => (
16-
<SideBar
17-
pathname={pathname}
18-
groups={sideNav}
19-
onSelect={redirect}
20-
as={props => <a {...props} rel="prefetch" />}
21-
title="Navigation"
22-
/>
23-
);
35+
export default ({ metadata }) => {
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 ? pathname : `${relative(path, currentPath)}.html`,
45+
})),
46+
}));
47+
48+
return (
49+
<SideBar
50+
pathname={pathname}
51+
groups={groups}
52+
onSelect={redirect}
53+
as={PrefetchLink}
54+
title="Navigation"
55+
/>
56+
);
57+
};

doc-kit.config.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ export default {
77
output: 'out',
88
input: ['pages/**/*.md'],
99
},
10-
'jsx-ast': {
11-
// TODO(@avivkeller): Hook this up to render at nodejs.org/learn
12-
pageURL: 'https://nodejs.github.io/learn{path}.html',
13-
editURL: 'https://github.com/nodejs/learn/edit/main/pages{path}.md',
14-
},
1510
web: {
1611
title: '',
12+
pageURL: 'https://nodejs.org/learn{path}.html',
13+
editURL: 'https://github.com/nodejs/learn/edit/main/pages{path}.md',
1714
imports: {
1815
...web.defaultConfiguration.imports,
1916
'#theme/Navigation': join(

package-lock.json

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

0 commit comments

Comments
 (0)