forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwithDownloadArchive.tsx
More file actions
45 lines (35 loc) · 1.25 KB
/
withDownloadArchive.tsx
File metadata and controls
45 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { notFound } from 'next/navigation';
import type { FC } from 'react';
import { getClientContext } from '#site/client-context';
import provideReleaseData from '#site/next-data/providers/releaseData';
import {
buildReleaseArtifacts,
extractVersionFromPath,
} from '#site/util/download/archive';
type DownloadArchive = ReturnType<typeof buildReleaseArtifacts>;
type WithDownloadArchiveProps = {
children: FC<DownloadArchive>;
};
/**
* Higher-order component that extracts version from pathname,
* fetches release data, and provides download artifacts to child component
*/
const WithDownloadArchive: FC<WithDownloadArchiveProps> = async ({
children: Component,
}) => {
const { pathname } = getClientContext();
// Extract version from pathname
const version = extractVersionFromPath(pathname);
// Find the release data for the given version
const releaseData = provideReleaseData();
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} />;
};
export default WithDownloadArchive;