Skip to content

Commit 63a013f

Browse files
authored
refactor: download archive page unnecessary checks (#8134)
* refactor: extra checks removed, changelog added * chore: redirect archive index page * chore: release check added
1 parent c10ebc1 commit 63a013f

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

apps/site/components/withDownloadArchive.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { notFound } from 'next/navigation';
22
import type { FC } from 'react';
3-
import semVer from 'semver';
43

54
import { getClientContext } from '#site/client-context';
65
import provideReleaseData from '#site/next-data/providers/releaseData';
@@ -27,16 +26,17 @@ const WithDownloadArchive: FC<WithDownloadArchiveProps> = async ({
2726
// Extract version from pathname
2827
const version = extractVersionFromPath(pathname);
2928

30-
if (version == null) {
31-
return notFound();
32-
}
33-
3429
// Find the release data for the given version
3530
const releaseData = provideReleaseData();
36-
const release = releaseData.find(
37-
release => semVer.major(version) === release.major
31+
const release = releaseData.find(release =>
32+
// Match major version only (e.g., v22.x.x for release.major v22)
33+
version.startsWith(`v${release.major}`)
3834
)!;
3935

36+
if (!release) {
37+
return notFound();
38+
}
39+
4040
const releaseArtifacts = buildReleaseArtifacts(release, version);
4141

4242
return <Component {...releaseArtifacts} />;

apps/site/pages/en/download/archive/index.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ layout: download-archive
2424
<ReleaseOverview release={release} />
2525

2626
<ul className='flex list-none flex-col gap-2 p-0 text-sm'>
27-
27+
<li>
28+
Read the <LinkWithArrow href={`https://github.com/nodejs/node/releases/tag/${version}`}>changelog</LinkWithArrow> or <Link href={`/blog/release/${version}`}>blog post</Link> for this version.
29+
</li>
2830
<li>
2931
Learn more about <Link href="/about/previous-releases">Node.js releases</Link>, including the release schedule and LTS status.
3032
</li>

apps/site/util/download/archive.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,10 @@ export const buildReleaseArtifacts = (
140140
* Extracts the version from the pathname.
141141
* It expects the version to be in the format like 'v22.0.4'.
142142
*/
143-
export const extractVersionFromPath = (pathname: string | undefined) => {
144-
if (!pathname) {
145-
return null;
146-
}
147-
143+
export const extractVersionFromPath = (pathname: string) => {
148144
const segments = pathname.split('/').filter(Boolean);
149-
const version = segments.pop();
150-
151-
// Checks the version prefix + digits + optional dot-separated digits
152-
// (v22, v22.0.4)
153-
if (!version || !version.match(/^v\d+(\.\d+)*$/)) {
154-
return null;
155-
}
145+
// The version is expected to be the last segment in the path
146+
const version = segments.pop()!;
156147

157148
return version;
158149
};

0 commit comments

Comments
 (0)