diff --git a/docusaurus.config.js b/docusaurus.config.js index 5d079a5e63..ef0aee1fec 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -11,6 +11,7 @@ import fs from 'fs'; import footerItems from './src/config/footer.navItems.js'; import baseHeadTags from './src/config/baseHeadTags.js'; import { sidebarItemsGenerator } from './custom-sidebar.js'; +import headTags from './src/config/CoveoSearchHeadTags.js'; const baseUrl = ''; const projectName = 'ai-unlimited-docs'; @@ -82,6 +83,7 @@ const config = { headTags: [ ...baseHeadTags, ...trackingScripts, + ...headTags ], // Even if you don't use internationalization, you can use this field to set diff --git a/src/components/CoveoSearch/CoveoSearch.js b/src/components/CoveoSearch/CoveoSearch.js new file mode 100644 index 0000000000..c1555f0641 --- /dev/null +++ b/src/components/CoveoSearch/CoveoSearch.js @@ -0,0 +1,87 @@ +import { useEffect } from 'react'; + +function CoveoSearch() { + useEffect(() => { + const hspApiKey = 'xx4ac4bcbd-1c8b-4482-b60b-bc0ebdc55e01'; + const siApiKey = 'xx116e6fc7-3430-4f29-9115-fde53bc5cd24'; + const orgId = 'teradataxrkwxj74'; + const siPageId = 'cda56b93-b731-4e51-9a46-6a2498b40cb0'; + const orgEndpont = `https://${orgId}.admin.org.coveo.com`; + const redirectionUrl = '/coveo-search'; + + function isSearchPage() { + return window.location.href.indexOf('/coveo-search') !== -1; + } + + function injectExternalSearchbox(searchboxID) { + const box = document.createElement('atomic-search-box'); + box.setAttribute('clear-filters', 'false'); + const wrapper = document.createElement('atomic-external'); + wrapper.appendChild(box); + document.getElementById(searchboxID)?.appendChild(wrapper); + } + + async function initSearchBox() { + const searchInterface = document.querySelector("atomic-search-interface#searchbox"); + if (searchInterface) { + await searchInterface.initialize({ + accessToken: siApiKey, + organizationId: orgId, + organizationEndpoints: { admin: orgEndpont }, + }); + + searchInterface.querySelector('atomic-search-box').redirectionUrl = redirectionUrl; + } + } + + async function initSearchPage() { + const hsp = document.querySelector('atomic-hosted-page#searchPage'); + if (hsp) { + await hsp.initialize({ + accessToken: hspApiKey, + organizationId: orgId, + organizationEndpoints: { admin: orgEndpont }, + pageId: siPageId + }); + } + + await customElements.whenDefined("atomic-search-interface"); + + const searchInterface = document.querySelector("atomic-search-interface#search"); + injectExternalSearchbox('atomicExternalSearchBox'); + + if (searchInterface) { + await searchInterface.initialize({ + accessToken: siApiKey, + organizationId: orgId, + organizationEndpoints: { admin: orgEndpont } + }); + + searchInterface.executeFirstSearch(); + } + } + + if (isSearchPage()) { + initSearchPage(); + } else { + initSearchBox(); + } + }, []); + + return ( + <> + {/* Search Box */} +
+