tangled
alpha
login
or
join now
keii.dev
/
nodejs.org
The Node.js® Website
0
fork
atom
overview
issues
pulls
pipelines
chore: appropriate base url and results for api
Claudio Wunder
2 years ago
04fd007a
1d70c588
+18
-13
3 changed files
expand all
collapse all
unified
split
app
[locale]
next-data
api-data
route.ts
components
Common
Search
States
WithSearchResult.tsx
MDX
SearchPage
index.tsx
+6
-8
app/[locale]/next-data/api-data/route.ts
···
7
7
import { getGitHubApiDocsUrl } from '@/util/gitHubUtils';
8
8
import { parseRichTextIntoPlainText } from '@/util/stringUtils';
9
9
10
10
-
const getPathnameForApiFile = (name: string) =>
11
11
-
`api/${name.replace('.md', '.html')}`;
10
10
+
const getPathnameForApiFile = (name: string, version: string) =>
11
11
+
`docs/${version}/api/${name.replace('.md', '.html')}`;
12
12
13
13
// This is the Route Handler for the `GET` method which handles the request
14
14
// for a digest and metadata of all API pages from the Node.js Website
···
16
16
export const GET = async () => {
17
17
const releases = await getReleaseData();
18
18
19
19
-
const latestLTSRelease = releases.find(release =>
19
19
+
const { versionWithPrefix } = releases.find(release =>
20
20
['Active LTS', 'Maintenance LTS'].includes(release.status)
21
21
-
);
21
21
+
)!;
22
22
23
23
-
const gitHubApiResponse = await fetch(
24
24
-
getGitHubApiDocsUrl(latestLTSRelease!.versionWithPrefix)
25
25
-
);
23
23
+
const gitHubApiResponse = await fetch(getGitHubApiDocsUrl(versionWithPrefix));
26
24
27
25
return gitHubApiResponse.json().then((apiDocsFiles: Array<GitHubApiFile>) => {
28
26
// maps over each api file and get the download_url, fetch the content and deflates it
···
41
39
42
40
return {
43
41
filename,
44
44
-
pathname: getPathnameForApiFile(name),
42
42
+
pathname: getPathnameForApiFile(name, versionWithPrefix),
45
43
content: deflatedSource,
46
44
};
47
45
}
+2
-1
components/Common/Search/States/WithSearchResult.tsx
···
3
3
4
4
import { pathToBreadcrumbs } from '@/components/Common/Search/utils';
5
5
import Link from '@/components/Link';
6
6
+
import { BASE_URL } from '@/next.constants.mjs';
6
7
import { highlighter } from '@/next.orama.mjs';
7
8
import type { SearchDoc } from '@/types';
8
9
···
15
16
16
17
export const WithSearchResult: FC<SearchResultProps> = props => {
17
18
const isAPIResult = props.hit.document.siteSection.toLowerCase() === 'api';
18
18
-
const basePath = isAPIResult ? 'https://nodejs.org' : '';
19
19
+
const basePath = isAPIResult ? BASE_URL : '';
19
20
const path = `${basePath}/${props.hit.document.path}`;
20
21
21
22
return (
+10
-4
components/MDX/SearchPage/index.tsx
···
9
9
import { pathToBreadcrumbs } from '@/components/Common/Search/utils';
10
10
import Link from '@/components/Link';
11
11
import { useBottomScrollListener } from '@/hooks/react-client';
12
12
-
import { DEFAULT_ORAMA_QUERY_PARAMS } from '@/next.constants.mjs';
12
12
+
import { BASE_URL, DEFAULT_ORAMA_QUERY_PARAMS } from '@/next.constants.mjs';
13
13
import { search as oramaSearch, highlighter } from '@/next.orama.mjs';
14
14
import type { SearchDoc } from '@/types';
15
15
···
70
70
? { where: { siteSection: { eq: searchSection } } }
71
71
: {};
72
72
73
73
-
const getDocumentURL = (path: string) =>
74
74
-
path.startsWith('api/') ? `https://nodejs.org/${path}` : path;
73
73
+
const getDocumentURL = (siteSection: string, path: string) => {
74
74
+
const isAPIResult = siteSection.toLowerCase() === 'api';
75
75
+
const basePath = isAPIResult ? BASE_URL : '';
76
76
+
return `${basePath}/${path}`;
77
77
+
};
75
78
76
79
return (
77
80
<div className={styles.searchPageContainer}>
···
103
106
{hits?.map(hit => (
104
107
<Link
105
108
key={hit.id}
106
106
-
href={getDocumentURL(hit.document.path)}
107
109
className={styles.searchResult}
110
110
+
href={getDocumentURL(
111
111
+
hit.document.siteSection.toLowerCase(),
112
112
+
hit.document.path
113
113
+
)}
108
114
>
109
115
<div>
110
116
<h2 className={styles.searchResultTitle}>