diff --git a/app/[locale]/next-data/api-data/route.ts b/app/[locale]/next-data/api-data/route.ts index 3c37494f2f6a8..bad0d93fd65ba 100644 --- a/app/[locale]/next-data/api-data/route.ts +++ b/app/[locale]/next-data/api-data/route.ts @@ -7,8 +7,8 @@ import type { GitHubApiFile } from '@/types'; import { getGitHubApiDocsUrl } from '@/util/gitHubUtils'; import { parseRichTextIntoPlainText } from '@/util/stringUtils'; -const getPathnameForApiFile = (name: string) => - `api/${name.replace('.md', '.html')}`; +const getPathnameForApiFile = (name: string, version: string) => + `docs/${version}/api/${name.replace('.md', '.html')}`; // This is the Route Handler for the `GET` method which handles the request // for a digest and metadata of all API pages from the Node.js Website @@ -16,13 +16,11 @@ const getPathnameForApiFile = (name: string) => export const GET = async () => { const releases = await getReleaseData(); - const latestLTSRelease = releases.find(release => + const { versionWithPrefix } = releases.find(release => ['Active LTS', 'Maintenance LTS'].includes(release.status) - ); + )!; - const gitHubApiResponse = await fetch( - getGitHubApiDocsUrl(latestLTSRelease!.versionWithPrefix) - ); + const gitHubApiResponse = await fetch(getGitHubApiDocsUrl(versionWithPrefix)); return gitHubApiResponse.json().then((apiDocsFiles: Array) => { // maps over each api file and get the download_url, fetch the content and deflates it @@ -41,7 +39,7 @@ export const GET = async () => { return { filename, - pathname: getPathnameForApiFile(name), + pathname: getPathnameForApiFile(name, versionWithPrefix), content: deflatedSource, }; } diff --git a/components/Common/Search/States/WithSearchResult.tsx b/components/Common/Search/States/WithSearchResult.tsx index 76757dafa4d1b..20aa1acfb92c0 100644 --- a/components/Common/Search/States/WithSearchResult.tsx +++ b/components/Common/Search/States/WithSearchResult.tsx @@ -3,6 +3,7 @@ import type { FC } from 'react'; import { pathToBreadcrumbs } from '@/components/Common/Search/utils'; import Link from '@/components/Link'; +import { BASE_URL } from '@/next.constants.mjs'; import { highlighter } from '@/next.orama.mjs'; import type { SearchDoc } from '@/types'; @@ -15,7 +16,7 @@ type SearchResultProps = { export const WithSearchResult: FC = props => { const isAPIResult = props.hit.document.siteSection.toLowerCase() === 'api'; - const basePath = isAPIResult ? 'https://nodejs.org' : ''; + const basePath = isAPIResult ? BASE_URL : ''; const path = `${basePath}/${props.hit.document.path}`; return ( diff --git a/components/MDX/SearchPage/index.tsx b/components/MDX/SearchPage/index.tsx index 29b6c5065402d..b5cda59982264 100644 --- a/components/MDX/SearchPage/index.tsx +++ b/components/MDX/SearchPage/index.tsx @@ -9,7 +9,7 @@ import { WithPoweredBy } from '@/components/Common/Search/States/WithPoweredBy'; import { pathToBreadcrumbs } from '@/components/Common/Search/utils'; import Link from '@/components/Link'; import { useBottomScrollListener } from '@/hooks/react-client'; -import { DEFAULT_ORAMA_QUERY_PARAMS } from '@/next.constants.mjs'; +import { BASE_URL, DEFAULT_ORAMA_QUERY_PARAMS } from '@/next.constants.mjs'; import { search as oramaSearch, highlighter } from '@/next.orama.mjs'; import type { SearchDoc } from '@/types'; @@ -70,8 +70,11 @@ const SearchPage: FC = () => { ? { where: { siteSection: { eq: searchSection } } } : {}; - const getDocumentURL = (path: string) => - path.startsWith('api/') ? `https://nodejs.org/${path}` : path; + const getDocumentURL = (siteSection: string, path: string) => { + const isAPIResult = siteSection.toLowerCase() === 'api'; + const basePath = isAPIResult ? BASE_URL : ''; + return `${basePath}/${path}`; + }; return (
@@ -103,8 +106,11 @@ const SearchPage: FC = () => { {hits?.map(hit => (