Skip to content

Commit e64f5af

Browse files
committed
feat(mdx): move to dedicated package, switch to @next/mdx
1 parent 587fe94 commit e64f5af

File tree

1,280 files changed

+802
-1429
lines changed

Some content is hidden

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

1,280 files changed

+802
-1429
lines changed

.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
orama:
5957
patterns:

.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
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: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-nocheck
3+
// TODO(@AVIVKELLER): THIS FILE
14
import { defaultLocale } from '@node-core/website-i18n';
25
import { notFound, redirect } from 'next/navigation';
36

47
import provideReleaseData from '#site/next-data/providers/releaseData';
58
import provideReleaseVersions from '#site/next-data/providers/releaseVersions';
69
import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs';
7-
import * as basePage from '#site/next.dynamic.page.mjs';
810

911
import type { DynamicParams } from '#site/types';
1012
import type { FC } from 'react';
1113

1214
type PageParams = DynamicParams<{ version: string }>;
1315

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-
2216
// Generates all possible static paths based on the locales and environment configuration
2317
// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)
2418
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales
@@ -91,3 +85,4 @@ export const dynamic = 'force-static';
9185
export const revalidate = 300;
9286

9387
export default getPage;
88+
export * from '#site/router/page';

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

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
import { defaultLocale, availableLocaleCodes } from '@node-core/website-i18n';
2-
import { notFound } from 'next/navigation';
3-
4-
import { ENABLE_STATIC_EXPORT } from '#site/next.constants.mjs';
5-
import { ENABLE_STATIC_EXPORT_LOCALE } from '#site/next.constants.mjs';
6-
import * as basePage from '#site/next.dynamic.page.mjs';
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+
*/
79

8-
import type { DynamicParams } from '#site/types';
9-
import type { FC } from 'react';
10+
import { sep } from 'node:path';
1011

11-
type PageParams = DynamicParams<{ path: Array<string> }>;
12+
import { availableLocaleCodes, defaultLocale } from '@node-core/website-i18n';
13+
import { notFound } from 'next/navigation';
1214

13-
// This is the default Viewport Metadata
14-
// @see https://nextjs.org/docs/app/api-reference/functions/generate-viewport#generateviewport-function
15-
export const generateViewport = basePage.generateViewport;
15+
import {
16+
ENABLE_STATIC_EXPORT,
17+
ENABLE_STATIC_EXPORT_LOCALE,
18+
} from '#site/next.constants.mjs';
19+
import { allRoutes, getMarkdownFile } from '#site/router';
20+
import { renderPage } from '#site/router/render';
21+
import { joinNested } from '#site/util/array';
1622

17-
// This generates each page's HTML Metadata
18-
// @see https://nextjs.org/docs/app/api-reference/functions/generate-metadata
19-
export const generateMetadata = basePage.generateMetadata;
23+
import type { PageParams } from '#site/router/page';
24+
import type { FC } from 'react';
2025

