Skip to content

Commit 6af8e13

Browse files
authored
fix: fallback to Maintenance LTS if no Active LTS found (#8251)
* Fallback to Maintenance LTS if no Active LTS found * Apply similar Maintenance LTS fallback to Orama logic
1 parent 6c49a09 commit 6af8e13

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

apps/site/components/withDownloadSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const WithDownloadSection: FC<WithDownloadSectionProps> = ({
3838
// Decides which initial release to use based on the current pathname
3939
const initialRelease = pathname.endsWith('/current')
4040
? 'Current'
41-
: 'Active LTS';
41+
: ['Active LTS' as const, 'Maintenance LTS' as const];
4242

4343
return (
4444
<WithNodeRelease status={initialRelease}>

apps/site/components/withFooter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const WithFooter: FC = () => {
2222

2323
const primary = (
2424
<div className="flex flex-row gap-2">
25-
<WithNodeRelease status="Active LTS">
25+
<WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>
2626
{({ release }) => (
2727
<BadgeGroup
2828
size="small"

apps/site/components/withNodeRelease.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ const WithNodeRelease: FC<WithNodeReleaseProps> = async ({
1919
}) => {
2020
const releaseData = await provideReleaseData();
2121

22-
const matchingRelease = releaseData.find(release =>
23-
[status].flat().includes(release.status)
24-
);
22+
let matchingRelease: NodeRelease | undefined;
23+
for (const statusItem of Array.isArray(status) ? status : [status]) {
24+
matchingRelease = releaseData.find(
25+
release => release.status === statusItem
26+
);
27+
if (matchingRelease) {
28+
break;
29+
}
30+
}
2531

26-
if (matchingRelease !== undefined) {
27-
return <Component release={matchingRelease!} />;
32+
if (matchingRelease) {
33+
return <Component release={matchingRelease} />;
2834
}
2935

3036
return null;

apps/site/scripts/orama-search/get-documents.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ const fetchOptions = process.env.GITHUB_TOKEN
1818
export const getAPIDocs = async () => {
1919
// Find the current Active LTS version
2020
const releaseData = await generateReleaseData();
21-
const { versionWithPrefix } = releaseData.find(
22-
r => r.status === 'Active LTS'
23-
);
21+
const ltsRelease =
22+
releaseData.find(r => r.status === 'Active LTS') ||
23+
releaseData.find(r => r.status === 'Maintenance LTS');
24+
25+
if (!ltsRelease) {
26+
throw new Error('No Active LTS or Maintenance LTS release found');
27+
}
2428

2529
// Get list of API docs from the Node.js repo
2630
const fetchResponse = await fetch(
27-
`https://api.github.com/repos/nodejs/node/contents/doc/api?ref=${versionWithPrefix}`,
31+
`https://api.github.com/repos/nodejs/node/contents/doc/api?ref=${ltsRelease.versionWithPrefix}`,
2832
fetchOptions
2933
);
3034
const documents = await fetchResponse.json();
@@ -36,7 +40,7 @@ export const getAPIDocs = async () => {
3640

3741
return {
3842
content: await res.text(),
39-
pathname: `docs/${versionWithPrefix}/api/${basename(name, '.md')}.html`,
43+
pathname: `docs/${ltsRelease.versionWithPrefix}/api/${basename(name, '.md')}.html`,
4044
};
4145
})
4246
);

0 commit comments

Comments
 (0)