mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
Core: Fallback to page icon when metadata doesn't exist
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-core': patch
|
||||
---
|
||||
|
||||
Page Tree Builder: Fallback to page icon when metadata doesn't exist
|
||||
@@ -17,7 +17,7 @@ export const DynamicLink = forwardRef<HTMLAnchorElement, DynamicLinkProps>(
|
||||
const params = useParams();
|
||||
|
||||
const url = useMemo(() => {
|
||||
return href?.replace(/\[.*\]/, (key) => {
|
||||
return href?.replace(/\[.*]/, (key) => {
|
||||
const mappedKey = key.slice(1, -1);
|
||||
const value = mappedKey in params ? params[mappedKey] : 'undefined';
|
||||
|
||||
|
||||
@@ -130,14 +130,13 @@ function resolveFolderItem(
|
||||
return [ctx.options.attachFile?.(node) ?? node];
|
||||
}
|
||||
|
||||
const isExcept = item.startsWith('!'),
|
||||
isExtract = item.startsWith('...');
|
||||
|
||||
let filename = item;
|
||||
const isExcept = item.startsWith('!');
|
||||
if (isExcept) {
|
||||
filename = item.slice(1);
|
||||
}
|
||||
|
||||
const isExtract = item.startsWith('...');
|
||||
if (isExtract) {
|
||||
} else if (isExtract) {
|
||||
filename = item.slice(3);
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ function resolveFolderItem(
|
||||
|
||||
function buildFolderNode(
|
||||
folder: Folder,
|
||||
defaultIsRoot: boolean,
|
||||
isGlobalRoot: boolean,
|
||||
ctx: PageTreeBuilderContext,
|
||||
): PageTree.Folder {
|
||||
const metaPath = resolvePath(folder.file.path, 'meta');
|
||||
@@ -177,9 +176,9 @@ function buildFolderNode(
|
||||
let children: PageTree.Node[];
|
||||
|
||||
if (!meta) {
|
||||
children = buildAll(folder.children, ctx, !defaultIsRoot);
|
||||
children = buildAll(folder.children, ctx, !isGlobalRoot);
|
||||
} else {
|
||||
const isRoot = metadata?.root ?? defaultIsRoot;
|
||||
const isRoot = metadata?.root ?? isGlobalRoot;
|
||||
const addedNodePaths = new Set<string>();
|
||||
|
||||
const resolved = metadata?.pages?.flatMap<PageTree.Node | '...'>((item) => {
|
||||
@@ -206,7 +205,7 @@ function buildFolderNode(
|
||||
const node: PageTree.Folder = {
|
||||
type: 'folder',
|
||||
name: metadata?.title ?? index?.name ?? pathToName(folder.file.name, true),
|
||||
icon: ctx.options.resolveIcon?.(metadata?.icon),
|
||||
icon: ctx.options.resolveIcon?.(metadata?.icon) ?? index?.icon,
|
||||
root: metadata?.root,
|
||||
defaultOpen: metadata?.defaultOpen,
|
||||
index,
|
||||
|
||||
Reference in New Issue
Block a user