Skip to content

Commit 97d6bda

Browse files
committed
index1
1 parent 76b91ac commit 97d6bda

1 file changed

Lines changed: 30 additions & 13 deletions

File tree

src/theme/DocSidebarItem/Category/index.tsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,39 @@ import {
2525
Github,
2626
PanelRight,
2727
Code2,
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29+
School,
2830
Zap,
2931
Container,
3032
ChevronDown,
33+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
34+
ChevronUp,
3135
ChevronRight,
3236
} from "lucide-react";
3337
import Link from "@docusaurus/Link";
3438
import clsx from "clsx";
3539
import { DocSidebarItemCategoryProps } from "../types";
3640
import styles from "./styles.module.css";
3741

38-
function itemHasHref(
39-
item: DocSidebarItemCategoryProps["item"]["items"][number],
40-
): item is Extract<
41-
DocSidebarItemCategoryProps["item"]["items"][number],
42-
{ href: string }
43-
> {
44-
return "href" in item && typeof item.href === "string";
42+
// Recursively get all doc ids from sidebar
43+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
44+
function getAllDocIds(items: any[]): string[] {
45+
let ids: string[] = [];
46+
for (const item of items) {
47+
if (item.type === "category") {
48+
// Include the category's href if it exists
49+
if (item.href) {
50+
ids.push(item.href);
51+
}
52+
ids = [...ids, ...getAllDocIds(item.items)];
53+
} else if (item.type === "doc") {
54+
ids.push(item.id);
55+
} else if (item.href) {
56+
// Handle link type items
57+
ids.push(item.href);
58+
}
59+
}
60+
return ids;
4561
}
4662

4763
const getIcon = (
@@ -58,9 +74,7 @@ const getIcon = (
5874
} else if (label.includes("Next.js") || className?.includes("nextjs")) {
5975
return <Zap className={`${styles.categoryIcon} ${styles.nextjsIcon}`} />;
6076
} else if (label.includes("Docker") || className?.includes("docker")) {
61-
return (
62-
<Container className={`${styles.categoryIcon} ${styles.dockerIcon}`} />
63-
);
77+
return <Container className={`${styles.categoryIcon} ${styles.dockerIcon}`} />;
6478
} else if (label.includes("Technical") || className?.includes("technical")) {
6579
return (
6680
<PanelRight
@@ -78,6 +92,10 @@ function DocSidebarItemCategory({
7892
onItemClick,
7993
activePath,
8094
level = 0,
95+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
96+
index,
97+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
98+
...props
8199
}: DocSidebarItemCategoryProps): React.ReactNode {
82100
const { items, label, collapsible, className, href } = item;
83101

@@ -104,14 +122,13 @@ function DocSidebarItemCategory({
104122
// Don't collapse if this category or any of its items are active
105123
const hasActiveItem = items.some((item) => {
106124
// Check for direct href match
107-
if (itemHasHref(item) && isSamePath(item.href, activePath)) {
125+
if (item.href && isSamePath(item.href, activePath)) {
108126
return true;
109127
}
110128
// Check for nested items (for categories like SQL Basics)
111129
if (item.type === "category" && item.items) {
112130
return item.items.some(
113-
(subItem) =>
114-
itemHasHref(subItem) && isSamePath(subItem.href, activePath),
131+
(subItem) => subItem.href && isSamePath(subItem.href, activePath),
115132
);
116133
}
117134
return false;

0 commit comments

Comments
 (0)