Skip to content

Commit

Permalink
style: addresses feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Jan 22, 2024
1 parent f876fa6 commit 3be81f7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 63 deletions.
14 changes: 7 additions & 7 deletions components/Common/Search/States/WithSearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type SearchDoc = {
pageSectionContent: string;
};

type Facets = { [key: string]: number };

type SearchResults = Nullable<Results<SearchDoc>>;

type SearchBoxProps = { onClose: () => void };
Expand Down Expand Up @@ -100,7 +102,7 @@ export const WithSearchBox: FC<SearchBoxProps> = ({ onClose }) => {
};
};

const facets = {
const facets: Facets = {
all: searchResults?.count ?? 0,
...(searchResults?.facets?.siteSection?.values ?? {}),
};
Expand Down Expand Up @@ -143,11 +145,7 @@ export const WithSearchBox: FC<SearchBoxProps> = ({ onClose }) => {
>
{facetName}
<span className={styles.fulltextSearchSectionCount}>
(
{facets[facetName as keyof typeof facets].toLocaleString(
'en'
)}
)
({facets[facetName].toLocaleString('en')})
</span>
</button>
))}
Expand Down Expand Up @@ -176,7 +174,9 @@ export const WithSearchBox: FC<SearchBoxProps> = ({ onClose }) => {
? searchResults?.count > 8 &&
searchTerm && (
<WithAllResults
{...{ searchResults, searchTerm, selectedFacetName }}
searchResults={searchResults}
searchTerm={searchTerm}
selectedFacetName={selectedFacetName}
/>
)
: null}
Expand Down
10 changes: 4 additions & 6 deletions components/Common/Search/States/WithSearchResult.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,16 +15,14 @@ type SearchResultProps = {

export const WithSearchResult: FC<SearchResultProps> = 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 (
<NextLink
<Link
key={props.hit.id}
href={path}
className={styles.fulltextSearchResult}
target={isAPIResult ? '_blank' : undefined}
rel={isAPIResult ? 'noopener noreferrer' : undefined}
>
<div
className={styles.fulltextSearchResultTitle}
Expand All @@ -39,6 +37,6 @@ export const WithSearchResult: FC<SearchResultProps> = props => {
{' > '}
{props.hit.document.pageTitle}
</div>
</NextLink>
</Link>
);
};
36 changes: 18 additions & 18 deletions components/Common/Search/index.module.css
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 7 additions & 13 deletions scripts/orama-search/get-documents.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
21 changes: 4 additions & 17 deletions scripts/orama-search/sync-orama-cloud.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3be81f7

Please sign in to comment.