11import type { PageTree } from 'fumadocs-core/server' ;
2+ import type { RouterType } from './const' ;
3+ import { parseDocId } from './utils' ;
24
35/**
46 * Get other page tree nodes that lives under the same parent
@@ -49,25 +51,34 @@ export function cloneRoot(tree: PageTree.Root) {
4951 } ;
5052}
5153
52- export function getDocsLayoutTree ( tree : PageTree . Root , slug : string [ ] ) {
53- const isV14 = slug [ 0 ] === '14' ;
54- const isV13 = slug [ 0 ] === '13' ;
55- const isLatest = ! isV14 && ! isV13 ;
54+ export function getDocsLayoutTree (
55+ tree : PageTree . Root ,
56+ docId : string ,
57+ routerType : RouterType ,
58+ ) {
59+ const { isV13, isV14, isVLatest, isPages, version } = parseDocId ( docId ) ;
5660
5761 const root = cloneRoot ( tree ) ;
5862 for ( const node of tree . children ) {
59- if ( isLatest ) {
60- const isPages = slug [ 0 ] === 'pages' ;
63+ if ( isVLatest ) {
6164 // App
62- if ( ! isPages && node . $id === '01-app' && node . type === 'folder' ) {
65+ if (
66+ routerType !== 'pages' &&
67+ node . $id === '01-app' &&
68+ node . type === 'folder'
69+ ) {
6370 const children = node . children ;
6471 if ( children [ 0 ] . type === 'folder' ) {
6572 children [ 0 ] . defaultOpen = true ;
6673 }
6774 root . children . push ( ...children ) ;
6875 }
6976 // Pages
70- if ( isPages && node . $id === '02-pages' && node . type === 'folder' ) {
77+ if (
78+ routerType === 'pages' &&
79+ node . $id === '02-pages' &&
80+ node . type === 'folder'
81+ ) {
7182 const children = node . children ;
7283 if ( children [ 0 ] . type === 'folder' ) {
7384 children [ 0 ] . defaultOpen = true ;
@@ -86,14 +97,12 @@ export function getDocsLayoutTree(tree: PageTree.Root, slug: string[]) {
8697 }
8798
8899 if ( isV13 || isV14 ) {
89- const version = isV14 ? '14' : '13' ;
90100 const gettingStarted = `${ version } /01-getting-started` ;
91101 const appFolder = `${ version } /02-app` ;
92102 const pagesFolder = `${ version } /03-pages` ;
93103 if ( node . $id === version && node . type === 'folder' ) {
94104 const children = node . children ;
95105
96- const isPages = slug [ 1 ] === 'pages' ;
97106 for ( const child of children ) {
98107 const expandChildren = [ appFolder , pagesFolder ] ;
99108 if (
@@ -105,10 +114,18 @@ export function getDocsLayoutTree(tree: PageTree.Root, slug: string[]) {
105114 if ( item . type === 'folder' ) item . defaultOpen = true ;
106115 }
107116 }
108- if ( ! isPages && child . $id === appFolder && child . type === 'folder' ) {
117+ if (
118+ routerType !== 'pages' &&
119+ child . $id === appFolder &&
120+ child . type === 'folder'
121+ ) {
109122 root . children . push ( ...child . children ) ;
110123 }
111- if ( isPages && child . $id === pagesFolder && child . type === 'folder' ) {
124+ if (
125+ routerType === 'pages' &&
126+ child . $id === pagesFolder &&
127+ child . type === 'folder'
128+ ) {
112129 root . children . push ( ...child . children ) ;
113130 }
114131
0 commit comments