The Node.js® Website

chore: appropriate base url and results for api

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