Skip to content

Commit

Permalink
fix: maintenance lts in the lack of active lts (nodejs#6025)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd authored Oct 18, 2023
1 parent db83182 commit fecdbb4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
7 changes: 6 additions & 1 deletion hooks/useNodeReleases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ export const useNodeReleases = () => {
[releases]
);

return { releases, getReleaseByStatus };
const getLatestIsLtsRelease = useCallback(
() => releases.find(release => release.isLts),
[releases]
);

return { releases, getReleaseByStatus, getLatestIsLtsRelease };
};
6 changes: 3 additions & 3 deletions layouts/DocsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { useNodeReleases } from '@/hooks/useNodeReleases';
import BaseLayout from './BaseLayout';

const DocsLayout: FC<PropsWithChildren> = ({ children }) => {
const { getReleaseByStatus } = useNodeReleases();
const { getReleaseByStatus, getLatestIsLtsRelease } = useNodeReleases();

const [lts, current] = useMemo(
() => [getReleaseByStatus('Active LTS'), getReleaseByStatus('Current')],
[getReleaseByStatus]
() => [getLatestIsLtsRelease(), getReleaseByStatus('Current')],
[getLatestIsLtsRelease, getReleaseByStatus]
);

const translationContext = {
Expand Down
2 changes: 1 addition & 1 deletion layouts/DownloadLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DownloadLayout: FC<PropsWithChildren> = ({ children }) => {

{children}

<WithNodeRelease status="Active LTS">
<WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>
{({ release }) => (
<>
<PrimaryDownloadMatrix {...release} />
Expand Down
2 changes: 1 addition & 1 deletion layouts/IndexLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const IndexLayout: FC<PropsWithChildren> = ({ children }) => {

<h2>{downloadHeadText}</h2>

<WithNodeRelease status="Active LTS">
<WithNodeRelease status={['Active LTS', 'Maintenance LTS']}>
{({ release }) => <HomeDownloadButton {...release} />}
</WithNodeRelease>

Expand Down
10 changes: 9 additions & 1 deletion next.json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import localeConfig from './i18n/config.json' assert { type: 'json' };
import siteNavigation from './navigation.json' assert { type: 'json' };
import blogData from './public/blog-posts-data.json' assert { type: 'json' };
import releaseData from './public/node-releases-data.json' assert { type: 'json' };
import siteRedirects from './redirects.json' assert { type: 'json' };
import siteConfig from './site.json' assert { type: 'json' };

export { siteConfig, siteNavigation, siteRedirects, localeConfig, blogData };
export {
siteConfig,
siteNavigation,
siteRedirects,
localeConfig,
blogData,
releaseData,
};
4 changes: 2 additions & 2 deletions providers/nodeReleasesProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, useMemo } from 'react';
import type { FC, PropsWithChildren } from 'react';

import nodeReleasesData from '@/public/node-releases-data.json';
import { releaseData } from '@/next.json.mjs';
import type { NodeReleaseSource, NodeRelease } from '@/types';
import { getNodeReleaseStatus } from '@/util/nodeRelease';

Expand All @@ -11,7 +11,7 @@ export const NodeReleasesProvider: FC<PropsWithChildren> = ({ children }) => {
const releases = useMemo(() => {
const now = new Date();

return nodeReleasesData.map((raw: NodeReleaseSource) => {
return releaseData.map((raw: NodeReleaseSource) => {
const support = {
currentStart: raw.currentStart,
ltsStart: raw.ltsStart,
Expand Down
10 changes: 7 additions & 3 deletions providers/withNodeRelease.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { NodeRelease, NodeReleaseStatus } from '@/types';
import { isNodeRelease } from '@/util/nodeRelease';

type WithNodeReleaseProps = {
status: NodeReleaseStatus;
status: NodeReleaseStatus[] | NodeReleaseStatus;
children: FC<{ release: NodeRelease }>;
};

Expand All @@ -16,8 +16,12 @@ export const WithNodeRelease: FC<WithNodeReleaseProps> = ({
}) => {
const { getReleaseByStatus } = useNodeReleases();

const release = useMemo(
() => getReleaseByStatus(status),
const [release] = useMemo(
() =>
[status]
.flat()
.map(s => getReleaseByStatus(s))
.filter(s => !!s),
[status, getReleaseByStatus]
);

Expand Down

0 comments on commit fecdbb4

Please sign in to comment.