Skip to content

Commit

Permalink
search results (#159)
Browse files Browse the repository at this point in the history
* search results

* fix(search): algolia search results

* fix(search): algolia search results - breadcrumbs

* fix(search): remove header from search

* fix(search): remove header from search results

---------

Co-authored-by: Vega <[email protected]>
  • Loading branch information
ObedVega and Vega authored Nov 19, 2024
1 parent 040652c commit 5361484
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
7 changes: 5 additions & 2 deletions src/theme/SearchBar/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@

.DocSearch-Form {
--docsearch-spacing: 1rem;
--docsearch-highlight-color: var(--cv-theme-tertiary);
border-radius: 0;
border-bottom: 1px solid #ebedee;
}

.DocSearch-Hit a {
--docsearch-highlight-color: var(--cv-theme-tertiary);
box-shadow: none;
padding-left: 0;
}
Expand Down Expand Up @@ -130,6 +128,11 @@
top: 1px;
}

.DocSearch-Hits mark {
background: rgb(243 116 64 / 20%);
color: var(--docsearch-hit-color);
}

.DocSearch-Button {
--docsearch-searchbox-shadow: none;
--docsearch-searchbox-background: transparent;
Expand Down
54 changes: 35 additions & 19 deletions src/theme/SearchPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,31 +228,28 @@ function SearchPageContent(): JSX.Element {
/algolia-docsearch-suggestion--highlight/g,
'search-result-match'
);

const items = hits.map(
({
url,
_highlightResult: { hierarchy },
_snippetResult: snippet = {},
}: {
url: string;
_highlightResult: { hierarchy: { [key: string]: { value: string } } };
_snippetResult: { content?: { value: string } };
}) => {

const items = hits.reduce((filteredItems, { url, _highlightResult: { hierarchy }, _snippetResult: snippet = {}, anchor }) => {
if (anchor === "site-header" || !anchor) {
return filteredItems;
}

if (snippet.content) {
const titles = Object.keys(hierarchy).map((key) =>
sanitizeValue(hierarchy[key]!.value)
);
return {

filteredItems.push({
title: titles.pop()!,
url: processSearchResultUrl(url),
summary: snippet.content
? `${sanitizeValue(snippet.content.value)}...`
: '',
summary: `${sanitizeValue(snippet.content.value)}...`,
breadcrumbs: titles,
};
});
}
);

return filteredItems;
}, []);


searchResultStateDispatcher({
type: 'update',
value: {
Expand Down Expand Up @@ -473,7 +470,26 @@ function SearchPageContent(): JSX.Element {
className={styles.searchResultItemHeading}
dangerouslySetInnerHTML={{ __html: title }}
></Heading>

{breadcrumbs.length > 0 && (
<nav aria-label="breadcrumbs">
<ul
className={clsx(
'breadcrumbs',
styles.searchResultItemPath
)}
>
{breadcrumbs.map((html, index) => (
<li
key={index}
className="breadcrumbs__item"
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: html }}
/>
))}
</ul>
</nav>
)}
{summary && (
<p
className={styles.searchResultItemSummary}
Expand Down
2 changes: 1 addition & 1 deletion src/theme/SearchPage/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@

:global(.search-result-match) {
color: var(--docsearch-hit-color);
background: rgb(255 215 142 / 25%);
background: rgb(243 116 64 / 20%);
padding: 0.09em 0;
}

0 comments on commit 5361484

Please sign in to comment.