Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions apps/site/components/withDownloadArchive.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { notFound } from 'next/navigation';
import type { FC } from 'react';
import semVer from 'semver';

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

if (version == null) {
return notFound();
}

// Find the release data for the given version
const releaseData = provideReleaseData();
const release = releaseData.find(
release => semVer.major(version) === release.major
const release = releaseData.find(release =>
// Match major version only (e.g., v22.x.x for release.major v22)
version.startsWith(`v${release.major}`)
)!;

if (!release) {
return notFound();
}

const releaseArtifacts = buildReleaseArtifacts(release, version);

return <Component {...releaseArtifacts} />;
Expand Down
4 changes: 3 additions & 1 deletion apps/site/pages/en/download/archive/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ layout: download-archive
<ReleaseOverview release={release} />

<ul className='flex list-none flex-col gap-2 p-0 text-sm'>

<li>
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.
</li>
<li>
Learn more about <Link href="/about/previous-releases">Node.js releases</Link>, including the release schedule and LTS status.
</li>
Expand Down
15 changes: 3 additions & 12 deletions apps/site/util/download/archive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,10 @@ export const buildReleaseArtifacts = (
* Extracts the version from the pathname.
* It expects the version to be in the format like 'v22.0.4'.
*/
export const extractVersionFromPath = (pathname: string | undefined) => {
if (!pathname) {
return null;
}

export const extractVersionFromPath = (pathname: string) => {
const segments = pathname.split('/').filter(Boolean);
const version = segments.pop();

// Checks the version prefix + digits + optional dot-separated digits
// (v22, v22.0.4)
if (!version || !version.match(/^v\d+(\.\d+)*$/)) {
return null;
}
// The version is expected to be the last segment in the path
const version = segments.pop()!;

return version;
};
Loading