mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
Core: Fix wrong index files output in i18n page tree generation
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-core': patch
|
||||
---
|
||||
|
||||
Fix wrong index files output in i18n page tree generation
|
||||
@@ -4,7 +4,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "next build",
|
||||
"dev": "next dev",
|
||||
"dev": "next dev --turbo",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -94,20 +94,13 @@ function buildAll(
|
||||
|
||||
if (node.file.name === 'index') {
|
||||
if (!skipIndex) output.unshift(treeNode);
|
||||
continue;
|
||||
} else {
|
||||
output.push(treeNode);
|
||||
}
|
||||
|
||||
output.push(treeNode);
|
||||
}
|
||||
|
||||
if ('children' in node) {
|
||||
const folder = buildFolderNode(node, false, ctx);
|
||||
|
||||
if (folder.children.length === 0 && folder.index) {
|
||||
output.push(folder.index);
|
||||
} else {
|
||||
folders.push(folder);
|
||||
}
|
||||
folders.push(buildFolderNode(node, false, ctx));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,22 +186,21 @@ function buildFolderNode(
|
||||
ctx.localeStorage?.read(metaPath, 'meta') ??
|
||||
ctx.storage.read(metaPath, 'meta');
|
||||
|
||||
const indexFile = ctx.storage.read(
|
||||
joinPath(folder.file.path, 'index'),
|
||||
'page',
|
||||
);
|
||||
const indexPath = joinPath(folder.file.path, 'index');
|
||||
const indexFile =
|
||||
ctx.localeStorage?.read(indexPath, 'page') ??
|
||||
ctx.storage.read(indexPath, 'page');
|
||||
|
||||
const metadata = meta?.data;
|
||||
const isRoot = metadata?.root ?? isGlobalRoot;
|
||||
const index = indexFile ? buildFileNode(indexFile, ctx) : undefined;
|
||||
|
||||
const addedNodePaths = new Set<string>();
|
||||
let children: PageTree.Node[];
|
||||
|
||||
if (!metadata?.pages) {
|
||||
children = buildAll(folder.children, ctx, !isRoot);
|
||||
} else {
|
||||
const addedNodePaths = new Set<string>();
|
||||
|
||||
const resolved = metadata?.pages?.flatMap<
|
||||
PageTree.Node | typeof rest | typeof restReversed
|
||||
>((item, i) => {
|
||||
@@ -245,7 +237,10 @@ function buildFolderNode(
|
||||
root: metadata?.root,
|
||||
defaultOpen: metadata?.defaultOpen,
|
||||
description: metadata?.description,
|
||||
index,
|
||||
index:
|
||||
isRoot || (indexFile && !addedNodePaths.has(indexFile.file.path))
|
||||
? index
|
||||
: undefined,
|
||||
children,
|
||||
$id: folder.file.path,
|
||||
$ref: !ctx.options.noRef
|
||||
|
||||
@@ -566,18 +566,24 @@ test('Loader: Without meta.json', () => {
|
||||
{
|
||||
"$id": "root",
|
||||
"children": [
|
||||
{
|
||||
"$id": "hello/index.mdx",
|
||||
"name": "Hello",
|
||||
"type": "page",
|
||||
"url": "/hello",
|
||||
},
|
||||
{
|
||||
"$id": "test.mdx",
|
||||
"name": "Hello",
|
||||
"type": "page",
|
||||
"url": "/test",
|
||||
},
|
||||
{
|
||||
"$id": "hello",
|
||||
"children": [],
|
||||
"index": {
|
||||
"$id": "hello/index.mdx",
|
||||
"name": "Hello",
|
||||
"type": "page",
|
||||
"url": "/hello",
|
||||
},
|
||||
"name": "Hello",
|
||||
"type": "folder",
|
||||
},
|
||||
],
|
||||
"name": "",
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ export default async function loader(
|
||||
source,
|
||||
path: filePath,
|
||||
},
|
||||
`invalid frontmatter in ${filePath}:`,
|
||||
`invalid frontmatter in ${filePath}`,
|
||||
)) as Record<string, unknown>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import { ThemeProvider } from 'next-themes';
|
||||
import {
|
||||
import React, {
|
||||
type ComponentPropsWithoutRef,
|
||||
Fragment,
|
||||
lazy,
|
||||
type ReactNode,
|
||||
useMemo,
|
||||
|
||||
Reference in New Issue
Block a user