From e810634fe13d74cb4903eee9dc59fb4bfec58d68 Mon Sep 17 00:00:00 2001 From: Shanu Goyanka Date: Mon, 30 Jun 2025 16:19:11 +0530 Subject: [PATCH 1/2] feat(docs): Added gloval search for uagents, network and innovation lab --- .../components/instant-algolia-search.tsx | 164 ++++++------------ theme/fetch-ai-docs/components/navbar.tsx | 8 +- 2 files changed, 55 insertions(+), 117 deletions(-) diff --git a/theme/fetch-ai-docs/components/instant-algolia-search.tsx b/theme/fetch-ai-docs/components/instant-algolia-search.tsx index fb93f077c..8a30070b3 100644 --- a/theme/fetch-ai-docs/components/instant-algolia-search.tsx +++ b/theme/fetch-ai-docs/components/instant-algolia-search.tsx @@ -24,10 +24,10 @@ type MyItem = NormalItem & { }; const searchClient = algoliasearch( - `${process.env.NEXT_PUBLIC_ALGOLIA_APP_ID}`, - `${process.env.NEXT_PUBLIC_ALGOLIA_API_KEY}`, + `4MNO2TMYQ5`, //4MNO2TMYQ5 + `79f05f43517b76c1b8af1c6c667dbaba`, ); -const indexName = `${process.env.NEXT_PUBLIC_ALGOLIA_INDEX}`; +const indexName = `Fetch ai Docs`; const markdownToHTML = (markdownString) => { return remark().use(remarkHTML).processSync(markdownString).toString(); @@ -69,8 +69,8 @@ export const InstantAlgoliaSearch = ({ } } - const actualPath = path.split("/docs")[1]; - router.push(actualPath); + // const actualPath = path.split("/docs")[1]; + router.push(path); setModalIsOpen(false); }; @@ -107,121 +107,59 @@ export const InstantAlgoliaSearch = ({ ); }; - const directoriesWithTags = directories - .filter((directory) => !!("tags" in directory)) - .map(({ route, tags }) => ({ route, tags })); - const CustomHits = connectHits(({ hits }) => { if (hits.length <= 0) { return ; } - const groupedHits = {}; - - for (const hit of hits) { - const route = hit.path.split("#")[0]; - - if (!groupedHits[route]) { - groupedHits[route] = []; - } - - groupedHits[route].push(hit); - } - - const tagColors = [ - "bg-indigo", - "bg-orange", - "bg-light-green", - "bg-blue-150", - "bg-yellow-150", - "bg-red-150", - ]; - return ( -
- {Object.entries(groupedHits).map(([route, hitsForRoute]) => ( -
-
- -
{route.split("/").pop()}
- {directoriesWithTags.map((directory) => { - if (route.includes(directory.route)) { - return ( -
-
- {directory.tags.slice(0, 3).map((tag, index) => ( - - {tag} - - ))} -
-
- ); - } - return null; - })} -
-
- -
    - { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (hitsForRoute as any[]).map((hit) => ( -
  • -
    onClickSearchResult(hit.path)} - > -
    -
    - {hit.title.replaceAll("#", "")} -
    - - {hit.content.length > 0 && ( -
    - -
    500 ? "..." : ""}`, - }} - /> - -
    - )} -
    - {hit.path - .replace(/^\/docs\//, "") - .split("/") - .join(" > ")} -
    -
    +
    +
      + {hits.map((hit) => ( +
    • +
      onClickSearchResult(hit.url)} + > +
      +
      + {hit.anchor || hit.hierarchy.lvl1 || hit.hierarchy.lvl0} +
      + + {hit.content && hit.content.length > 0 && ( +
      + +
      500 ? "..." : ""}`, + }} + /> +
      -
      -
    • - )) - } -
    -
    - ))} + )} +
    + {hit.url} +
    +
    +
    +
    +
  • + ))} +
); }); diff --git a/theme/fetch-ai-docs/components/navbar.tsx b/theme/fetch-ai-docs/components/navbar.tsx index f741b46ea..863406fde 100644 --- a/theme/fetch-ai-docs/components/navbar.tsx +++ b/theme/fetch-ai-docs/components/navbar.tsx @@ -270,11 +270,11 @@ export function Navbar({ items }: NavBarProps): ReactElement { })}
- {/*
+
{renderComponent(config.search.component, { - directories: flatDirectories, + directories: [], })} -
*/} +
{/*
{openOs && ( @@ -306,7 +306,7 @@ export function Navbar({ items }: NavBarProps): ReactElement {
{/*
{renderComponent(config.search.component, { - directories: flatDirectories, + directories: [], // className: "md:nx-hidden nx-mt-6 nx-mb-2", })}
*/} From f086df5cf3a8a52304e5e69be712d43b630075f0 Mon Sep 17 00:00:00 2001 From: Shanu Goyanka Date: Mon, 30 Jun 2025 16:27:07 +0530 Subject: [PATCH 2/2] Fixed linting issues --- .../components/instant-algolia-search.tsx | 11 +---------- theme/fetch-ai-docs/constants.tsx | 4 ++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/theme/fetch-ai-docs/components/instant-algolia-search.tsx b/theme/fetch-ai-docs/components/instant-algolia-search.tsx index 8a30070b3..8961444a3 100644 --- a/theme/fetch-ai-docs/components/instant-algolia-search.tsx +++ b/theme/fetch-ai-docs/components/instant-algolia-search.tsx @@ -12,17 +12,12 @@ import { getComponents } from "../mdx-components"; import { useConfig } from "../contexts"; import { remark } from "remark"; import remarkHTML from "remark-html"; -import type { Item as NormalItem } from "nextra/normalize-pages"; import { Input } from "./input"; import Modal from "./search-model"; import { DarkShortcut, Shortcut } from "src/icons/shared-icons"; import { useTheme } from "next-themes"; import { ThemeMode } from "../helpers"; -type MyItem = NormalItem & { - tags?: string[]; -}; - const searchClient = algoliasearch( `4MNO2TMYQ5`, //4MNO2TMYQ5 `79f05f43517b76c1b8af1c6c667dbaba`, @@ -33,11 +28,7 @@ const markdownToHTML = (markdownString) => { return remark().use(remarkHTML).processSync(markdownString).toString(); }; -export const InstantAlgoliaSearch = ({ - directories, -}: { - directories: MyItem[]; -}) => { +export const InstantAlgoliaSearch = () => { const config = useConfig(); const router = useRouter(); const [modalIsOpen, setModalIsOpen] = useState(false); diff --git a/theme/fetch-ai-docs/constants.tsx b/theme/fetch-ai-docs/constants.tsx index 8bf2e0b40..c7a3133f8 100644 --- a/theme/fetch-ai-docs/constants.tsx +++ b/theme/fetch-ai-docs/constants.tsx @@ -268,8 +268,8 @@ export const DEFAULT_THEME: DocsThemeConfig = { ), }, search: { - component: function Search({ directories }) { - return ; + component: function Search() { + return ; }, emptyResult: (