From d7ff336ac3942f064a6ff2b79c8bc5619e5a434b Mon Sep 17 00:00:00 2001 From: Jason I Date: Wed, 11 Oct 2023 13:48:25 -0700 Subject: [PATCH] feat: add ai chatbot integration with Kapa script --- src/hooks/useIsDocs.ts | 6 +++++ .../Navbar/MobileSidebar/PrimaryMenu/index.js | 7 ++--- src/theme/Root.js | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/hooks/useIsDocs.ts create mode 100644 src/theme/Root.js diff --git a/src/hooks/useIsDocs.ts b/src/hooks/useIsDocs.ts new file mode 100644 index 0000000000..279d15bc32 --- /dev/null +++ b/src/hooks/useIsDocs.ts @@ -0,0 +1,6 @@ +import { useLocation } from "@docusaurus/router"; + +export function useIsDocs() { + const location = useLocation(); + return location.pathname.startsWith("/docs/"); +} diff --git a/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.js b/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.js index 96670a8950..9df00f78e6 100644 --- a/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.js +++ b/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.js @@ -2,7 +2,8 @@ import React from "react"; import { useThemeConfig } from "@docusaurus/theme-common"; import { useNavbarMobileSidebar } from "@docusaurus/theme-common/internal"; import NavbarItem from "@theme/NavbarItem"; -import { useLocation } from "@docusaurus/router"; +import { useIsDocs } from "@site/src/hooks/useIsDocs"; + function useNavbarItems() { // TODO temporary casting until ThemeConfig type is improved return useThemeConfig().navbar.items; @@ -14,8 +15,8 @@ export default function NavbarMobilePrimaryMenu() { // TODO how can the order be defined for mobile? // Should we allow providing a different list of items? let items = useNavbarItems(); - const location = useLocation(); - const isDocsPage = location.pathname.startsWith("/docs/"); + + const isDocsPage = useIsDocs(); if (isDocsPage) { items = items.filter( diff --git a/src/theme/Root.js b/src/theme/Root.js new file mode 100644 index 0000000000..13335c607b --- /dev/null +++ b/src/theme/Root.js @@ -0,0 +1,26 @@ +import React from "react"; +import Head from "@docusaurus/Head"; +import { useIsDocs } from "@site/src/hooks/useIsDocs"; + +export default function Root({ children }) { + const isDocsPage = useIsDocs(); + + return ( + <> + {isDocsPage && ( + // AI Chatbot Integration via Kapa + +