Skip to content

Commit c79301c

Browse files
committed
feat(doc-kit): bump version, use virtualImports
1 parent 775888e commit c79301c

File tree

10 files changed

+238
-133
lines changed

10 files changed

+238
-133
lines changed

components/Footer/footer.json

Lines changed: 0 additions & 62 deletions
This file was deleted.

components/Footer/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import Footer from '@node-core/ui-components/Containers/Footer';
22
import NavItem from '@node-core/ui-components/Containers/NavBar/NavItem';
33

4-
import { socialLinks, footerLinks } from './footer.json';
4+
import {
5+
socialLinks,
6+
footerLinks,
7+
} from '#site/navigation.json' with { type: 'json' };
58

69
// The Node.js Project is legally obligated to include the following text.
710
// It should not be modified unless explicitly requested by OpenJS staff.

components/Navigation/index.jsx

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
55

66
import SearchBox from '@node-core/doc-kit/src/generators/web/ui/components/SearchBox';
77
import { useTheme } from '@node-core/doc-kit/src/generators/web/ui/hooks/useTheme.mjs';
8-
8+
import { topNavigation } from '#site/navigation.json' with { type: 'json' };
99
import Logo from '#theme/Logo';
1010

1111
/**
@@ -18,23 +18,11 @@ export default ({ metadata }) => {
1818
<NavBar
1919
Logo={Logo}
2020
sidebarItemTogglerAriaLabel="Toggle navigation menu"
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-
]}
21+
navItems={Object.values(topNavigation).map(({ link, label, target }) => ({
22+
link,
23+
text: label,
24+
target,
25+
}))}
3826
>
3927
<SearchBox pathname={metadata.path} />
4028
<ThemeToggle

components/Sidebar/index.jsx

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
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';
4-
5-
/** @type {Array<[string, string]>} */
6-
const categories = [
7-
['getting-started', 'Getting Started'],
8-
['command-line', 'Command Line'],
9-
['http', 'HTTP'],
10-
['manipulating-files', 'Manipulating Files'],
11-
['asynchronous-work', 'Asynchronous Work'],
12-
['typescript', 'TypeScript'],
13-
['modules', 'Modules'],
14-
['diagnostics', 'Diagnostics'],
15-
['test-runner', 'Test Runner'],
16-
];
17-
18-
/** @type {Map<string, Array<{ heading: string, path: string }>>} */
19-
const byDir = new Map();
20-
for (const [heading, path] of pages) {
21-
const dir = path.split('/')[1];
22-
if (!byDir.has(dir)) byDir.set(dir, []);
23-
byDir.get(dir).push({ heading, path });
24-
}
2+
import sidebarGroups from '#learn/navigation.json' with { type: 'json' };
253

264
/** @param {string} url */
275
const redirect = url => (window.location.href = url);
@@ -31,26 +9,12 @@ const PrefetchLink = props => <a {...props} rel="prefetch" />;
319
/**
3210
* Sidebar component for MDX documentation with page navigation
3311
*/
34-
export default ({ metadata }) => {
35-
const { path: currentPath, basename } = metadata;
36-
const pathname = `${basename}.html`;
37-
38-
const groups = categories.map(([dir, title]) => ({
39-
groupName: title,
40-
items: byDir.get(dir).map(({ heading, path }) => ({
41-
label: heading,
42-
link:
43-
currentPath === path ? pathname : `${relative(path, currentPath)}.html`,
44-
})),
45-
}));
46-
47-
return (
48-
<SideBar
49-
pathname={pathname}
50-
groups={groups}
51-
onSelect={redirect}
52-
as={PrefetchLink}
53-
title="Navigation"
54-
/>
55-
);
56-
};
12+
export default ({ metadata }) => (
13+
<SideBar
14+
pathname={`/learn${metadata.path}`}
15+
groups={sidebarGroups}
16+
onSelect={redirect}
17+
as={PrefetchLink}
18+
title="Navigation"
19+
/>
20+
);

doc-kit.config.mjs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import web from '@node-core/doc-kit/src/generators/web/index.mjs';
22
import { join } from 'node:path';
3+
import { populateI18n, createGroupings } from './utils/index.mjs';
4+
import sidebarGroups from './navigation.json' with { type: 'json' };
35

46
/** @type {import('@node-core/doc-kit/src/utils/configuration/types.d.ts').Configuration} */
57
export default {
@@ -8,12 +10,29 @@ export default {
810
input: ['pages/**/*.md'],
911
},
1012
web: {
11-
title: '',
13+
// Important Configuration
14+
project: 'Node.js',
15+
title: '{project} Learn',
1216
pageURL: 'https://nodejs.org/learn{path}.html',
1317
editURL: 'https://github.com/nodejs/learn/edit/main/pages{path}.md',
18+
templatePath: join(import.meta.dirname, 'template.html'),
19+
20+
// Imports
1421
imports: {
1522
...web.defaultConfiguration.imports,
1623
'#theme/Layout': join(import.meta.dirname, 'components/Layout/index.jsx'),
1724
},
25+
virtualImports: {
26+
'#site/navigation.json': JSON.stringify(
27+
populateI18n(
28+
await fetch(
29+
'https://raw.githubusercontent.com/nodejs/nodejs.org/refs/heads/main/apps/site/navigation.json'
30+
).then(r => r.json())
31+
)
32+
),
33+
'#learn/navigation.json': JSON.stringify(
34+
await createGroupings(sidebarGroups)
35+
),
36+
},
1837
},
1938
};

