@@ -16,6 +16,9 @@ import { useDocSearchKeyboardEvents } from "@docsearch/react"
1616import { DocSearchHit } from "@docsearch/react/dist/esm/types"
1717import SearchButton from "./SearchButton"
1818import SearchModal from "./SearchModal"
19+ import { sanitizeHitUrl } from "../../utils/url"
20+ import { sanitizeHitTitle } from "../../utils/sanitizeHitTitle"
21+
1922// Styles
2023import "@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 ( / ^ h t t p s ? : \/ \/ [ ^ \/ ] + (? = \/ ) / , "" )
57- . replace ( "#main-content" , "" )
58- . replace ( "#content" , "" )
59- . replace ( "#top" , "" )
60-
61- const sanitizeHitTitle = ( value : string ) : string => {
62- const newValue = value . replaceAll ( """ , '"' )
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