Core & UI: Support separators without name

This commit is contained in:
Fuma Nama
2025-04-25 16:59:44 +08:00
parent d4d1ba72ac
commit 07cd6908c0
5 changed files with 11 additions and 5 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'fumadocs-core': patch
'fumadocs-ui': patch
---
Support separators without name
+1 -1
View File
@@ -66,7 +66,7 @@ export function getBreadcrumbItemsFromPath(
let items: BreadcrumbItem[] = [];
path.forEach((item, i) => {
if (item.type === 'separator' && includeSeparator) {
if (item.type === 'separator' && item.name && includeSeparator) {
items.push({
name: item.name,
});
+1 -1
View File
@@ -31,7 +31,7 @@ export interface Separator {
$id?: string;
type: 'separator';
name: ReactNode;
name?: ReactNode;
icon?: ReactElement;
}
@@ -57,7 +57,7 @@ export interface PageTreeBuilder {
const group = /^\((?<name>.+)\)$/;
const link = /^(?:\[(?<icon>[^\]]+)])?\[(?<name>[^\]]+)]\((?<url>[^)]+)\)$/;
const separator = /^---(?:\[(?<icon>[^\]]+)])?(?<name>.+)---$/;
const separator = /^---(?:\[(?<icon>[^\]]+)])?(?<name>.+)---|^---$/;
const rest = '...' as const;
const restReversed = 'z...a' as const;
const extractPrefix = '...';
@@ -227,7 +227,7 @@ export function SidebarSeparator(props: HTMLAttributes<HTMLParagraphElement>) {
<p
{...props}
className={cn(
'inline-flex items-center gap-2 mb-2 px-2 text-sm font-medium [&_svg]:size-4 [&_svg]:shrink-0',
'inline-flex items-center gap-2 mb-2 px-2 text-sm font-medium empty:mb-0 [&_svg]:size-4 [&_svg]:shrink-0',
props.className,
)}
style={{
@@ -432,7 +432,7 @@ export function SidebarPageTree(props: {
if (item.type === 'separator') {
if (Separator) return <Separator key={i} item={item} />;
return (
<SidebarSeparator key={i} className={cn(i !== 0 && 'mt-8')}>
<SidebarSeparator key={i} className={cn(i !== 0 && 'mt-6')}>
{item.icon}
{item.name}
</SidebarSeparator>