From dbba55606bd8308ee42ff73ea607bfe2743218fe Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 15 Aug 2025 19:21:40 +0600 Subject: [PATCH] website: fix astro not compiling because it can't detect server-side component --- website/src/components/drawer/Drawer.astro | 43 ++++++++++++++ website/src/components/drawer/drawer.tsx | 45 -------------- .../components/navigation/DocSideBar.astro | 58 ++----------------- .../src/components/navigation/TopBar.astro | 6 +- website/src/pages/docs/[...slug]/index.astro | 5 ++ website/src/utils/get-collection.ts | 57 ++++++++++++++++++ 6 files changed, 110 insertions(+), 104 deletions(-) create mode 100644 website/src/components/drawer/Drawer.astro delete mode 100644 website/src/components/drawer/drawer.tsx create mode 100644 website/src/utils/get-collection.ts diff --git a/website/src/components/drawer/Drawer.astro b/website/src/components/drawer/Drawer.astro new file mode 100644 index 00000000..eba12c8c --- /dev/null +++ b/website/src/components/drawer/Drawer.astro @@ -0,0 +1,43 @@ +--- +import { LuMenu } from "react-icons/lu"; +--- + + + +
+ +
+ +
+
+ + diff --git a/website/src/components/drawer/drawer.tsx b/website/src/components/drawer/drawer.tsx deleted file mode 100644 index 4f61cd65..00000000 --- a/website/src/components/drawer/drawer.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import React, { useState } from "react"; -import { LuMenu } from "react-icons/lu"; - - - -interface DrawerProps { - buttonLabel?: React.ReactNode; - children: React.ReactNode; - className?: string; -} - - -export const Drawer: React.FC = ({ - buttonLabel = , - children, - className = "", -}) => { - const [open, setOpen] = useState(false); - - return ( - <> - - - - {/* Drawer */} -
- -
{children}
-
- - ); -}; diff --git a/website/src/components/navigation/DocSideBar.astro b/website/src/components/navigation/DocSideBar.astro index f4456c33..83a08bc9 100644 --- a/website/src/components/navigation/DocSideBar.astro +++ b/website/src/components/navigation/DocSideBar.astro @@ -1,63 +1,13 @@ --- -import type { HTMLAttributes } from "astro/types"; -import type { CollectionEntry } from "astro:content"; -import { getCollection } from "astro:content"; - -interface NavigationItem extends HTMLAttributes<"a"> { - title: string; - tag?: string; -} - -interface NavigationGroup { - title: string; - items: NavigationItem[]; -} +import { getNavigationCollection } from "~/utils/get-collection"; interface Props { - topGroups?: NavigationGroup[]; - classList?: string; - bottomGroups?: NavigationGroup[]; + classList?: string[]; } + const { classList } = Astro.props; -const sortByOrder = (a: CollectionEntry<"docs">, b: CollectionEntry<"docs">) => - a.data.order - b.data.order; - -async function queryCollection(startsWith: string) { - return ( - await getCollection("docs", (entry) => { - if (!entry.id.startsWith(startsWith)) return false; - if (entry.id.split("/").length > 2) return false; - if (entry.id.endsWith("meta")) return false; - return true; - }) - ).toSorted(sortByOrder); -} -const toNavItems = (entries: CollectionEntry<"docs">[]) => - entries.map((page) => ({ - title: page.data.title, - href: `/docs/${page.id}`, - })); - -// Define navigation sections -const sections: [ - string, - string, - (prefix: string) => Promise[]>, -][] = [ - ["Get Started", "get-started/", queryCollection], - ["Developing Plugins", "developing-plugins/", queryCollection], - ["Plugin APIs", "plugin-apis/", queryCollection], - ["Reference", "reference/", queryCollection], -]; - -// Build navigation dynamically -const navigation: NavigationGroup[] = await Promise.all( - sections.map(async ([title, prefix, queryFn]) => ({ - title, - items: toNavItems(await queryFn(prefix)), - })) -); +const navigation = await getNavigationCollection(); const pathname = Astro.url.pathname.endsWith("/") ? Astro.url.pathname.slice(0, -1) diff --git a/website/src/components/navigation/TopBar.astro b/website/src/components/navigation/TopBar.astro index 5b33d80a..cbe03e19 100644 --- a/website/src/components/navigation/TopBar.astro +++ b/website/src/components/navigation/TopBar.astro @@ -3,8 +3,6 @@ import { routes } from "~/collections/app"; import { FaGithub } from "react-icons/fa6"; import SidebarButton from "./sidebar-button"; import Search from "astro-pagefind/components/Search"; -import { Drawer } from "../drawer/drawer"; -import DocSideBar from "./DocSideBar.astro"; const pathname = Astro.url.pathname; --- @@ -16,9 +14,7 @@ const pathname = Astro.url.pathname;
{ pathname.startsWith("/docs") ? ( - - - +
) : ( ) diff --git a/website/src/pages/docs/[...slug]/index.astro b/website/src/pages/docs/[...slug]/index.astro index be019bdb..5a4fbc0b 100644 --- a/website/src/pages/docs/[...slug]/index.astro +++ b/website/src/pages/docs/[...slug]/index.astro @@ -3,6 +3,8 @@ import RootLayout from "layouts/RootLayout.astro"; import type { GetStaticPaths } from "astro"; import { render } from "astro:content"; import { getCollection, getEntry } from "astro:content"; +import DocSideBar from "~/components/navigation/DocSideBar.astro"; +import Drawer from "~/components/drawer/Drawer.astro"; export const getStaticPaths = (async () => { const pages = await getCollection("docs"); @@ -29,5 +31,8 @@ if (page.id.startsWith("components/") || page.id.startsWith("integrations/")) { --- + + + diff --git a/website/src/utils/get-collection.ts b/website/src/utils/get-collection.ts new file mode 100644 index 00000000..9e0ade80 --- /dev/null +++ b/website/src/utils/get-collection.ts @@ -0,0 +1,57 @@ +import type { HTMLAttributes } from "astro/types"; +import { getCollection, type CollectionEntry } from "astro:content"; + +interface NavigationItem extends HTMLAttributes<"a"> { + title: string; + tag?: string; +} + +export interface NavigationGroup { + title: string; + items: NavigationItem[]; +} + +function sortByOrder(a: CollectionEntry<"docs">, b: CollectionEntry<"docs">) { + return a.data.order - b.data.order; +} + +async function queryCollection(startsWith: string) { + return ( + await getCollection("docs", (entry) => { + if (!entry.id.startsWith(startsWith)) return false; + if (entry.id.split("/").length > 2) return false; + if (entry.id.endsWith("meta")) return false; + return true; + }) + ).toSorted(sortByOrder); +} +function toNavItems(entries: CollectionEntry<"docs">[]) { + return entries.map((page) => ({ + title: page.data.title, + href: `/docs/${page.id}`, + })); +} + +export async function getNavigationCollection() { + // Define navigation sections + const sections: [ + string, + string, + (prefix: string) => Promise[]> + ][] = [ + ["Get Started", "get-started/", queryCollection], + ["Developing Plugins", "developing-plugins/", queryCollection], + ["Plugin APIs", "plugin-apis/", queryCollection], + ["Reference", "reference/", queryCollection], + ]; + + // Build navigation dynamically + const navigation: NavigationGroup[] = await Promise.all( + sections.map(async ([title, prefix, queryFn]) => ({ + title, + items: toNavItems(await queryFn(prefix)), + })) + ); + + return navigation; +}