Skip to content

Commit 311063d

Browse files
committed
refactor: nodevuData generator added
1 parent 656bd98 commit 311063d

5 files changed

Lines changed: 46 additions & 73 deletions

File tree

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

Lines changed: 29 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ import {
1717
ENABLE_STATIC_EXPORT_LOCALE,
1818
ENABLE_STATIC_EXPORT,
1919
} from '#site/next.constants.mjs';
20-
import {
21-
PAGE_VIEWPORT,
22-
DYNAMIC_ROUTES,
23-
DYNAMIC_MARKDOWN_ROUTES,
24-
} from '#site/next.dynamic.constants.mjs';
20+
import { PAGE_VIEWPORT } from '#site/next.dynamic.constants.mjs';
2521
import { dynamicRouter } from '#site/next.dynamic.mjs';
2622
import { allLocaleCodes, availableLocaleCodes } from '#site/next.locales.mjs';
2723
import { defaultLocale } from '#site/next.locales.mjs';
@@ -96,33 +92,6 @@ const getPage: FC<DynamicParams> = async props => {
9692
// Gets the current full pathname for a given path
9793
const pathname = dynamicRouter.getPathname(path);
9894

99-
const staticGeneratedLayout = DYNAMIC_ROUTES.get(pathname);
100-
101-
// If the current pathname corresponds to a statically generated route but does
102-
// not have a dynamic Markdown file, it means there is no Markdown file on the
103-
// filesystem for it. However, it is still a valid route with an assigned layout
104-
// that should be rendered.
105-
if (
106-
staticGeneratedLayout !== undefined &&
107-
!DYNAMIC_MARKDOWN_ROUTES.has(staticGeneratedLayout)
108-
) {
109-
// Metadata and shared Context to be available through the lifecycle of the page
110-
const sharedContext = { pathname: `/${pathname}` };
111-
112-
// Defines a shared Server Context for the Client-Side
113-
// That is shared for all pages under the dynamic router
114-
setClientContext(sharedContext);
115-
116-
// The Matter Provider allows Client-Side injection of the data
117-
// to a shared React Client Provider even though the page is rendered
118-
// within a server-side context
119-
return (
120-
<MatterProvider {...sharedContext}>
121-
<WithLayout layout={staticGeneratedLayout} />
122-
</MatterProvider>
123-
);
124-
}
125-
12695
// We retrieve the source of the Markdown file by doing an educated guess
12796
// of what possible files could be the source of the page, since the extension
12897
// context is lost from `getStaticProps` as a limitation of Next.js itself
@@ -131,36 +100,36 @@ const getPage: FC<DynamicParams> = async props => {
131100
pathname
132101
);
133102

134-
if (source.length && filename.length) {
135-
// This parses the source Markdown content and returns a React Component and
136-
// relevant context from the Markdown File
137-
const { content, frontmatter, headings, readingTime } =
138-
await dynamicRouter.getMDXContent(source, filename);
139-
140-
// Metadata and shared Context to be available through the lifecycle of the page
141-
const sharedContext = {
142-
frontmatter: frontmatter,
143-
headings: headings,
144-
pathname: `/${pathname}`,
145-
readingTime: readingTime,
146-
filename: filename,
147-
};
148-
149-
// Defines a shared Server Context for the Client-Side
150-
// That is shared for all pages under the dynamic router
151-
setClientContext(sharedContext);
152-
153-
// The Matter Provider allows Client-Side injection of the data
154-
// to a shared React Client Provider even though the page is rendered
155-
// within a server-side context
156-
return (
157-
<MatterProvider {...sharedContext}>
158-
<WithLayout layout={frontmatter.layout}>{content}</WithLayout>
159-
</MatterProvider>
160-
);
103+
if (source === '' && filename === '') {
104+
return notFound();
161105
}
162106

163-
return notFound();
107+
// This parses the source Markdown content and returns a React Component and
108+
// relevant context from the Markdown File
109+
const { content, frontmatter, headings, readingTime } =
110+
await dynamicRouter.getMDXContent(source, filename);
111+
112+
// Metadata and shared Context to be available through the lifecycle of the page
113+
const sharedContext = {
114+
frontmatter: frontmatter,
115+
headings: headings,
116+
pathname: `/${pathname}`,
117+
readingTime: readingTime,
118+
filename: filename,
119+
};
120+
121+
// Defines a shared Server Context for the Client-Side
122+
// That is shared for all pages under the dynamic router
123+
setClientContext(sharedContext);
124+
125+
// The Matter Provider allows Client-Side injection of the data
126+
// to a shared React Client Provider even though the page is rendered
127+
// within a server-side context
128+
return (
129+
<MatterProvider {...sharedContext}>
130+
<WithLayout layout={frontmatter.layout}>{content}</WithLayout>
131+
</MatterProvider>
132+
);
164133
};
165134

166135
// Enforces that this route is used as static rendering
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
import nodevu from '@nodevu/core';
4+
5+
/**
6+
* This file is used to fetch Node.js release data from Nodevu.
7+
* It uses the `nodevu` package to fetch the data and export it for use in
8+
* other parts of the site.
9+
*/
10+
export default nodevu({ fetch });

apps/site/next-data/generators/releaseData.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import nodevu from '@nodevu/core';
3+
import nodevuData from './nodevuData.mjs';
44

55
// Gets the appropriate release status for each major release
66
const getNodeReleaseStatus = (now, support) => {
@@ -32,9 +32,7 @@ const getNodeReleaseStatus = (now, support) => {
3232
* @returns {Promise<Array<import('../../types').NodeRelease>>}
3333
*/
3434
const generateReleaseData = async () => {
35-
const nodevuOutput = await nodevu({ fetch });
36-
37-
const majors = Object.entries(nodevuOutput).filter(
35+
const majors = Object.entries(await nodevuData).filter(
3836
([version, { support }]) => {
3937
// Filter out those without documented support
4038
// Basically those not in schedule.json

apps/site/next-data/generators/releaseVersions.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import nodevu from '@nodevu/core';
3+
import nodevuData from './nodevuData.mjs';
44

55
/**
66
* This method is used to generate all Node.js versions
@@ -9,9 +9,7 @@ import nodevu from '@nodevu/core';
99
* @returns {Promise<Array<string>>}
1010
*/
1111
const generateAllVersionsData = async () => {
12-
const nodevuOutput = await nodevu({ fetch });
13-
14-
const majors = Object.entries(nodevuOutput).filter(
12+
const majors = Object.entries(await nodevuData).filter(
1513
([version, { support }]) => {
1614
// Filter out those without documented support
1715
// Basically those not in schedule.json

apps/site/util/download/archive.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,22 @@ const getCompatibleArtifacts = ({
5858
return Object.entries(platforms).flatMap(([os, items]) => {
5959
if (exclude.includes(os)) return [];
6060

61-
const operatingSystem = os as OperatingSystem;
62-
6361
return items
6462
.filter(({ compatibility, value }) =>
65-
isCompatible(compatibility, operatingSystem, value, version)
63+
isCompatible(compatibility, os as OperatingSystem, value, version)
6664
)
6765
.map(({ value, label }) => {
6866
const url = getNodeDownloadUrl({
6967
version: version,
70-
os: operatingSystem,
68+
os: os as OperatingSystem,
7169
platform: value,
7270
kind: kind,
7371
});
7472

7573
return {
7674
file: url.replace(`${DIST_URL}${version}/`, ''),
7775
kind: kind,
78-
os: operatingSystem,
76+
os: os as OperatingSystem,
7977
architecture: label,
8078
url: url,
8179
version: version,

0 commit comments

Comments
 (0)