diff --git a/www/apps/api-reference/app/not-found.tsx b/www/apps/api-reference/app/not-found.tsx new file mode 100644 index 0000000000..c4995885c2 --- /dev/null +++ b/www/apps/api-reference/app/not-found.tsx @@ -0,0 +1,58 @@ +import { AcademicCapSolid, BookOpen } from "@medusajs/icons" +import clsx from "clsx" +import { CardList, H1, H2, MDXComponents, SimilarPages } from "docs-ui" +import { config } from "../config" + +const P = MDXComponents.p as React.FC< + React.HTMLAttributes +> +const A = MDXComponents.a as React.FC< + React.AnchorHTMLAttributes +> + +const NotFoundPage = () => { + return ( +
+

Page Not Found

+

The page you were looking for isn't available.

+

+ If you're looking for Medusa v1 documentation, it's been moved + to docs.medusajs.com/v1. +

+

+ If you think this is a mistake, please{" "} + + report this issue on GitHub + + . +

+ +

Other Resources

+ +
+ ) +} + +export default NotFoundPage diff --git a/www/apps/book/app/_not-found.mdx b/www/apps/book/app/_not-found.mdx index c023cec3cf..40256b5ff3 100644 --- a/www/apps/book/app/_not-found.mdx +++ b/www/apps/book/app/_not-found.mdx @@ -2,7 +2,7 @@ hide_content_menu: true --- -import { CardList, H1 } from "docs-ui" +import { CardList, H1, SimilarPages } from "docs-ui" import { BookOpen, AcademicCapSolid, @@ -22,6 +22,10 @@ If you're looking for Medusa v1 documentation, it's been moved to [docs.medusajs If you think this is a mistake, please [report this issue on GitHub](https://github.com/medusajs/medusa/issues/new?assignees=&labels=type%3A+docs&template=docs.yml). + + +## Other Resources + + +## Other Resources + + +## Other Resources + + +## Other Resources + + +## Other Resources + +> +const Ul = MDXComponents.ul as React.FC> +const Li = MDXComponents.li as React.FC> +const A = MDXComponents.a as React.FC< + React.AnchorHTMLAttributes +> + +export const SimilarPages = () => { + const similarPages = useSimilarPages() + + if (!similarPages.length) { + return null + } + + return ( +
+

Similar Pages

+

Maybe you're looking for:

+
    + {similarPages.map((page) => ( +
  • + {page.title} +
  • + ))} +
+
+ ) +} diff --git a/www/packages/docs-ui/src/components/index.ts b/www/packages/docs-ui/src/components/index.ts index 35c0944daf..d4fc8fbe90 100644 --- a/www/packages/docs-ui/src/components/index.ts +++ b/www/packages/docs-ui/src/components/index.ts @@ -76,6 +76,7 @@ export * from "./Search/Suggestions/Item" export * from "./Select" export * from "./Sidebar" export * from "./Sidebar/Item" +export * from "./SimilarPages" export * from "./SourceCodeLink" export * from "./SplitLists" export * from "./Table" diff --git a/www/packages/docs-ui/src/hooks/index.ts b/www/packages/docs-ui/src/hooks/index.ts index cf8192a6a7..782877f679 100644 --- a/www/packages/docs-ui/src/hooks/index.ts +++ b/www/packages/docs-ui/src/hooks/index.ts @@ -16,4 +16,5 @@ export * from "./use-request-runner" export * from "./use-scroll-utils" export * from "./use-search-navigation" export * from "./use-select" +export * from "./use-similar-pages" export * from "./use-tabs" diff --git a/www/packages/docs-ui/src/hooks/use-similar-pages/index.tsx b/www/packages/docs-ui/src/hooks/use-similar-pages/index.tsx new file mode 100644 index 0000000000..565473c635 --- /dev/null +++ b/www/packages/docs-ui/src/hooks/use-similar-pages/index.tsx @@ -0,0 +1,46 @@ +"use client" + +import { usePathname } from "next/navigation" +import { useSearch } from "../../providers" +import { useEffect, useState } from "react" +import { HitType } from "../../components" + +type SimilarPage = { + id: string + title: string + url: string +} + +export const useSimilarPages = () => { + const pathname = usePathname() + const { searchClient, selectedIndex } = useSearch() + const [similarPages, setSimilarPages] = useState([]) + + useEffect(() => { + void searchClient + .search({ + requests: [ + { + query: pathname.split("/").join(" ").trim(), + indexName: selectedIndex, + hitsPerPage: 3, + distinct: true, + }, + ], + }) + .then(({ results }) => { + const hits = "hits" in results[0] ? results[0].hits : [] + const pages = hits.map((hit) => ({ + id: hit.objectID, + title: hit.hierarchy.lvl1 || hit.hierarchy.lvl0 || "Untitled", + url: hit.url, + })) + setSimilarPages(pages) + }) + .catch(() => { + setSimilarPages([]) + }) + }, [pathname, searchClient]) + + return similarPages +} diff --git a/www/packages/docs-ui/src/providers/Search/index.tsx b/www/packages/docs-ui/src/providers/Search/index.tsx index 4a7c40b47c..fa66ea8130 100644 --- a/www/packages/docs-ui/src/providers/Search/index.tsx +++ b/www/packages/docs-ui/src/providers/Search/index.tsx @@ -80,12 +80,10 @@ export const SearchProvider = ({ const modalRef = useRef(null) - const searchClient: SearchClient = useMemo(() => { - const algoliaClient = algoliasearch(algolia.appId, algolia.apiKey) - return { - ...algoliaClient, - } - }, [algolia.appId, algolia.apiKey]) + const searchClient: SearchClient = useMemo( + () => algoliasearch(algolia.appId, algolia.apiKey), + [algolia.appId, algolia.apiKey] + ) useEffect(() => { if (initialDefaultIndex !== selectedIndex) {