Skip to content

Commit 26c0195

Browse files
committed
feat: update getDocsLayoutTree
1 parent d22760d commit 26c0195

File tree

1 file changed

+60
-103
lines changed

1 file changed

+60
-103
lines changed

apps/docs/src/lib/pageTree.ts

Lines changed: 60 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -50,121 +50,78 @@ export function cloneRoot(tree: PageTree.Root) {
5050
}
5151

5252
export function getDocsLayoutTree(tree: PageTree.Root, slug: string[]) {
53-
const isApp = slug[0] === 'app';
54-
const isPages = slug[0] === 'pages';
5553
const isV14 = slug[0] === '14';
5654
const isV13 = slug[0] === '13';
55+
const isLatest = !isV14 && !isV13;
56+
5757
const root = cloneRoot(tree);
5858
for (const node of tree.children) {
59-
// App
60-
if (isApp && node.$id === '01-app' && node.type === 'folder') {
61-
const children = node.children;
62-
if (children[0].type === 'folder') {
63-
children[0].defaultOpen = true;
59+
if (isLatest) {
60+
const isPages = slug[0] === 'pages';
61+
// App
62+
if (!isPages && node.$id === '01-app' && node.type === 'folder') {
63+
const children = node.children;
64+
if (children[0].type === 'folder') {
65+
children[0].defaultOpen = true;
66+
}
67+
root.children.push(...children);
6468
}
65-
root.children.push(...children);
66-
}
67-
// Pages
68-
if (isPages && node.$id === '02-pages' && node.type === 'folder') {
69-
const children = node.children;
70-
if (children[0].type === 'folder') {
71-
children[0].defaultOpen = true;
69+
// Pages
70+
if (isPages && node.$id === '02-pages' && node.type === 'folder') {
71+
const children = node.children;
72+
if (children[0].type === 'folder') {
73+
children[0].defaultOpen = true;
74+
}
75+
root.children.push(...children);
7276
}
73-
root.children.push(...children);
74-
}
75-
if (
76-
!isV14 &&
77-
!isV13 &&
78-
!isApp &&
79-
!isPages &&
80-
node.$id &&
81-
node.type === 'folder' &&
82-
!['13', '14'].includes(node.$id)
83-
) {
84-
root.children.push(node);
85-
}
86-
// Architecture && Community
87-
if (
88-
(isApp || isPages) &&
89-
node.$id &&
90-
!['13', '14', '01-app', '02-pages'].includes(node.$id) &&
91-
node.type === 'folder'
92-
) {
93-
root.children.push(node);
94-
}
9577

96-
if (isV13 && node.$id === '13' && node.type === 'folder') {
97-
const children = node.children;
98-
const isApp = slug[1] === 'app';
99-
const isPages = slug[1] === 'pages';
100-
for (const child of children) {
101-
const expandChildren = ['13/02-app', '13/03-pages'];
102-
if (
103-
child.$id &&
104-
child.type === 'folder' &&
105-
expandChildren.includes(child.$id)
106-
) {
107-
for (const item of child.children) {
108-
if (item.type === 'folder') item.defaultOpen = true;
109-
}
110-
}
111-
if (isApp && child.$id === '13/02-app' && child.type === 'folder') {
112-
root.children.push(...child.children);
113-
}
114-
if (isPages && child.$id === '13/03-pages' && child.type === 'folder') {
115-
root.children.push(...child.children);
116-
}
117-
if (!isApp && !isPages && child.type === 'folder' && child.$id) {
118-
root.children.push(child);
119-
}
120-
if (
121-
(isApp || isPages) &&
122-
child.$id &&
123-
!['13/02-app', '13/03-pages'].includes(child.$id) &&
124-
child.type === 'folder'
125-
) {
126-
if (child.$id === '13/01-getting-started') {
127-
child.defaultOpen = true;
128-
}
129-
root.children.push(child);
130-
}
78+
// Architecture && Community
79+
if (
80+
node.$id &&
81+
!['13', '14', '01-app', '02-pages'].includes(node.$id) &&
82+
node.type === 'folder'
83+
) {
84+
root.children.push(node);
13185
}
13286
}
13387

134-
if (isV14 && node.$id === '14' && node.type === 'folder') {
135-
const children = node.children;
136-
const isApp = slug[1] === 'app';
137-
const isPages = slug[1] === 'pages';
138-
for (const child of children) {
139-
const expandChildren = ['14/02-app', '14/03-pages'];
140-
if (
141-
child.$id &&
142-
child.type === 'folder' &&
143-
expandChildren.includes(child.$id)
144-
) {
145-
for (const item of child.children) {
146-
if (item.type === 'folder') item.defaultOpen = true;
88+
if (isV13 || isV14) {
89+
const version = isV14 ? '14' : '13';
90+
const gettingStarted = `${version}/01-getting-started`;
91+
const appFolder = `${version}/02-app`;
92+
const pagesFolder = `${version}/03-pages`;
93+
if (node.$id === version && node.type === 'folder') {
94+
const children = node.children;
95+
96+
const isPages = slug[1] === 'pages';
97+
for (const child of children) {
98+
const expandChildren = [appFolder, pagesFolder];
99+
if (
100+
child.$id &&
101+
child.type === 'folder' &&
102+
expandChildren.includes(child.$id)
103+
) {
104+
for (const item of child.children) {
105+
if (item.type === 'folder') item.defaultOpen = true;
106+
}
147107
}
148-
}
149-
if (isApp && child.$id === '14/02-app' && child.type === 'folder') {
150-
root.children.push(...child.children);
151-
}
152-
if (isPages && child.$id === '14/03-pages' && child.type === 'folder') {
153-
root.children.push(...child.children);
154-
}
155-
if (!isApp && !isPages && child.type === 'folder' && child.$id) {
156-
root.children.push(child);
157-
}
158-
if (
159-
(isApp || isPages) &&
160-
child.$id &&
161-
!['14/02-app', '14/03-pages'].includes(child.$id) &&
162-
child.type === 'folder'
163-
) {
164-
if (child.$id === '14/01-getting-started') {
165-
child.defaultOpen = true;
108+
if (!isPages && child.$id === appFolder && child.type === 'folder') {
109+
root.children.push(...child.children);
110+
}
111+
if (isPages && child.$id === pagesFolder && child.type === 'folder') {
112+
root.children.push(...child.children);
113+
}
114+
115+
if (
116+
child.$id &&
117+
![appFolder, pagesFolder].includes(child.$id) &&
118+
child.type === 'folder'
119+
) {
120+
if (child.$id === gettingStarted) {
121+
child.defaultOpen = true;
122+
}
123+
root.children.push(child);
166124
}
167-
root.children.push(child);
168125
}
169126
}
170127
}

0 commit comments

Comments
 (0)