From 43be8acb6495e2d31904441a9150017b919cc533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20=C5=A0tefani=C4=87?= <80431202+stefanicjuraj@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:42:49 +0100 Subject: [PATCH] feat: add search website index (#210) Signed-off-by: stefanicjuraj --- src/components/Search.jsx | 30 +++++++++++++++++++++++++----- src/styles/components/search.scss | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/Search.jsx b/src/components/Search.jsx index d5cca801..5132ff8a 100644 --- a/src/components/Search.jsx +++ b/src/components/Search.jsx @@ -126,6 +126,8 @@ function Search() {
+
+ )} @@ -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}']`); @@ -179,7 +186,7 @@ function Hit({ hit, setIsSearchVisible, indexName }) { }} > - {indexName === 'docs' && ( + {(indexName === 'docs' || indexName === 'website') && ( <>
🟦 @@ -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 (
- {indexName === 'docs' ? 'Documentation' : 'Blog'} + {getIndexLabel()} {" "} ({nbHits} results) diff --git a/src/styles/components/search.scss b/src/styles/components/search.scss index 808fa107..7345347e 100644 --- a/src/styles/components/search.scss +++ b/src/styles/components/search.scss @@ -134,7 +134,7 @@ padding-bottom: 32px; } -[data-index="blogs_test"] .ais-Hits-list { +[data-index="website"] .ais-Hits-list { padding-bottom: 256px; }