@@ -4,6 +4,7 @@ import { type ReactNode, useState } from 'react'
44import type { Folder , Item , Separator } from 'fumadocs-core/page-tree'
55import Link from 'next/link'
66import { usePathname } from 'next/navigation'
7+ import { blockTypeToIconMap } from '@/components/ui/icon-mapping'
78import { i18n } from '@/lib/i18n'
89import { cn } from '@/lib/utils'
910
@@ -41,6 +42,18 @@ function stripLangPrefix(path: string): string {
4142 return path
4243}
4344
45+ /**
46+ * Resolves the provider icon for a tools sidebar item. Tool pages live under
47+ * `/tools/<slug>`, where the slug matches a block type in the icon map.
48+ */
49+ function getToolIcon ( url : string ) {
50+ const path = stripLangPrefix ( url )
51+ if ( ! path . startsWith ( '/tools/' ) ) return null
52+ const slug = path . slice ( '/tools/' . length )
53+ if ( ! slug || slug . includes ( '/' ) ) return null
54+ return blockTypeToIconMap [ slug ] ?? null
55+ }
56+
4457function isActive ( url : string , pathname : string , nested = true ) : boolean {
4558 const normalizedPathname = stripLangPrefix ( pathname )
4659 const normalizedUrl = stripLangPrefix ( url )
@@ -55,7 +68,7 @@ const ITEM_BASE =
5568const ITEM_ACTIVE_MOBILE = 'bg-fd-primary/10 font-medium text-fd-primary'
5669
5770const ITEM_DESKTOP =
58- 'lg:mb-[0.0625rem] lg:block lg: rounded-lg lg:px-2.5 lg:py-1.5 lg:font-normal lg:text-[13px] lg:leading-tight'
71+ 'lg:mb-[0.0625rem] lg:rounded-lg lg:px-2.5 lg:py-1.5 lg:font-normal lg:text-[13px] lg:leading-tight'
5972const ITEM_TEXT = 'lg:text-[#3b3b3b] lg:dark:text-[#cdcdcd]'
6073const ITEM_HOVER = 'lg:hover:bg-[#f2f2f2] lg:dark:hover:bg-[#262626]'
6174const ITEM_ACTIVE =
@@ -69,6 +82,7 @@ const FOLDER_ACTIVE =
6982export function SidebarItem ( { item } : { item : Item } ) {
7083 const pathname = usePathname ( )
7184 const active = isActive ( item . url , pathname , false )
85+ const ToolIcon = getToolIcon ( item . url )
7286
7387 return (
7488 < Link
@@ -83,6 +97,7 @@ export function SidebarItem({ item }: { item: Item }) {
8397 active && ITEM_ACTIVE
8498 ) }
8599 >
100+ { ToolIcon && < ToolIcon className = 'size-[14px] flex-shrink-0' /> }
86101 { item . name }
87102 </ Link >
88103 )
0 commit comments