Skip to content

Commit d3d2bd4

Browse files
committed
feat(mdx): switch to @next/mdx
1 parent bbbe264 commit d3d2bd4

Some content is hidden

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

54 files changed

+859
-1626
lines changed

.github/CODEOWNERS

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,17 @@ docs @nodejs/nodejs-website @nodejs/web-infra
3838
SECURITY.md @nodejs/security-wg
3939

4040
# Node.js Release Blog Posts
41-
apps/site/pages/en/blog/release @nodejs/releasers
42-
apps/site/pages/en/blog/announcements @nodejs/releasers
41+
packages/content/src/en/blog/release @nodejs/releasers
42+
packages/content/src/en/blog/announcements @nodejs/releasers
4343

4444
# The following users DO NOT have write access, and their review is requested
4545
# via a GitHub action.
46-
apps/site/pages/en/learn/diagnostics @nodejs/diagnostics
47-
48-
apps/site/pages/en/learn/getting-started/security-best-practices.md @nodejs/security-wg
49-
50-
apps/site/pages/en/learn/manipulating-files @nodejs/fs
51-
52-
apps/site/pages/en/learn/test-runner @nodejs/test_runner
53-
54-
apps/site/pages/en/learn/typescript @nodejs/typescript
55-
56-
apps/site/pages/en/about/partners.mdx @nodejs/marketing
57-
apps/site/pages/en/about/branding.mdx @nodejs/marketing
58-
59-
apps/site/pages/en/learn/getting-started/userland-migrations.md @nodejs/userland-migrations
60-
apps/site/pages/en/blog/migrations @nodejs/userland-migrations
46+
packages/content/src/en/learn/diagnostics @nodejs/diagnostics
47+
packages/content/src/en/learn/getting-started/security-best-practices.md @nodejs/security-wg
48+
packages/content/src/en/learn/manipulating-files @nodejs/fs
49+
packages/content/src/en/learn/test-runner @nodejs/test_runner
50+
packages/content/src/en/learn/typescript @nodejs/typescript
51+
packages/content/src/en/about/partners.mdx @nodejs/marketing
52+
packages/content/src/en/about/branding.mdx @nodejs/marketing
53+
packages/content/src/en/learn/getting-started/userland-migrations.md @nodejs/userland-migrations
54+
packages/content/src/en/blog/migrations @nodejs/userland-migrations

.github/dependabot.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ updates:
5252
- shiki
5353
- sval
5454
- unist-util-*
55-
- vfile
56-
- vfile-*
5755
- reading-time
5856
- twoslash
5957
orama:

.github/workflows/publish-packages.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ jobs:
7979
PKG_NAME=$(basename "$pkg")
8080
PKG_JSON="$pkg/package.json"
8181
82+
IS_PRIVATE=$(jq -r '.private // false' "$PKG_JSON")
83+
if [ "$IS_PRIVATE" = "true" ]; then
84+
echo "⏭️ Skipping private package: $PKG_NAME"
85+
continue
86+
fi
87+
8288
# Determine if the package has changed (or include all on manual trigger)
8389
if [ "$EVENT_NAME" == "workflow_dispatch" ] || ! git diff --quiet $COMMIT_SHA~1 $COMMIT_SHA -- "$pkg/"; then
8490
OLD_VERSION=$(git show $COMMIT_SHA~1:$PKG_JSON | jq -r '.version')
@@ -113,6 +119,12 @@ jobs:
113119
- name: Publish
114120
working-directory: packages/${{ matrix.package }}
115121
run: |
122+
# Fail-safe
123+
if jq -e '.private == true' package.json > /dev/null; then
124+
echo "❌ Refusing to publish private package"
125+
exit 0
126+
fi
127+
116128
# Check if a custom publish script exists in package.json
117129
if jq -e '.scripts.release' package.json > /dev/null; then
118130
pnpm run release

.github/workflows/translations-pr-lint.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ on:
99
branches:
1010
- main
1111
paths:
12-
- 'apps/site/pages/**/*.md'
13-
- 'apps/site/pages/**/*.mdx'
14-
- '!apps/site/pages/en/**/*.md'
15-
- '!apps/site/pages/en/**/*.mdx'
12+
- 'packages/content/src/**/*.md'
13+
- 'packages/content/src/**/*.mdx'
14+
- '!packages/content/src/en/**/*.md'
15+
- '!packages/content/src/en/**/*.mdx'
1616
- 'packages/i18n/src/locales/*.json'
1717
- '!packages/i18n/src/locales/en.json'
1818
- 'apps/site/snippets/**/*.bash'

