diff --git a/apify-docs-theme/src/config.js b/apify-docs-theme/src/config.js index d10c339f2c..b02fdecbf4 100644 --- a/apify-docs-theme/src/config.js +++ b/apify-docs-theme/src/config.js @@ -315,37 +315,37 @@ const plugins = [ ]; const scripts = [ - { - src: 'https://widget.kapa.ai/kapa-widget.bundle.js', - 'data-website-id': 'a9937f98-9c9d-44d9-a433-fec4cb1c114d', - 'data-project-name': 'Apify', - 'data-modal-title': 'Apify AI Assistant', - 'data-project-color': '#666666', - 'data-button-hide': 'true', - 'data-search-mode-enabled': 'true', - 'data-search-include-source-names': '["Docs"]', - 'data-project-logo': 'https://apify.com/img/apify-logo/logomark-32x32.svg', - 'data-modal-example-questions': 'How to run an Actor?,Create a version of an Actor?', - 'data-modal-override-open-id': 'ask-ai-input', - 'data-modal-override-open-class': 'search-input', - 'data-font-size-xs': '1.2rem', - 'data-font-size-sm': '1.4rem', - 'data-font-size-md': '1.6rem', - 'data-font-size-lg': '1.8rem', - 'data-font-size-xl': '2.0rem', - async: true, - }, - { - src: 'https://cdn.jsdelivr.net/npm/@inkeep/cxkit-js@0.5/dist/embed.js', - type: 'module', - async: true, - }, + // { + // src: 'https://widget.kapa.ai/kapa-widget.bundle.js', + // 'data-website-id': 'a9937f98-9c9d-44d9-a433-fec4cb1c114d', + // 'data-project-name': 'Apify', + // 'data-modal-title': 'Apify AI Assistant', + // 'data-project-color': '#666666', + // 'data-button-hide': 'true', + // 'data-search-mode-enabled': 'true', + // 'data-search-include-source-names': '["Docs"]', + // 'data-project-logo': 'https://apify.com/img/apify-logo/logomark-32x32.svg', + // 'data-modal-example-questions': 'How to run an Actor?,Create a version of an Actor?', + // 'data-modal-override-open-id': 'ask-ai-input', + // 'data-modal-override-open-class': 'search-input', + // 'data-font-size-xs': '1.2rem', + // 'data-font-size-sm': '1.4rem', + // 'data-font-size-md': '1.6rem', + // 'data-font-size-lg': '1.8rem', + // 'data-font-size-xl': '2.0rem', + // async: true, + // }, + // { + // src: 'https://cdn.jsdelivr.net/npm/@inkeep/cxkit-js@0.5/dist/embed.js', + // type: 'module', + // async: true, + // }, ]; const customFields = { - inkeepApiKey: process.env.LOCALHOST || process.env.DEV - ? 'bbbb9f1001a9b66f282431a80bb743a24e2bdefb85d4f1e4' // development, works with localhost - : '8af30e40009f26622237f75aab8256064c26a3063717c48a', // production, only works on apify.com (any subdomain) + // inkeepApiKey: process.env.LOCALHOST || process.env.DEV + // ? 'bbbb9f1001a9b66f282431a80bb743a24e2bdefb85d4f1e4' // development, works with localhost + // : '8af30e40009f26622237f75aab8256064c26a3063717c48a', // production, only works on apify.com (any subdomain) }; module.exports = { diff --git a/apify-docs-theme/src/theme/SearchBar/index.js b/apify-docs-theme/src/theme/SearchBar/index.js index 1c30dc7ed1..e5d4ae8714 100644 --- a/apify-docs-theme/src/theme/SearchBar/index.js +++ b/apify-docs-theme/src/theme/SearchBar/index.js @@ -1,14 +1,15 @@ // eslint-disable-next-line simple-import-sort/imports import BrowserOnly from '@docusaurus/BrowserOnly'; import RouterLink from '@docusaurus/Link'; -// import { useHistory, useLocation } from '@docusaurus/router'; +import { useHistory, useLocation } from '@docusaurus/router'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; -import clsx from 'clsx'; -import React, { useEffect, useState } from 'react'; -import { useHotkeys } from 'react-hotkeys-hook'; +// import clsx from 'clsx'; +// import React, { useEffect, useState } from 'react'; +import React, { useCallback } from 'react'; +// import { useHotkeys } from 'react-hotkeys-hook'; -// import { ApifySearch } from '@apify/docs-search-modal'; -import { ControlKeyIcon, SearchIcon } from '@apify/docs-search-modal/dist/utils/icons'; +import { ApifySearch } from '@apify/docs-search-modal'; +// import { ControlKeyIcon, SearchIcon } from '@apify/docs-search-modal/dist/utils/icons'; // needs to be imported as the last thing, so that it can override the default styles // TODO: update simple-import-sort to allow importing css as last. @@ -43,201 +44,201 @@ export function Link(props) { return {props.children}; } -// export default function SearchBar({ onClick }) { -// const { siteConfig } = useDocusaurusContext(); -// const location = useLocation(); -// const history = useHistory(); -// -// const navigate = useCallback((href) => { -// const shortHref = href.substring('https://docs.apify.com'.length); -// -// if (matchesCurrentInstance(shortHref, siteConfig.baseUrl)) { -// return history.push(shortHref); -// } -// return window.location.assign(href); -// }, [history, siteConfig.baseUrl]); -// -// const getVersion = useCallback(() => { -// const match = location.pathname.match(/\/(\d+\.\d+|next)/); -// -// return match ? match[1] : 'latest'; -// }, [location]); -// -// return ( -// -// {() => ( -// -// -// -// )} -// -// ); -// } - export default function SearchBar({ onClick }) { - const [variant, setVariant] = useState(null); - const [opened, setOpened] = useState(false); const { siteConfig } = useDocusaurusContext(); - const { inkeepApiKey } = siteConfig.customFields; - - useEffect(() => { - const storedVariant = localStorage.getItem('search-provider'); - - if (storedVariant) { - setVariant(storedVariant); - } else { - const assignedVariant = Math.random() < 0.5 ? 'inkeep' : 'kapa'; - localStorage.setItem('search-provider', assignedVariant); - setVariant(assignedVariant); - } - }, []); + const location = useLocation(); + const history = useHistory(); - onClick = () => { - if (opened) { - return; - } + const navigate = useCallback((href) => { + const shortHref = href.substring('https://docs.apify.com'.length); - setOpened(true); - - if (variant === 'kapa') { - if (window.Kapa && typeof window.Kapa.open === 'function') { - window.Kapa.open(); - window.Kapa('onModalClose', () => { - setOpened(false); - }); - } else { - console.error('Kapa.ai widget is not available.'); - } - return; + if (matchesCurrentInstance(shortHref, siteConfig.baseUrl)) { + return history.push(shortHref); } + return window.location.assign(href); + }, [history, siteConfig.baseUrl]); - if (variant !== 'inkeep') { - console.warn('Unknown search variant:', variant); - return; - } + const getVersion = useCallback(() => { + const match = location.pathname.match(/\/(\d+\.\d+|next)/); - if (window.Inkeep) { - const config = { - baseSettings: { - apiKey: inkeepApiKey, - organizationDisplayName: 'Apify', - primaryBrandColor: '#FF9013', - transformSource: (source) => { - function getTabForSource(src) { - if (src.url.includes('help.apify.com')) { - return 'Help'; - } - return 'Docs'; - } - - if (source.contentType === 'documentation') { - return { - ...source, - tabs: [...(source.tabs || []), getTabForSource(source)], - }; - } - return source; - }, - trigger: { - disableDefaultTrigger: true, - }, - theme: { - styles: [ - { - key: 'main', - type: 'link', - value: '/inkeep-overrides.css', - }, - ], - }, - }, - modalSettings: { - onOpenChange: handleOpenChange, - }, - searchSettings: { - tabs: [ - ['Docs', { isAlwaysVisible: true }], - 'GitHub', - 'All', - ], - }, - aiChatSettings: { - aiAssistantAvatar: 'https://intercom.help/apify/assets/favicon', - chatSubjectName: 'Apify', - exampleQuestions: [ - 'What is an Actor?', - 'How to use my own proxies?', - 'How to integrate Apify Actors with GitHub?', - 'How to share key-value stores between runs?', - ], - getHelpOptions: [ - { - action: { - type: 'open_link', - url: 'https://apify.com/contact', - }, - icon: { - builtIn: 'IoChatbubblesOutline', - }, - name: 'Contact Us', - }, - ], - }, - defaultView: 'chat', - }; - const modal = window.Inkeep.ModalSearchAndChat(config); - - function handleOpenChange(newOpen) { - modal.update({ modalSettings: { isOpen: newOpen } }); - setOpened(newOpen); - } - - modal.update({ modalSettings: { isOpen: true } }); - } else { - console.error('Inkeep widget is not available.'); - } - }; - - const [key, setKey] = useState(null); - - useEffect(() => { - if (typeof navigator !== 'undefined') { - const isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform); - setKey(isMac ? '⌘' : 'ctrl'); - } - }, []); - - useHotkeys('mod+k, /', () => { - onClick(); - }, { preventDefault: true }); + return match ? match[1] : 'latest'; + }, [location]); return ( {() => ( - - - - Search - - - {key !== null && (<> - - {key === 'ctrl' ? : key} - - K - >)} - - - + )} ); } + +// export default function SearchBar({ onClick }) { +// const [variant, setVariant] = useState(null); +// const [opened, setOpened] = useState(false); +// const { siteConfig } = useDocusaurusContext(); +// const { inkeepApiKey } = siteConfig.customFields; +// +// useEffect(() => { +// const storedVariant = localStorage.getItem('search-provider'); +// +// if (storedVariant) { +// setVariant(storedVariant); +// } else { +// const assignedVariant = Math.random() < 0.5 ? 'inkeep' : 'kapa'; +// localStorage.setItem('search-provider', assignedVariant); +// setVariant(assignedVariant); +// } +// }, []); +// +// onClick = () => { +// if (opened) { +// return; +// } +// +// setOpened(true); +// +// if (variant === 'kapa') { +// if (window.Kapa && typeof window.Kapa.open === 'function') { +// window.Kapa.open(); +// window.Kapa('onModalClose', () => { +// setOpened(false); +// }); +// } else { +// console.error('Kapa.ai widget is not available.'); +// } +// return; +// } +// +// if (variant !== 'inkeep') { +// console.warn('Unknown search variant:', variant); +// return; +// } +// +// if (window.Inkeep) { +// const config = { +// baseSettings: { +// apiKey: inkeepApiKey, +// organizationDisplayName: 'Apify', +// primaryBrandColor: '#FF9013', +// transformSource: (source) => { +// function getTabForSource(src) { +// if (src.url.includes('help.apify.com')) { +// return 'Help'; +// } +// return 'Docs'; +// } +// +// if (source.contentType === 'documentation') { +// return { +// ...source, +// tabs: [...(source.tabs || []), getTabForSource(source)], +// }; +// } +// return source; +// }, +// trigger: { +// disableDefaultTrigger: true, +// }, +// theme: { +// styles: [ +// { +// key: 'main', +// type: 'link', +// value: '/inkeep-overrides.css', +// }, +// ], +// }, +// }, +// modalSettings: { +// onOpenChange: handleOpenChange, +// }, +// searchSettings: { +// tabs: [ +// ['Docs', { isAlwaysVisible: true }], +// 'GitHub', +// 'All', +// ], +// }, +// aiChatSettings: { +// aiAssistantAvatar: 'https://intercom.help/apify/assets/favicon', +// chatSubjectName: 'Apify', +// exampleQuestions: [ +// 'What is an Actor?', +// 'How to use my own proxies?', +// 'How to integrate Apify Actors with GitHub?', +// 'How to share key-value stores between runs?', +// ], +// getHelpOptions: [ +// { +// action: { +// type: 'open_link', +// url: 'https://apify.com/contact', +// }, +// icon: { +// builtIn: 'IoChatbubblesOutline', +// }, +// name: 'Contact Us', +// }, +// ], +// }, +// defaultView: 'chat', +// }; +// const modal = window.Inkeep.ModalSearchAndChat(config); +// +// function handleOpenChange(newOpen) { +// modal.update({ modalSettings: { isOpen: newOpen } }); +// setOpened(newOpen); +// } +// +// modal.update({ modalSettings: { isOpen: true } }); +// } else { +// console.error('Inkeep widget is not available.'); +// } +// }; +// +// const [key, setKey] = useState(null); +// +// useEffect(() => { +// if (typeof navigator !== 'undefined') { +// const isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform); +// setKey(isMac ? '⌘' : 'ctrl'); +// } +// }, []); +// +// useHotkeys('mod+k, /', () => { +// onClick(); +// }, { preventDefault: true }); +// +// return ( +// +// {() => ( +// +// +// +// +// Search +// +// +// {key !== null && (<> +// +// {key === 'ctrl' ? : key} +// +// K +// >)} +// +// +// +// +// )} +// +// ); +// }