Skip to content

Commit 04fd007

Browse files
committed
chore: appropriate base url and results for api
1 parent 1d70c58 commit 04fd007

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

app/[locale]/next-data/api-data/route.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,20 @@ import type { GitHubApiFile } from '@/types';
77
import { getGitHubApiDocsUrl } from '@/util/gitHubUtils';
88
import { parseRichTextIntoPlainText } from '@/util/stringUtils';
99

10-
const getPathnameForApiFile = (name: string) =>
11-
`api/${name.replace('.md', '.html')}`;
10+
const getPathnameForApiFile = (name: string, version: string) =>
11+
`docs/${version}/api/${name.replace('.md', '.html')}`;
1212

1313
// This is the Route Handler for the `GET` method which handles the request
1414
// for a digest and metadata of all API pages from the Node.js Website
1515
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers
1616
export const GET = async () => {
1717
const releases = await getReleaseData();
1818

19-
const latestLTSRelease = releases.find(release =>
19+
const { versionWithPrefix } = releases.find(release =>
2020
['Active LTS', 'Maintenance LTS'].includes(release.status)
21-
);
21+
)!;
2222

23-
const gitHubApiResponse = await fetch(
24-
getGitHubApiDocsUrl(latestLTSRelease!.versionWithPrefix)
25-
);
23+
const gitHubApiResponse = await fetch(getGitHubApiDocsUrl(versionWithPrefix));
2624

2725
return gitHubApiResponse.json().then((apiDocsFiles: Array<GitHubApiFile>) => {
2826
// maps over each api file and get the download_url, fetch the content and deflates it
@@ -41,7 +39,7 @@ export const GET = async () => {
4139

4240
return {
4341
filename,
44-
pathname: getPathnameForApiFile(name),
42+
pathname: getPathnameForApiFile(name, versionWithPrefix),
4543
content: deflatedSource,
4644
};
4745
}

components/Common/Search/States/WithSearchResult.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { FC } from 'react';
33

44
import { pathToBreadcrumbs } from '@/components/Common/Search/utils';
55
import Link from '@/components/Link';
6+
import { BASE_URL } from '@/next.constants.mjs';
67
import { highlighter } from '@/next.orama.mjs';
78
import type { SearchDoc } from '@/types';
89

@@ -15,7 +16,7 @@ type SearchResultProps = {
1516

1617
export const WithSearchResult: FC<SearchResultProps> = props => {
1718
const isAPIResult = props.hit.document.siteSection.toLowerCase() === 'api';
18-
const basePath = isAPIResult ? 'https://nodejs.org' : '';
19+
const basePath = isAPIResult ? BASE_URL : '';
1920
const path = `${basePath}/${props.hit.document.path}`;
2021

2122
return (

components/MDX/SearchPage/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { WithPoweredBy } from '@/components/Common/Search/States/WithPoweredBy';
99
import { pathToBreadcrumbs } from '@/components/Common/Search/utils';
1010
import Link from '@/components/Link';
1111
import { useBottomScrollListener } from '@/hooks/react-client';
12-
import { DEFAULT_ORAMA_QUERY_PARAMS } from '@/next.constants.mjs';
12+
import { BASE_URL, DEFAULT_ORAMA_QUERY_PARAMS } from '@/next.constants.mjs';
1313
import { search as oramaSearch, highlighter } from '@/next.orama.mjs';
1414
import type { SearchDoc } from '@/types';
1515

@@ -70,8 +70,11 @@ const SearchPage: FC = () => {
7070
? { where: { siteSection: { eq: searchSection } } }
7171
: {};
7272

73-
const getDocumentURL = (path: string) =>
74-
path.startsWith('api/') ? `https://nodejs.org/${path}` : path;
73+
const getDocumentURL = (siteSection: string, path: string) => {
74+
const isAPIResult = siteSection.toLowerCase() === 'api';
75+
const basePath = isAPIResult ? BASE_URL : '';
76+
return `${basePath}/${path}`;
77+
};
7578

7679
return (
7780
<div className={styles.searchPageContainer}>
@@ -103,8 +106,11 @@ const SearchPage: FC = () => {
103106
{hits?.map(hit => (
104107
<Link
105108
key={hit.id}
106-
href={getDocumentURL(hit.document.path)}
107109
className={styles.searchResult}
110+
href={getDocumentURL(
111+
hit.document.siteSection.toLowerCase(),
112+
hit.document.path
113+
)}
108114
>
109115
<div>
110116
<h2 className={styles.searchResultTitle}>

0 commit comments

Comments
 (0)