.github/workflows/translations-sync.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,16 @@ jobs:
7777
uses: actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
7878
with:
7979
path: |
80-
apps/site/.eslintmdcache
81-
apps/site/.prettiercache
80+
.turbo/cache
81+
.eslintmdcache
82+
.stylelintcache
83+
.prettiercache
8284
# We want to restore Turborepo Cache and ESlint and Prettier Cache
8385
# The ESLint and Prettier cache's are useful to reduce the overall runtime of ESLint and Prettier
8486
# as they will only run on files that have changed since the last cached run
8587
# this might of course lead to certain files not being checked against the linter, but the chances
8688
# of such situation from happening are very slim as the checksums of both files would need to match
87-
key: cache-lint-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('apps/site/.eslintmdcache') }}
89+
key: cache-lint-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('.turbo/cache/**') }}
8890
restore-keys: |
8991
cache-lint-${{ hashFiles('pnpm-lock.yaml') }}-
9092
cache-lint-
@@ -98,8 +100,8 @@ jobs:
98100
fi
99101
100102
- name: Run ESLint
101-
working-directory: apps/site
102-
run: node --run lint:md -- --fix
103+
working-directory: packages/content
104+
run: node --run lint:fix
103105

104106
- name: Run Prettier
105107
run: node --run prettier:fix
Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,2 @@
1-
/**
2-
* This file extends on the `page.tsx` file, which is the default file that is used to render
3-
* the entry points for each locale and then also reused within the [...path] route to render the
4-
* and contains all logic for rendering our dynamic and static routes within the Node.js Website.
5-
*
6-
* Note: that each `page.tsx` should have its own `generateStaticParams` to prevent clash of
7-
* dynamic params, which will lead on static export errors and other sort of issues.
8-
*/
9-
10-
import { availableLocaleCodes, defaultLocale } from '@node-core/website-i18n';
11-
import { notFound } from 'next/navigation';
12-
13-
import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs';
14-
import { ENABLE_STATIC_EXPORT_LOCALE } from '#site/next.constants.mjs';
15-
import { dynamicRouter } from '#site/next.dynamic.mjs';
16-
import * as basePage from '#site/next.dynamic.page.mjs';
17-
18-
import type { DynamicParams } from '#site/types';
19-
import type { FC } from 'react';
20-
21-
type PageParams = DynamicParams<{ path: Array<string> }>;
22-
23-
// This is the default Viewport Metadata
24-
// @see https://nextjs.org/docs/app/api-reference/functions/generate-viewport#generateviewport-function
25-
export const generateViewport = basePage.generateViewport;
26-
27-
// This generates each page's HTML Metadata
28-
// @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata
29-
export const generateMetadata = basePage.generateMetadata;
30-
31-
// Generates all possible static paths based on the locales and environment configuration
32-
// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)
33-
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales
34-
// - Otherwise, generates paths only for the default locale
35-
// @see https://nextjs.org/docs/app/api-reference/functions/generate-static-params
36-
export const generateStaticParams = async () => {
37-
// Return an empty array if static export is disabled
38-
if (!ENABLE_STATIC_EXPORT) {
39-
return [];
40-
}
41-
42-
const routes = await dynamicRouter.getAllRoutes();
43-
44-
// Helper function to fetch and map routes for a specific locale
45-
const getRoutesForLocale = async (l: string) =>
46-
routes.map(pathname => dynamicRouter.mapPathToRoute(l, pathname));
47-
48-
// Determine which locales to include in the static export
49-
const locales = ENABLE_STATIC_EXPORT_LOCALE
50-
? availableLocaleCodes
51-
: [defaultLocale.code];
52-
53-
// Generates all possible routes for all available locales
54-
const routesWithLocales = await Promise.all(locales.map(getRoutesForLocale));
55-
56-
return routesWithLocales.flat().sort();
57-
};
58-
59-
// This method parses the current pathname and does any sort of modifications needed on the route
60-
// then it proceeds to retrieve the Markdown file and parse the MDX Content into a React Component
61-
// finally it returns (if the locale and route are valid) the React Component with the relevant context
62-
// and attached context providers for rendering the current page
63-
const getPage: FC<PageParams> = async props => {
64-
const { path, locale: routeLocale } = await props.params;
65-
66-
// Gets the current full pathname for a given path
67-
const [locale, pathname] = basePage.getLocaleAndPath(path, routeLocale);
68-
69-
// Gets the Markdown content and context
70-
const [content, context] = await basePage.getMarkdownContext({
71-
locale,
72-
pathname,
73-
});
74-
75-
// If we have a filename and layout then we have a page
76-
if (context.filename && context.frontmatter.layout) {
77-
return basePage.renderPage({
78-
content,
79-
layout: context.frontmatter.layout,
80-
context,
81-
});
82-
}
83-
84-
return notFound();
85-
};
86-
87-
// Enforces that this route is used as static rendering
88-
// Except whenever on the Development mode as we want instant-refresh when making changes
89-
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
90-
export const dynamic = 'force-static';
91-
92-
// Ensures that this endpoint is invalidated and re-executed every X minutes
93-
// so that when new deployments happen, the data is refreshed
94-
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate
95-
export const revalidate = 300;
96-
97-
export default getPage;
1+
export * from '../page';
2+
export { default } from '../page';

