core: let getPageTreePeers handle i18n (#2441)

* core: let  handle i18n

* core: replace extract from url
This commit is contained in:
wjsoj
2025-10-10 00:05:09 +08:00
committed by GitHub
parent b3d53128db
commit 230c6bf626
2 changed files with 33 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
let `getPageTreePeers` handle i18n
+28 -6
View File
@@ -68,15 +68,37 @@ export function getPageTreeRoots(
* Get other page tree nodes that lives under the same parent
*/
export function getPageTreePeers(
tree: PageTree.Root,
treeOrTrees: PageTree.Root | Record<string, PageTree.Root>,
url: string,
): PageTree.Item[] {
const parent = findParentFromTree(tree, url);
if (!parent) return [];
// Check if it's a single tree or multiple trees (i18n)
if ('children' in treeOrTrees) {
// Single tree case
const tree = treeOrTrees as PageTree.Root;
const parent = findParentFromTree(tree, url);
if (!parent) return [];
return parent.children.filter(
(item) => item.type === 'page' && item.url !== url,
) as PageTree.Item[];
return parent.children.filter(
(item) => item.type === 'page' && item.url !== url,
) as PageTree.Item[];
}
// Multiple trees case
const trees = treeOrTrees as Record<string, PageTree.Root>;
for (const lang in trees) {
const rootTree = trees[lang];
if (rootTree) {
const parent = findParentFromTree(rootTree, url);
if (parent) {
return parent.children.filter(
(item) => item.type === 'page' && item.url !== url,
) as PageTree.Item[];
}
}
}
return [];
}
function findParentFromTree(