navigation.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
[
2+
[
3+
"Getting Started",
4+
[
5+
"/getting-started/introduction-to-nodejs.md",
6+
"/getting-started/how-much-javascript-do-you-need-to-know-to-use-nodejs.md",
7+
"/getting-started/differences-between-nodejs-and-the-browser.md",
8+
"/getting-started/the-v8-javascript-engine.md",
9+
"/getting-started/an-introduction-to-the-npm-package-manager.md",
10+
"/getting-started/ecmascript-2015-es6-and-beyond.md",
11+
"/getting-started/debugging.md",
12+
"/getting-started/fetch.md",
13+
"/getting-started/websocket.md",
14+
"/getting-started/nodejs-the-difference-between-development-and-production.md",
15+
"/getting-started/profiling.md",
16+
"/getting-started/nodejs-with-webassembly.md",
17+
"/getting-started/security-best-practices.md",
18+
"/getting-started/userland-migrations.md"
19+
]
20+
],
21+
[
22+
"Command Line",
23+
[
24+
"/command-line/run-nodejs-scripts-from-the-command-line.md",
25+
"/command-line/how-to-use-the-nodejs-repl.md",
26+
"/command-line/output-to-the-command-line-using-nodejs.md",
27+
"/command-line/accept-input-from-the-command-line-in-nodejs.md",
28+
"/command-line/how-to-read-environment-variables-from-nodejs.md"
29+
]
30+
],
31+
[
32+
"HTTP",
33+
[
34+
"/http/anatomy-of-an-http-transaction.md",
35+
"/http/enterprise-network-configuration.md"
36+
]
37+
],
38+
[
39+
"Manipulating Files",
40+
[
41+
"/manipulating-files/nodejs-file-stats.md",
42+
"/manipulating-files/nodejs-file-paths.md",
43+
"/manipulating-files/reading-files-with-nodejs.md",
44+
"/manipulating-files/writing-files-with-nodejs.md",
45+
"/manipulating-files/working-with-file-descriptors-in-nodejs.md",
46+
"/manipulating-files/working-with-folders-in-nodejs.md",
47+
"/manipulating-files/working-with-different-filesystems.md"
48+
]
49+
],
50+
[
51+
"Asynchronous Work",
52+
[
53+
"/asynchronous-work/javascript-asynchronous-programming-and-callbacks.md",
54+
"/asynchronous-work/asynchronous-flow-control.md",
55+
"/asynchronous-work/discover-promises-in-nodejs.md",
56+
"/asynchronous-work/discover-javascript-timers.md",
57+
"/asynchronous-work/overview-of-blocking-vs-non-blocking.md",
58+
"/asynchronous-work/event-loop-timers-and-nexttick.md",
59+
"/asynchronous-work/the-nodejs-event-emitter.md",
60+
"/asynchronous-work/understanding-processnexttick.md",
61+
"/asynchronous-work/understanding-setimmediate.md",
62+
"/asynchronous-work/dont-block-the-event-loop.md"
63+
]
64+
],
65+
[
66+
"TypeScript",
67+
[
68+
"/typescript/introduction.md",
69+
"/typescript/run-natively.md",
70+
"/typescript/transpile.md",
71+
"/typescript/run.md",
72+
"/typescript/publishing-a-ts-package.md"
73+
]
74+
],
75+
[
76+
"Modules",
77+
[
78+
"/modules/how-to-use-streams.md",
79+
"/modules/backpressuring-in-streams.md",
80+
"/modules/publishing-a-package.md",
81+
"/modules/publishing-node-api-modules.md",
82+
"/modules/abi-stability.md"
83+
]
84+
],
85+
[
86+
"Diagnostics",
87+
[
88+
"/diagnostics/user-journey.md",
89+
"/diagnostics/memory/index.md",
90+
"/diagnostics/live-debugging/index.md",
91+
"/diagnostics/poor-performance/index.md",
92+
"/diagnostics/flame-graphs.md"
93+
]
94+
],
95+
[
96+
"Test Runner",
97+
[
98+
"/test-runner/introduction.md",
99+
"/test-runner/using-test-runner.md",
100+
"/test-runner/mocking.md",
101+
"/test-runner/collecting-code-coverage.md"
102+
]
103+
]
104+
]

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"devDependencies": {
1111
"@eslint/js": "^10.0.1",
12-
"@node-core/doc-kit": "1.3.1",
12+
"@node-core/doc-kit": "1.3.2",
1313
"@node-core/remark-lint": "^1.3.0",
1414
"eslint": "^10.1.0",
1515
"eslint-plugin-mdx": "^3.7.0",

template.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="icon" href="https://nodejs.org/static/images/favicons/favicon.png"/>
8+
<title>{title}</title>
9+
<meta name="description" content="Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.">
10+
<link rel="stylesheet" href="{root}styles.css" />
11+
<meta property="og:title" content="{title}">
12+
<meta property="og:description" content="Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.">
13+
<meta property="og:image" content="https://nodejs.org/en/next-data/og/announcement/Node.js%20%E2%80%94%20Learn%20Articles" />
14+
<meta property="og:type" content="website">
15+
16+
<link rel="preconnect" href="https://fonts.googleapis.com" />
17+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
18+
<link rel="stylesheet"
19+
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=Open+Sans:ital,wght@0,300..800;1,300..800" />
20+
<link rel="canonical" href="https://nodejs.org/learn{path}" />
21+
22+
<script>document.documentElement.setAttribute("data-theme", document.documentElement.style.colorScheme = localStorage.getItem("theme") || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"));</script>
23+
<script type="importmap">{importMap}</script>
24+
<script type="speculationrules">{speculationRules}</script>
25+
</head>
26+
27+
<body>
28+
<div id="root">{dehydrated}</div>
29+
<script type="module" src="{root}{entrypoint}"></script>
30+
</body>
31+
</html>

0 commit comments

Comments
 (0)