apps/site/app/[locale]/blog/[...path]/page.tsx

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

apps/site/app/[locale]/download/archive/[version]/page.tsx

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@ import { notFound, redirect } from 'next/navigation';
44
import provideReleaseData from '#site/next-data/providers/releaseData';
55
import provideReleaseVersions from '#site/next-data/providers/releaseVersions';
66
import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs';
7-
import * as basePage from '#site/next.dynamic.page.mjs';
7+
import { getMarkdownFile } from '#site/router';
8+
import { renderPage } from '#site/router/render';
89

910
import type { DynamicParams } from '#site/types';
1011
import type { FC } from 'react';
1112

1213
type PageParams = DynamicParams<{ version: string }>;
1314

14-
// This is the default Viewport Metadata
15-
// @see https://nextjs.org/docs/app/api-reference/functions/generate-viewport#generateviewport-function
16-
export const generateViewport = basePage.generateViewport;
17-
18-
// This generates each page's HTML Metadata
19-
// @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata
20-
export const generateMetadata = basePage.generateMetadata;
21-
2215
// Generates all possible static paths based on the locales and environment configuration
2316
// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)
2417
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales
@@ -43,10 +36,7 @@ export const generateStaticParams = async () => {
4336
// finally it returns (if the locale and route are valid) the React Component with the relevant context
4437
// and attached context providers for rendering the current page
4538
const getPage: FC<PageParams> = async props => {
46-
const { version, locale: routeLocale } = await props.params;
47-
48-
// Gets the current full pathname for a given path
49-
const [locale, pathname] = basePage.getLocaleAndPath(version, routeLocale);
39+
const { version, locale } = await props.params;
5040

5141
if (version === 'current') {
5242
const releaseData = await provideReleaseData();
@@ -59,35 +49,19 @@ const getPage: FC<PageParams> = async props => {
5949
const versions = await provideReleaseVersions();
6050

6151
// Verifies if the current route is a dynamic route
62-
const isDynamicRoute = versions.some(r => r.includes(pathname));
63-
64-
// Gets the Markdown content and context for Download Archive pages
65-
const [content, context] = await basePage.getMarkdownContext({
66-
locale,
67-
pathname: 'download/archive',
68-
});
52+
const isDynamicRoute = versions.some(r => r.includes(version));
6953

7054
// If this isn't a valid dynamic route for archive version or there's no markdown
7155
// file for this, then we fail as not found as there's nothing we can do.
72-
if (isDynamicRoute && context.filename) {
73-
return basePage.renderPage({
74-
content,
75-
layout: context.frontmatter.layout!,
76-
context: { ...context, pathname: `/download/archive/${pathname}` },
77-
});
56+
if (isDynamicRoute) {
57+
const markdown = (await getMarkdownFile(locale, 'download/archive'))!;
58+
markdown.pathname = `/download/archive/${version}`;
59+
60+
return renderPage(markdown);
7861
}
7962

8063
return notFound();
8164
};
8265

83-
// Enforces that this route is used as static rendering
84-
// Except whenever on the Development mode as we want instant-refresh when making changes
85-
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
86-
export const dynamic = 'force-static';
87-
88-
// Ensures that this endpoint is invalidated and re-executed every X minutes
89-
// so that when new deployments happen, the data is refreshed
90-
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate
91-
export const revalidate = 300;
92-
9366
export default getPage;
67+
export * from '#site/router/page';

apps/site/app/[locale]/feed/[feed]/route.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,4 @@ export const generateStaticParams = async () =>
3535
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams
3636
export const dynamicParams = false;
3737

38-
// Enforces that this route is cached and static as much as possible
39-
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
40-
export const dynamic = 'force-static';
41-
42-
// Ensures that this endpoint is invalidated and re-executed every X minutes
43-
// so that when new deployments happen, the data is refreshed
44-
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate
45-
export const revalidate = 300;
38+
export { dynamic, revalidate } from '#site/router/page';

apps/site/app/[locale]/next-data/og/[category]/[title]/route.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,4 @@ export const generateStaticParams = async () => [
5959
},
6060
];
6161

62-
// Enforces that this route is cached and static as much as possible
63-
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
64-
export const dynamic = 'force-static';
62+
export { dynamic } from '#site/router/page';

0 commit comments

Comments
 (0)