Core: Fix breadcrumb empty when includePage isn't specified

This commit is contained in:
fuma-nama
2024-09-21 10:58:51 +08:00
parent e45bc67c09
commit 15781f082c
5 changed files with 48 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
Fix breadcrumb empty when `includePage` isn't specified
+1 -1
View File
@@ -89,7 +89,7 @@ function searchPath(
const items: BreadcrumbItem[] = [];
if (separator) items.push({ name: separator });
if (options.includePage)
if (includePage)
items.push({
name: node.index.name,
url: node.index.url,
+1 -3
View File
@@ -51,9 +51,7 @@ export function loadFiles(files: VirtualFile[], options: LoadOptions): Storage {
}
if (file.type === 'meta') {
storage.write(relativePath, file.type, {
data: file.data as MetaData,
});
storage.write(relativePath, file.type, file.data as MetaData);
}
}
+39
View File
@@ -7,6 +7,8 @@ import {
import { describe, expect, test } from 'vitest';
import type { Root } from '@/server/page-tree';
import { findNeighbour } from '@/server/page-tree-utils';
import { PageTree } from '../dist/server';
import { getBreadcrumbItems } from '@/breadcrumb';
test('Find Neighbours', () => {
const tree: Root = {
@@ -113,3 +115,40 @@ describe('Path utilities', () => {
expect(splitPath('/a/c')).toEqual(['a', 'c']);
});
});
test('Breadcrumbs', () => {
const tree: PageTree.Root = {
name: 'Hello World',
children: [
{
type: 'page',
name: 'Hello World',
url: '/docs',
},
{
type: 'page',
name: 'Hello World',
url: '/docs/test',
},
{
type: 'page',
name: 'Fumadocs',
url: '/docs/test2',
},
{
type: 'folder',
name: 'Hello World',
index: {
type: 'page',
name: 'World',
url: '/docs/folder',
},
children: [],
},
],
};
expect(getBreadcrumbItems('/docs/folder', tree)).toStrictEqual([
{ name: 'World', url: '/docs/folder' },
]);
});
+2 -6
View File
@@ -13,9 +13,7 @@ describe('Virtual Storage', () => {
title: 'Hello',
},
});
storage.write('meta.json', 'meta', {
data: {},
});
storage.write('meta.json', 'meta', {});
expect(storage.list().length).toBe(2);
});
@@ -26,9 +24,7 @@ describe('Virtual Storage', () => {
});
test('Nested Directories', () => {
storage.write('dir1/dir2/meta.json', 'meta', {
data: {},
});
storage.write('dir1/dir2/meta.json', 'meta', {});
expect(storage.readDir('dir1')).toBeDefined();
expect(storage.readDir('dir1/dir2')).toBeDefined();