Skip to content

Commit cf23e7c

Browse files
authored
chore(cleanup): move mdx files out of root (#8167)
* chore(cleanup): move mdx files out of root * fixup! * use prefix
1 parent 6cabc97 commit cf23e7c

File tree

10 files changed

+121
-189
lines changed

10 files changed

+121
-189
lines changed

apps/site/components/Downloads/Release/ReleaseCodeBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ import CodeBox from '#site/components/Common/CodeBox';
1111
import LinkWithArrow from '#site/components/Common/LinkWithArrow';
1212
import Link from '#site/components/Link';
1313
import WithReleaseAlertBox from '#site/components/withReleaseAlertBox';
14-
import { createSval } from '#site/next.jsx.compiler.mjs';
1514
import {
1615
ReleaseContext,
1716
ReleasesContext,
1817
} from '#site/providers/releaseProvider';
1918
import type { DownloadSnippet } from '#site/types/download';
2019
import type { ReleaseContextType } from '#site/types/release';
2120
import { INSTALL_METHODS } from '#site/util/download';
21+
import createInterpreter from '#site/util/interpreter';
2222

2323
// Creates a minimal JavaScript interpreter for parsing the JavaScript code from the snippets
2424
// Note: that the code runs inside a sandboxed environment and cannot interact with any code outside of the sandbox
2525
// It also does not have access to any Global or Window objects, nor it can execute code on the end-user's browser
2626
// It also only allows a return statement for a string and it forces the return value to also be a string and only be used
2727
// by Shiki to render the highlighted syntax. Hence XSS attacks or JavaScript injections are not possible.
28-
const interpreter = createSval({}, 'script');
28+
const interpreter = createInterpreter({}, 'script');
2929

3030
/**
3131
* Parses a snippet string using the interpreter with the given release context

apps/site/next.mdx.compiler.mjs renamed to apps/site/mdx/compiler.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { compile as mdxCompile } from '@mdx-js/mdx';
44
import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
55
import { matter } from 'vfile-matter';
66

7-
import { createSval } from './next.jsx.compiler.mjs';
8-
import { REHYPE_PLUGINS, REMARK_PLUGINS } from './next.mdx.plugins.mjs';
9-
import { createGitHubSlugger } from './util/github';
7+
import { rehypePlugins, remarkPlugins } from './plugins.mjs';
8+
import { createGitHubSlugger } from '../util/github';
9+
import createInterpreter from '../util/interpreter';
1010

1111
// Defines a JSX Fragment and JSX Runtime for the MDX Compiler
12-
export const reactRuntime = { Fragment, jsx, jsxs };
12+
const reactRuntime = { Fragment, jsx, jsxs };
1313

1414
/**
1515
* This is our custom simple MDX Compiler that is used to compile Markdown and MDX
@@ -27,7 +27,7 @@ export const reactRuntime = { Fragment, jsx, jsxs };
2727
* readingTime: import('reading-time').ReadTimeResults;
2828
* }>}
2929
*/
30-
export async function compile(
30+
export default async function compile(
3131
source,
3232
fileExtension,
3333
components = {},
@@ -42,12 +42,12 @@ export async function compile(
4242

4343
// Compiles the MDX/Markdown source into a serializable VFile
4444
const compiled = await mdxCompile(source, {
45-
rehypePlugins: REHYPE_PLUGINS,
46-
remarkPlugins: REMARK_PLUGINS,
45+
rehypePlugins,
46+
remarkPlugins,
4747
format: fileExtension,
4848
});
4949

50-
const interpreter = createSval({
50+
const interpreter = createInterpreter({
5151
...components,
5252
'react/jsx-runtime': reactRuntime,
5353
});

apps/site/mdx/components.mjs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
'use strict';
2+
3+
import BadgeGroup from '@node-core/ui-components/Common/BadgeGroup';
4+
import Blockquote from '@node-core/ui-components/Common/Blockquote';
5+
import MDXCodeTabs from '@node-core/ui-components/MDX/CodeTabs';
6+
7+
import Button from '#site/components/Common/Button';
8+
import LinkWithArrow from '#site/components/Common/LinkWithArrow';
9+
import DownloadButton from '#site/components/Downloads/DownloadButton';
10+
import DownloadsTable from '#site/components/Downloads/DownloadsTable';
11+
import BlogPostLink from '#site/components/Downloads/Release/BlogPostLink';
12+
import ChangelogLink from '#site/components/Downloads/Release/ChangelogLink';
13+
import ReleaseDownloadLink from '#site/components/Downloads/Release/DownloadLink';
14+
import ReleaseInstallationMethodDropdown from '#site/components/Downloads/Release/InstallationMethodDropdown';
15+
import ReleaseOperatingSystemDropdown from '#site/components/Downloads/Release/OperatingSystemDropdown';
16+
import ReleasePackageManagerDropdown from '#site/components/Downloads/Release/PackageManagerDropdown';
17+
import ReleasePlatformDropdown from '#site/components/Downloads/Release/PlatformDropdown';
18+
import ReleasePrebuiltDownloadButtons from '#site/components/Downloads/Release/PrebuiltDownloadButtons';
19+
import ReleaseCodeBox from '#site/components/Downloads/Release/ReleaseCodeBox';
20+
import ReleaseVersionDropdown from '#site/components/Downloads/Release/VersionDropdown';
21+
import EOLAlertBox from '#site/components/EOL/EOLAlert';
22+
import EOLReleaseTable from '#site/components/EOL/EOLReleaseTable';
23+
import Link from '#site/components/Link';
24+
import UpcomingMeetings from '#site/components/MDX/Calendar/UpcomingMeetings';
25+
import MDXCodeBox from '#site/components/MDX/CodeBox';
26+
import MDXImage from '#site/components/MDX/Image';
27+
import MinorReleasesTable from '#site/components/Releases/MinorReleasesTable';
28+
import PreviousReleasesTable from '#site/components/Releases/PreviousReleasesTable';
29+
import ReleaseOverview from '#site/components/Releases/ReleaseOverview';
30+
import WithBadgeGroup from '#site/components/withBadgeGroup';
31+
import WithBanner from '#site/components/withBanner';
32+
import WithDownloadArchive from '#site/components/withDownloadArchive';
33+
import WithNodeRelease from '#site/components/withNodeRelease';
34+
import WithReleaseAlertBox from '#site/components/withReleaseAlertBox';
35+
import WithReleaseSelect from '#site/components/withReleaseSelect';
36+
import { ReleaseProvider } from '#site/providers/releaseProvider';
37+
38+
/**
39+
* A full list of React Components that we want to pass through to MDX
40+
*
41+
* @satisfies {import('mdx/types').MDXComponents}
42+
*/
43+
export default {
44+
// HTML overrides
45+
a: Link,
46+
blockquote: Blockquote,
47+
pre: MDXCodeBox,
48+
img: MDXImage,
49+
// Renders MDX CodeTabs
50+
CodeTabs: MDXCodeTabs,
51+
// Renders a Download Button
52+
DownloadButton,
53+
// Renders a stateless Release Select Component
54+
WithReleaseSelect,
55+
// Group of components that enable you to select versions for Node.js
56+
// releases and download selected versions. Uses `releaseProvider` as a provider
57+
Release: {
58+
Provider: ReleaseProvider,
59+
VersionDropdown: ReleaseVersionDropdown,
60+
InstallationMethodDropdown: ReleaseInstallationMethodDropdown,
61+
PackageManagerDropdown: ReleasePackageManagerDropdown,
62+
PlatformDropdown: ReleasePlatformDropdown,
63+
OperatingSystemDropdown: ReleaseOperatingSystemDropdown,
64+
BlogPostLink,
65+
PrebuiltDownloadButtons: ReleasePrebuiltDownloadButtons,
66+
ReleaseCodeBox,
67+
ChangelogLink,
68+
DownloadLink: ReleaseDownloadLink,
69+
},
70+
// HOC for providing the Download Archive Page properties
71+
WithDownloadArchive,
72+
DownloadsTable,
73+
PreviousReleasesTable,
74+
WithNodeRelease,
75+
WithReleaseAlertBox,
76+
WithBanner,
77+
WithBadgeGroup,
78+
BadgeGroup,
79+
ReleaseOverview,
80+
MinorReleasesTable,
81+
UpcomingMeetings,
82+
EOLAlertBox,
83+
EOLReleaseTable,
84+
Button,
85+
Link,
86+
LinkWithArrow,
87+
};

apps/site/next.mdx.plugins.mjs renamed to apps/site/mdx/plugins.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import rehypeSlug from 'rehype-slug';
77
import remarkGfm from 'remark-gfm';
88
import readingTime from 'remark-reading-time';
99

10-
import remarkTableTitles from './util/table';
10+
import remarkTableTitles from '../util/table';
1111

1212
/**
1313
* Provides all our Rehype Plugins that are used within MDX
1414
*/
15-
export const REHYPE_PLUGINS = [
15+
export const rehypePlugins = [
1616
// Generates `id` attributes for headings (H1, ...)
1717
rehypeSlug,
1818
// Automatically add anchor links to headings (H1, ...)
@@ -25,7 +25,7 @@ export const REHYPE_PLUGINS = [
2525
/**
2626
* Provides all our Remark Plugins that are used within MDX
2727
*/
28-
export const REMARK_PLUGINS = [
28+
export const remarkPlugins = [
2929
// Support GFM syntax to be used within Markdown
3030
remarkGfm,
3131
// Generates metadata regarding headings

apps/site/next.dynamic.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import matter from 'gray-matter';
77
import { cache } from 'react';
88
import { VFile } from 'vfile';
99

10+
import compile from './mdx/compiler.mjs';
11+
import mdxComponents from './mdx/components.mjs';
1012
import { BASE_PATH } from './next.constants.mjs';
1113
import { BASE_URL } from './next.constants.mjs';
1214
import { DEFAULT_CATEGORY_OG_TYPE } from './next.constants.mjs';
@@ -16,8 +18,6 @@ import { PAGE_METADATA } from './next.dynamic.constants.mjs';
1618
import { getMarkdownFiles } from './next.helpers.mjs';
1719
import { siteConfig } from './next.json.mjs';
1820
import { availableLocaleCodes, defaultLocale } from './next.locales.mjs';
19-
import { compile } from './next.mdx.compiler.mjs';
20-
import { MDX_COMPONENTS } from './next.mdx.components.mjs';
2121

2222
// This is the combination of the Application Base URL and Base PATH
2323
const baseUrlAndPath = `${BASE_URL}${BASE_PATH}`;
@@ -177,7 +177,7 @@ const getDynamicRouter = async () => {
177177

178178
// This compiles our MDX source (VFile) into a final MDX-parsed VFile
179179
// that then is passed as a string to the MDXProvider which will run the MDX Code
180-
return compile(sourceAsVirtualFile, fileExtension, MDX_COMPONENTS);
180+
return compile(sourceAsVirtualFile, fileExtension, mdxComponents);
181181
};
182182

183183
// Creates a Cached Version of the MDX Compiler

apps/site/next.jsx.compiler.mjs

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

apps/site/next.mdx.components.mjs

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

apps/site/next.mdx.use.client.mjs

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

apps/site/next.mdx.use.mjs

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

0 commit comments

Comments
 (0)