Skip to content

Commit

Permalink
feat: add search website index (#210)
Browse files Browse the repository at this point in the history
Signed-off-by: stefanicjuraj <[email protected]>
  • Loading branch information
stefanicjuraj authored Dec 19, 2024
1 parent 2d34558 commit 43be8ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions src/components/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ function Search() {
<SearchIndex indexName="docs" setDisplayHits={setDisplayHits} setIsSearchVisible={setIsSearchVisible} />
<hr style={{ marginBottom: '40px' }} />
<SearchIndex indexName="blogs_test" setDisplayHits={setDisplayHits} setIsSearchVisible={setIsSearchVisible} />
<hr style={{ marginBottom: '40px' }} />
<SearchIndex indexName="website" setDisplayHits={setDisplayHits} setIsSearchVisible={setIsSearchVisible} />
</>
)}
<Configure hitsPerPage={10} clickAnalytics getRankingInfo={false} />
Expand Down Expand Up @@ -153,10 +155,15 @@ function SearchIndex({ indexName, setDisplayHits, setIsSearchVisible }) {
function Hit({ hit, setIsSearchVisible, indexName }) {
const handleClick = (e) => {
e.preventDefault();
let hitUrl = hit.url;

if (indexName === 'blogs_test') {
hitUrl = `https://www.daytona.io/dotfiles/${hit.slug}`;
} else if (indexName === 'website') {
hitUrl = `https://www.daytona.io/${hit.slug}`;
}

const currentUrl = window.location.href;
const hitUrl = indexName === 'blogs_test'
? `https://www.daytona.io/dotfiles/${hit.slug}`
: hit.url;

if (currentUrl.includes(hitUrl)) {
const element = document.querySelector(`[data-slug='${hit.slug}']`);
Expand All @@ -179,7 +186,7 @@ function Hit({ hit, setIsSearchVisible, indexName }) {
}}
>
<a href={hit.url} tabIndex="-1" onClick={handleClick}>
{indexName === 'docs' && (
{(indexName === 'docs' || indexName === 'website') && (
<>
<h5 style={{ fontSize: '20px', display: 'flex', alignItems: 'center' }}>
<span style={{ fontSize: '10px', marginRight: '8px' }}>🟦</span>
Expand Down Expand Up @@ -230,10 +237,23 @@ const CustomStats = ({ nbHits, indexName, setDisplayHits }) => {
setDisplayHits(nbHits > 0)
}, [nbHits, setDisplayHits])

const getIndexLabel = () => {
switch(indexName) {
case 'docs':
return 'Documentation';
case 'blogs_test':
return 'Blog';
case 'website':
return 'Website';
default:
return 'Results';
}
}

return (
<div className="custom-stats">
<span style={{ color: 'var(--primary-text-color)' }}>
{indexName === 'docs' ? 'Documentation' : 'Blog'}
{getIndexLabel()}
{" "}
</span>
({nbHits} results)
Expand Down
2 changes: 1 addition & 1 deletion src/styles/components/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
padding-bottom: 32px;
}

[data-index="blogs_test"] .ais-Hits-list {
[data-index="website"] .ais-Hits-list {
padding-bottom: 256px;
}

Expand Down

0 comments on commit 43be8ac

Please sign in to comment.