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
2 changes: 1 addition & 1 deletion apps/site/components/withDownloadSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const WithDownloadSection: FC<WithDownloadSectionProps> = ({
// Decides which initial release to use based on the current pathname
const initialRelease = pathname.endsWith('/current')
? 'Current'
: 'Active LTS';
: ['Active LTS' as const, 'Maintenance LTS' as const];

return (
<WithNodeRelease status={initialRelease}>
Expand Down
2 changes: 1 addition & 1 deletion apps/site/components/withFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const WithFooter: FC = () => {

const primary = (
<div className="flex flex-row gap-2">
<WithNodeRelease status="Active LTS">
<WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>
{({ release }) => (
<BadgeGroup
size="small"
Expand Down
16 changes: 11 additions & 5 deletions apps/site/components/withNodeRelease.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ const WithNodeRelease: FC<WithNodeReleaseProps> = async ({
}) => {
const releaseData = await provideReleaseData();

const matchingRelease = releaseData.find(release =>
[status].flat().includes(release.status)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code would have worked fine, there was no need to refactor this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No? If there was a Maintenance LTS release in the array before an Active LTS release, the old logic would have picked the Maintenance LTS release. The new logic ensures we've looked at the whole array for an Active LTS release before switching to a Maintenance LTS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, that was an oversight. But I'd still wage over not using for statements within a React component.

Copy link
Member Author

@MattIPv4 MattIPv4 Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the context of this fix, I'd prefer for robust logic over using newer language syntax, a for loop works perfectly fine and really is doing nothing fundamentally different.

);
let matchingRelease: NodeRelease | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we do a folllo-up PR that doesn't do for and uses proper built-ins to match the repo convention style? cc @nodejs/nodejs-website

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there is a built-in that can do what this is doing? No array methods have a break equivalent?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean what we were doing before, Using array.find()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No? The old logic was iterating over release data so you can do a find to early return a match from it. The new logic iterates over status but early returns a value from release data, which I don't believe can be done cleanly with array methods?

for (const statusItem of Array.isArray(status) ? status : [status]) {
matchingRelease = releaseData.find(
release => release.status === statusItem
);
if (matchingRelease) {
break;
}
}

if (matchingRelease !== undefined) {
return <Component release={matchingRelease!} />;
if (matchingRelease) {
return <Component release={matchingRelease} />;
}

return null;
Expand Down
14 changes: 9 additions & 5 deletions apps/site/scripts/orama-search/get-documents.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ const fetchOptions = process.env.GITHUB_TOKEN
export const getAPIDocs = async () => {
// Find the current Active LTS version
const releaseData = await generateReleaseData();
const { versionWithPrefix } = releaseData.find(
r => r.status === 'Active LTS'
);
const ltsRelease =
releaseData.find(r => r.status === 'Active LTS') ||
releaseData.find(r => r.status === 'Maintenance LTS');

if (!ltsRelease) {
throw new Error('No Active LTS or Maintenance LTS release found');
}

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

return {
content: await res.text(),
pathname: `docs/${versionWithPrefix}/api/${basename(name, '.md')}.html`,
pathname: `docs/${ltsRelease.versionWithPrefix}/api/${basename(name, '.md')}.html`,
};
})
);
Expand Down
Loading