Skip to content

Commit 166375b

Browse files
committed
update Search/index.tsx
1 parent 5a7f54d commit 166375b

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

src/components/Search/index.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { useDocSearchKeyboardEvents } from "@docsearch/react"
1616
import { DocSearchHit } from "@docsearch/react/dist/esm/types"
1717
import SearchButton from "./SearchButton"
1818
import SearchModal from "./SearchModal"
19+
import { sanitizeHitUrl } from "../../utils/url"
20+
import { sanitizeHitTitle } from "../../utils/sanitizeHitTitle"
21+
1922
// Styles
2023
import "@docsearch/css"
2124

@@ -49,21 +52,7 @@ const Search = forwardRef<{}, "button">((_, ref) => {
4952
const appId = process.env.GATSBY_ALGOLIA_APP_ID || ""
5053
const apiKey = process.env.GATSBY_ALGOLIA_SEARCH_KEY || ""
5154
const indexName =
52-
process.env.GATSBY_ALGOLIA_BASE_SEARCH_INDEX_NAME || "prod-ethereum-org"
53-
54-
const sanitizeHitUrl = (url: string): string =>
55-
url
56-
.replace(/^https?:\/\/[^\/]+(?=\/)/, "")
57-
.replace("#main-content", "")
58-
.replace("#content", "")
59-
.replace("#top", "")
60-
61-
const sanitizeHitTitle = (value: string): string => {
62-
const newValue = value.replaceAll("&quot;", '"')
63-
const siteNameIndex = value.lastIndexOf(" | ")
64-
if (siteNameIndex < 0) return newValue
65-
return newValue.substring(0, siteNameIndex)
66-
}
55+
process.env.GATSBY_ALGOLIA_BASE_SEARCH_INDEX_NAME || "ethereumorg"
6756

6857
// Check for the breakpoint with theme token
6958
const xlBp = useToken("breakpoints", "xl")
@@ -89,7 +78,7 @@ const Search = forwardRef<{}, "button">((_, ref) => {
8978
/>
9079
)}
9180
<Portal>
92-
{isOpen ? (
81+
{isOpen && (
9382
<SearchModal
9483
apiKey={apiKey}
9584
appId={appId}
@@ -153,7 +142,7 @@ const Search = forwardRef<{}, "button">((_, ref) => {
153142
},
154143
}}
155144
/>
156-
) : null}
145+
)}
157146
</Portal>
158147
</>
159148
)

0 commit comments

Comments
 (0)