diff --git a/components/Common/Search/States/WithSearchBox.tsx b/components/Common/Search/States/WithSearchBox.tsx index 58f6b76645192..7d9defa88bf07 100644 --- a/components/Common/Search/States/WithSearchBox.tsx +++ b/components/Common/Search/States/WithSearchBox.tsx @@ -29,6 +29,8 @@ export type SearchDoc = { pageSectionContent: string; }; +type Facets = { [key: string]: number }; + type SearchResults = Nullable>; type SearchBoxProps = { onClose: () => void }; @@ -100,7 +102,7 @@ export const WithSearchBox: FC = ({ onClose }) => { }; }; - const facets = { + const facets: Facets = { all: searchResults?.count ?? 0, ...(searchResults?.facets?.siteSection?.values ?? {}), }; @@ -143,11 +145,7 @@ export const WithSearchBox: FC = ({ onClose }) => { > {facetName} - ( - {facets[facetName as keyof typeof facets].toLocaleString( - 'en' - )} - ) + ({facets[facetName].toLocaleString('en')}) ))} @@ -176,7 +174,9 @@ export const WithSearchBox: FC = ({ onClose }) => { ? searchResults?.count > 8 && searchTerm && ( ) : null} diff --git a/components/Common/Search/States/WithSearchResult.tsx b/components/Common/Search/States/WithSearchResult.tsx index 57cd8e77bbb8c..e2769bd4f4b16 100644 --- a/components/Common/Search/States/WithSearchResult.tsx +++ b/components/Common/Search/States/WithSearchResult.tsx @@ -1,9 +1,9 @@ import type { Result } from '@orama/orama'; -import NextLink from 'next/link'; import type { FC } from 'react'; import type { SearchDoc } from '@/components/Common/Search/States/WithSearchBox'; import { pathToBreadcrumbs } from '@/components/Common/Search/utils'; +import Link from '@/components/Link'; import { highlighter } from '@/next.orama.mjs'; import styles from './index.module.css'; @@ -15,16 +15,14 @@ type SearchResultProps = { export const WithSearchResult: FC = props => { const isAPIResult = props.hit.document.siteSection.toLowerCase() === 'api'; - const basePath = isAPIResult ? 'https://nodejs.org/docs/latest' : '/en'; + const basePath = isAPIResult ? 'https://nodejs.org' : ''; const path = `${basePath}/${props.hit.document.path}`; return ( -
= props => { {' > '} {props.hit.document.pageTitle}
-
+ ); }; diff --git a/components/Common/Search/index.module.css b/components/Common/Search/index.module.css index 9717e606051e7..02be508deaae5 100644 --- a/components/Common/Search/index.module.css +++ b/components/Common/Search/index.module.css @@ -1,23 +1,23 @@ .searchButton { @apply relative - w-52 - rounded-md - bg-neutral-100 - py-2 - pl-9 - pr-4 - text-left - text-sm - text-neutral-700 - transition-colors - duration-200 - ease-in-out - hover:bg-neutral-200 - hover:text-neutral-800 - dark:bg-neutral-900 - dark:text-neutral-600 - dark:hover:bg-neutral-800 - dark:hover:text-neutral-500; + w-52 + rounded-md + bg-neutral-100 + py-2 + pl-9 + pr-4 + text-left + text-sm + text-neutral-700 + transition-colors + duration-200 + ease-in-out + hover:bg-neutral-200 + hover:text-neutral-800 + dark:bg-neutral-900 + dark:text-neutral-600 + dark:hover:bg-neutral-800 + dark:hover:text-neutral-500; } .magnifyingGlassIcon { diff --git a/package-lock.json b/package-lock.json index 2b6cfef59cc1e..72a7779d5fb54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,7 +60,7 @@ "vfile-matter": "~5.0.0" }, "devDependencies": { - "@orama/orama": "^2.0.1", + "@orama/orama": "~2.0.1", "@storybook/addon-controls": "~7.6.8", "@storybook/addon-interactions": "~7.6.8", "@storybook/addon-themes": "~7.6.8", diff --git a/package.json b/package.json index 4552dca157267..079f591dffe96 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "vfile-matter": "~5.0.0" }, "devDependencies": { - "@orama/orama": "^2.0.1", + "@orama/orama": "~2.0.1", "@storybook/addon-controls": "~7.6.8", "@storybook/addon-interactions": "~7.6.8", "@storybook/addon-themes": "~7.6.8", diff --git a/scripts/orama-search/get-documents.mjs b/scripts/orama-search/get-documents.mjs index 4774fd99161b0..7b94778fcb5fb 100644 --- a/scripts/orama-search/get-documents.mjs +++ b/scripts/orama-search/get-documents.mjs @@ -34,19 +34,13 @@ const splitIntoSections = markdownContent => { })); }; -const getPageTitle = data => { - const { title } = data; - - if (title) { - return title; - } - - const { pathname } = data; - const parts = pathname.split('/'); - const lastPart = parts[parts.length - 1].replace(/\.html$/, ''); - - return lastPart.replace(/-/g, ' '); -}; +const getPageTitle = data => + data.title || + data.pathname + .split('/') + .pop() + .replace(/\.html$/, '') + .replace(/-/g, ' '); export const siteContent = [...pageData, ...apiData] .map(data => { diff --git a/scripts/orama-search/sync-orama-cloud.mjs b/scripts/orama-search/sync-orama-cloud.mjs index 230f07ca99627..fb13a6741c20e 100644 --- a/scripts/orama-search/sync-orama-cloud.mjs +++ b/scripts/orama-search/sync-orama-cloud.mjs @@ -21,50 +21,37 @@ const runUpdate = async () => { batches.push(siteContent.slice(i, i + batchSize)); } - console.log( - `Inserting ${batches.length} batches of ${batchSize} documents each.` - ); await Promise.all(batches.map(insertBatch)); - console.log(`Done inserting batches. ${siteContent.length} documents total.`); }; // We call the "notify" API to upsert the documents in the index. // Orama will keep a queue of all the documents we send, and will process them once we call the "deploy" API. // Full docs on the "notify" API: https://docs.oramasearch.com/cloud/data-sources/custom-integrations/webhooks#updating-removing-inserting-elements-in-a-live-index -const insertBatch = async batch => { +const insertBatch = async batch => await fetch(`${ORAMA_API_BASE_URL}/notify`, { method: 'POST', headers: oramaHeaders, - body: JSON.stringify({ - upsert: batch, - }), + body: JSON.stringify({ upsert: batch }), }); -}; // We call the "deploy" API to trigger a deployment of the index, which will process all the documents in the queue. // Full docs on the "deploy" API: https://docs.oramasearch.com/cloud/data-sources/custom-integrations/webhooks#deploying-the-index -const triggerDeployment = async () => { - console.log('Triggering deployment'); +const triggerDeployment = async () => await fetch(`${ORAMA_API_BASE_URL}/deploy`, { method: 'POST', headers: oramaHeaders, }); - console.log('Done triggering deployment'); -}; // We call the "snapshot" API to empty the index before inserting the new documents. // The "snapshot" API is tipically used to replace the entire index with a fresh set of documents, but we use it here to empty the index. // This operation gets queued, so the live index will still be available until we call the "deploy" API and redeploy the index. // Full docs on the "snapshot" API: https://docs.oramasearch.com/cloud/data-sources/custom-integrations/webhooks#inserting-a-snapshot -const emptyOramaIndex = async () => { - console.log('Emptying index'); +const emptyOramaIndex = async () => await fetch(`${ORAMA_API_BASE_URL}/snapshot`, { method: 'POST', headers: oramaHeaders, body: JSON.stringify([]), }); - console.log('Done emptying index'); -}; // Now we proceed to call the APIs in order: // 1. Empty the index