diff --git a/scripts/indexr.js b/scripts/indexr.js index fbf1e9c6..d70f4ffb 100644 --- a/scripts/indexr.js +++ b/scripts/indexr.js @@ -64,6 +64,35 @@ async function indexData() { apiKey: process.env.TYPESENSE_API_KEY, }); + + let collectionExists = false; + try { + await client.collections(process.env.TYPESENSE_COLLECTION).retrieve(); + collectionExists = true; + } catch (error) { + if (error.httpStatus !== 404) { + throw error; + } + } + + if (collectionExists) { + await client.collections(process.env.TYPESENSE_COLLECTION).delete(); + console.log(`Collection ${process.env.TYPESENSE_COLLECTION} deleted successfully.`); + } + + await client.collections().create({ + name: process.env.TYPESENSE_COLLECTION, + fields: [ + { name: 'objectID', type: 'string' }, + { name: 'title', type: 'string' }, + { name: 'search_keyword', type: 'string' }, + { name: 'slug', type: 'string' }, + { name: 'excerpt', type: 'string' }, + { name: 'headings', type: 'string[]', facet: false } + ] + }); + console.log(`Collection ${process.env.TYPESENSE_COLLECTION} created successfully.`); + const response = await request('http://localhost:8000/___graphql', pageQuery); console.log('response', response); const data = await response; diff --git a/src/components/SearchHits.scss b/src/components/SearchHits.scss index 1c8744d6..165e994b 100644 --- a/src/components/SearchHits.scss +++ b/src/components/SearchHits.scss @@ -2,7 +2,9 @@ ais-highlight-0000000000 { color: $white; - background-color: $success-green; + background-color: #00b2bd; + padding: 0 6px; + border-radius: 4px; } .input-empty { @@ -34,7 +36,7 @@ ais-highlight-0000000000 { text-decoration: none; } p { - margin: 6px 0; + margin: 6px 0 !important; font-size: 14px; line-height: 20px; overflow-wrap: break-word; diff --git a/src/components/SearchInputBox.jsx b/src/components/SearchInputBox.jsx index d24790f3..5985fc35 100644 --- a/src/components/SearchInputBox.jsx +++ b/src/components/SearchInputBox.jsx @@ -14,7 +14,7 @@ import { SearchHits } from './SearchHits'; import TypesenseInstantsearchAdapter from "typesense-instantsearch-adapter"; const ClickOutHandler = require('react-onclickout'); -// Create the Typesense InstantSearch Adapter instance + // @ts-ignore // console.log(process.env.TYPESENSE_SEARCH_API_KEY); // console.log(process.env.TYPESENSE_HOST); @@ -60,7 +60,7 @@ class SearchInputBox extends React.Component { searchQuery: '' }; - this.debouncedSearch = debounce(this.handleSearch, 300); + this.debouncedSearch = debounce(this.handleSearch, 500); } onClickOut = (event) => { @@ -78,9 +78,11 @@ class SearchInputBox extends React.Component { hasInput: query.length > 2, }); - this.setState({ searchQuery: '' }, () => { - this.debouncedSearch(query); - }); + if (this.state.searchQuery !== query) { + this.setState({ searchQuery: '' }, () => { + this.debouncedSearch(query); + }); + } } handleSearch = (query) => { diff --git a/src/components/layout.jsx b/src/components/layout.jsx index 1e32367d..79ccb2e9 100644 --- a/src/components/layout.jsx +++ b/src/components/layout.jsx @@ -52,7 +52,6 @@ class Layout extends React.Component { const navElement = document.querySelector( `.contextual-links a.dynamic-link__internal[href*="#${entry.target.id}"]`, ) - console.log(entry); if (entry.isIntersecting) { if (navElement && !navElement.classList.contains('border-red-100')) { document.querySelectorAll('.contextual-links__link a.border-red-100.border-b-2').forEach(previousActive => {