21-
/**
22-
* Generates all possible static paths based on the locales and environment configuration
23-
* - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)
24-
* - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales
25-
* - Otherwise, generates paths only for the default locale
26-
*
27-
* @see https://nextjs.org/docs/app/api-reference/functions/generate-static-params
28-
*/
26+
// Generates all possible static paths based on the locales and environment configuration
27+
// - Returns an empty array if static export is disabled (`ENABLE_STATIC_EXPORT` is false)
28+
// - If `ENABLE_STATIC_EXPORT_LOCALE` is true, generates paths for all available locales
29+
// - Otherwise, generates paths only for the default locale
30+
// @see https://nextjs.org/docs/app/api-reference/functions/generate-static-params
2931
export const generateStaticParams = async () => {
3032
// Return an empty array if static export is disabled
3133
if (!ENABLE_STATIC_EXPORT) {
@@ -37,40 +39,24 @@ export const generateStaticParams = async () => {
3739
? availableLocaleCodes
3840
: [defaultLocale.code];
3941

40-
const routes = await Promise.all(
41-
// Gets all mapped routes to the Next.js Routing Engine by Locale
42-
locales.map(locale => ({ locale }))
42+
return locales.map((locale: string) =>
43+
allRoutes.map(path => ({
44+
locale,
45+
path: path.split(sep),
46+
}))
4347
);
44-
45-
return routes.flat().sort();
4648
};
4749

4850
// This method parses the current pathname and does any sort of modifications needed on the route
4951
// then it proceeds to retrieve the Markdown file and parse the MDX Content into a React Component
5052
// finally it returns (if the locale and route are valid) the React Component with the relevant context
5153
// and attached context providers for rendering the current page
5254
const getPage: FC<PageParams> = async props => {
53-
const { path, locale: routeLocale } = await props.params;
55+
const { path = [], locale } = await props.params;
5456

55-
// Gets the current full pathname for a given path
56-
const [locale, pathname] = basePage.getLocaleAndPath(path, routeLocale);
57-
58-
// Gets the Markdown content and context
59-
const [content, context] = await basePage.getMarkdownContext({
60-
locale,
61-
pathname,
62-
});
63-
64-
// If we have a filename and layout then we have a page
65-
if (context.filename && context.frontmatter.layout) {
66-
return basePage.renderPage({
67-
content,
68-
layout: context.frontmatter.layout,
69-
context,
70-
});
71-
}
57+
const markdown = await getMarkdownFile(locale, joinNested(path));
7258

73-
return notFound();
59+
return markdown ? renderPage(markdown) : notFound();
7460
};
7561

7662
// Enforces that this route is used as static rendering
@@ -84,3 +70,4 @@ export const dynamic = 'force-static';
8470
export const revalidate = 300;
8571

8672
export default getPage;
73+
export * from '#site/router/page';

apps/site/app/sitemap.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { availableLocaleCodes, defaultLocale } from '@node-core/website-i18n';
33
import { BASE_PATH } from '#site/next.constants.mjs';
44
import { BASE_URL } from '#site/next.constants.mjs';
55
import { EXTERNAL_LINKS_SITEMAP } from '#site/next.constants.mjs';
6-
import { BLOG_DYNAMIC_ROUTES } from '#site/next.dynamic.constants.mjs';
7-
import { dynamicRouter } from '#site/next.dynamic.mjs';
6+
import { BLOG_DYNAMIC_ROUTES } from '#site/router/constants';
87

98
import type { MetadataRoute } from 'next';
109

10+
import { allRoutes } from '../router';
11+
1112
// This is the combination of the Application Base URL and Base PATH
1213
const baseUrlAndPath = `${BASE_URL}${BASE_PATH}`;
1314

@@ -21,9 +22,6 @@ const getAlternatePath = (r: string, locales: Array<string>) =>
2122

2223
// This allows us to generate a `sitemap.xml` file dynamically based on the needs of the Node.js Website
2324
const sitemap = async (): Promise<MetadataRoute.Sitemap> => {
24-
// Gets a list of all statically available routes
25-
const routes = await dynamicRouter.getAllRoutes();
26-
2725
const currentDate = new Date().toISOString();
2826

2927
const getSitemapEntry = (r: string, locales: Array<string> = []) => ({
@@ -33,7 +31,7 @@ const sitemap = async (): Promise<MetadataRoute.Sitemap> => {
3331
alternates: { languages: getAlternatePath(r, locales) },
3432
});
3533

36-
const staticPaths = routes.map(r => getSitemapEntry(r, nonDefaultLocales));
34+
const staticPaths = allRoutes.map(r => getSitemapEntry(r, nonDefaultLocales));
3735
const blogPaths = BLOG_DYNAMIC_ROUTES.map(r => getSitemapEntry(`blog/${r}`));
3836
const externalPaths = EXTERNAL_LINKS_SITEMAP.map(r => getSitemapEntry(r));
3937

0 commit comments

Comments
 (0)