Skip to content

Commit 199c3e6

Browse files
committed
refactor: renamed to download archive
1 parent c7264ea commit 199c3e6

File tree

11 files changed

+51
-39
lines changed

11 files changed

+51
-39
lines changed

apps/site/components/Downloads/DownloadsTable/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { FC } from 'react';
55

66
import Link from '#site/components/Link';
77
import { OperatingSystemLabel } from '#site/util/downloadUtils';
8-
import type { NodeDownloadArtifact } from '#site/util/downloadUtils/simple';
8+
import type { NodeDownloadArtifact } from '#site/util/downloadUtils/archive';
99

1010
type DownloadsTableProps = {
1111
source: Array<NodeDownloadArtifact>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const ReleaseCodeBox: FC = () => {
106106
>
107107
{t.rich('layouts.download.codeBox.noScriptDetected', {
108108
link: text => (
109-
<Link href="/download/simplified">
109+
<Link href="/download/archive">
110110
<b>{text}</b>
111111
</Link>
112112
),

apps/site/components/withSimplifiedDownload.tsx renamed to apps/site/components/withDownloadArchive.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,32 @@ import getReleaseData from '#site/next-data/releaseData';
55
import {
66
buildReleaseArtifacts,
77
extractVersionFromPath,
8-
} from '#site/util/downloadUtils/simple';
8+
findReleaseByVersion,
9+
} from '#site/util/downloadUtils/archive';
910

10-
type SimplifiedDownload = ReturnType<typeof buildReleaseArtifacts>;
11+
type DownloadArchive = ReturnType<typeof buildReleaseArtifacts>;
1112

12-
type WithSimplifiedDownloadProps = {
13-
children: FC<SimplifiedDownload>;
13+
type WithDownloadArchiveProps = {
14+
children: FC<DownloadArchive>;
1415
};
1516

1617
/**
1718
* Provides download artifacts and sidebar items to its child component
1819
*/
19-
const WithSimplifiedDownload: FC<WithSimplifiedDownloadProps> = async ({
20+
const WithDownloadArchive: FC<WithDownloadArchiveProps> = async ({
2021
children: Component,
2122
}) => {
2223
const { pathname } = getClientContext();
2324
const releaseData = await getReleaseData();
2425

2526
// Extract version from pathname
26-
const { version, major } = extractVersionFromPath(pathname) || {};
27+
const version = extractVersionFromPath(pathname);
2728

2829
if (!version) {
2930
return null;
3031
}
3132

32-
// Find the matching release
33-
const release = releaseData.find(
34-
release =>
35-
release.major === major ||
36-
(release.isLts === true && version === 'simplified')
37-
);
33+
const release = findReleaseByVersion(releaseData, version);
3834

3935
if (!release) {
4036
return null;
@@ -50,4 +46,4 @@ const WithSimplifiedDownload: FC<WithSimplifiedDownloadProps> = async ({
5046
return <Component {...releaseArtifacts} />;
5147
};
5248

53-
export default WithSimplifiedDownload;
49+
export default WithDownloadArchive;

apps/site/components/withLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ArticlePageLayout from '#site/layouts/ArticlePage';
55
import BlogLayout from '#site/layouts/Blog';
66
import DefaultLayout from '#site/layouts/Default';
77
import DownloadLayout from '#site/layouts/Download';
8-
import DownloadSimpleLayout from '#site/layouts/DownloadSimple';
8+
import DownloadArchiveLayout from '#site/layouts/DownloadArchive';
99
import GlowingBackdropLayout from '#site/layouts/GlowingBackdrop';
1010
import LearnLayout from '#site/layouts/Learn';
1111
import PostLayout from '#site/layouts/Post';
@@ -19,7 +19,7 @@ const layouts = {
1919
'blog-post': PostLayout,
2020
'blog-category': BlogLayout,
2121
download: DownloadLayout,
22-
'download-simple': DownloadSimpleLayout,
22+
'download-archive': DownloadArchiveLayout,
2323
article: ArticlePageLayout,
2424
} satisfies Record<Layouts, FC>;
2525

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import WithNavBar from '#site/components/withNavBar';
66

77
import styles from './layouts.module.css';
88

9-
const DownloadSimpleLayout: FC = () => (
9+
const DownloadArchiveLayout: FC = () => (
1010
<>
1111
<WithNavBar />
1212

1313
<div className={styles.downloadLayout}>
1414
<main>
15-
<WithMarkdownContent file={['download', 'simplified']} />
15+
<WithMarkdownContent file={['download', 'archive']} />
1616
</main>
1717
</div>
1818

1919
<WithFooter />
2020
</>
2121
);
2222

23-
export default DownloadSimpleLayout;
23+
export default DownloadArchiveLayout;

apps/site/next.dynamic.constants.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export const IGNORED_ROUTES = [
2020
locale !== defaultLocale.code && /^blog/.test(pathname),
2121
// This is used to ignore all pathnames that are empty
2222
({ locale, pathname }) => locale.length && !pathname.length,
23-
// This is used to ignore download routes for major versions and simplified download page
24-
({ pathname }) => /^download\/(v\d+(\.\d+)*|simplified)$/.test(pathname),
23+
// This is used to ignore download routes for major versions and downloads archive page
24+
({ pathname }) => /^download\/(v\d+(\.\d+)*|archive)$/.test(pathname),
2525
];
2626

2727
/**
@@ -32,14 +32,14 @@ export const IGNORED_ROUTES = [
3232
* @type {Map<string, import('./types').Layouts>} A Map of pathname and Layout Name
3333
*/
3434
export const DYNAMIC_ROUTES = new Map([
35-
// Creates dynamic routes for simplified download pages for each version
35+
// Creates dynamic routes for downloads archive pages for each version
3636
// (e.g., /download/v18.20.8, /download/v20.19.2)
3737
...provideReleaseData()
3838
.flatMap(({ minorVersions, versionWithPrefix }) => [
3939
`download/${versionWithPrefix}`,
4040
...minorVersions.map(minor => `download/${minor.versionWithPrefix}`),
4141
])
42-
.map(version => [version, 'download-simple']),
42+
.map(version => [version, 'download-archive']),
4343
// Provides Routes for all Blog Categories
4444
...blogData.categories.map(c => [`blog/${c}`, 'blog-category']),
4545
// Provides Routes for all Blog Categories w/ Pagination

apps/site/next.mdx.use.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ import { ReleaseOverview } from './components/Downloads/ReleaseOverview';
77
import UpcomingMeetings from './components/MDX/Calendar/UpcomingMeetings';
88
import WithBadgeGroup from './components/withBadgeGroup';
99
import WithBanner from './components/withBanner';
10+
import WithDownloadArchive from './components/withDownloadArchive';
1011
import WithNodeRelease from './components/withNodeRelease';
11-
import WithSimplifiedDownload from './components/withSimplifiedDownload';
12+
1213
/**
1314
* A full list of React Components that we want to pass through to MDX
1415
*
1516
* @satisfies {import('mdx/types').MDXComponents}
1617
*/
1718
export const mdxComponents = {
1819
DownloadReleasesTable: DownloadReleasesTable,
19-
// HOC for providing the Simplified Download Page properties
20-
WithSimplifiedDownload: WithSimplifiedDownload,
20+
// HOC for providing the Download Archive Page properties
21+
WithDownloadArchive: WithDownloadArchive,
2122
// Renders a table with Node.js Releases with different platforms and architectures
2223
DownloadsTable: DownloadsTable,
2324
// HOC for getting Node.js Release Metadata

apps/site/pages/en/download/simplified.mdx renamed to apps/site/pages/en/download/archive.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Download Node.js®
3-
layout: download-simple
3+
layout: download-archive
44
---
55

6-
<WithSimplifiedDownload>
6+
<WithDownloadArchive>
77
{({ binaries, installers, version, release, sources, majors }) => (
88
<>
99
<h1>Download Node.js® {version}</h1>
@@ -52,4 +52,4 @@ layout: download-simple
5252
</details>
5353
</>
5454
)}
55-
</WithSimplifiedDownload>
55+
</WithDownloadArchive>

apps/site/types/layouts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export type Layouts =
66
| 'blog-category'
77
| 'blog-post'
88
| 'download'
9-
| 'download-simple'
9+
| 'download-archive'
1010
| 'article';
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,35 @@ export const buildReleaseArtifacts = (
129129
};
130130
};
131131

132+
/**
133+
* Extracts the version from the pathname.
134+
* It expects the version to be in the format 'v22.0.4' or 'archive'.
135+
*/
132136
export const extractVersionFromPath = (pathname: string | undefined) => {
133137
if (!pathname) return null;
134138

135139
const segments = pathname.split('/').filter(Boolean);
136140
const version = segments.pop();
137-
const major = semVer.major(version || '');
138141

139-
// Check version format like (v22.0.4 or 'simplified')
140-
if (
141-
!version ||
142-
(!version.match(/^v\d+(\.\d+)*$/) && version !== 'simplified')
143-
) {
142+
// Check version format like (v22.0.4 or 'archive')
143+
if (!version || (!version.match(/^v\d+(\.\d+)*$/) && version !== 'archive')) {
144144
return null;
145145
}
146146

147-
return { version, major };
147+
return version;
148+
};
149+
150+
/**
151+
* Finds the appropriate release based on version, if 'archive' is passed,
152+
* it returns the latest LTS release.
153+
*/
154+
export const findReleaseByVersion = (
155+
releaseData: Array<NodeRelease>,
156+
version: string | 'archive'
157+
) => {
158+
if (version === 'archive') {
159+
return releaseData.find(release => release.status === 'LTS');
160+
}
161+
162+
return releaseData.find(release => semVer.major(version) === release.major);
148163
};

0 commit comments

Comments
 (0)