-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
228 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
[ | ||
{ | ||
"type": "file", | ||
"name": "index", | ||
"label": "Client API Overview" | ||
}, | ||
{ | ||
"type": "file", | ||
"name": "api-runtime", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
[ | ||
{ | ||
"text": "Guide", | ||
"link": "/level1/", | ||
"activeMatch": "/level1/" | ||
"text": "Basic", | ||
"link": "/basic-level-1/", | ||
"activeMatch": "/basic-level-1" | ||
}, | ||
{ | ||
"text": "Index Convention", | ||
"link": "/index-convention-level-1/", | ||
"activeMatch": "/index-convention-level-1" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
"index", | ||
{ | ||
"type": "dir", | ||
"label": "Level 2", | ||
"name": "level-2" | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
...sted-overview/doc/level1/level2/index.mdx → ...sted-overview/doc/basic-level-1/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--- | ||
title: Level 1 | ||
overview: true | ||
--- |
9 changes: 9 additions & 0 deletions
9
e2e/fixtures/nested-overview/doc/basic-level-1/level-2/_meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
"index", | ||
"two", | ||
{ | ||
"type": "dir", | ||
"name": "level-3", | ||
"label": "Level 3" | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
...erview/doc/level1/level2/level3/index.mdx → ...rview/doc/basic-level-1/level-2/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--- | ||
title: Level 2 | ||
overview: true | ||
--- |
1 change: 1 addition & 0 deletions
1
e2e/fixtures/nested-overview/doc/basic-level-1/level-2/level-3/_meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["index", "three"] |
4 changes: 4 additions & 0 deletions
4
e2e/fixtures/nested-overview/doc/basic-level-1/level-2/level-3/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Level 3 | ||
overview: true | ||
--- |
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
e2e/fixtures/nested-overview/doc/index-convention-level-1/_meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
"index", | ||
{ | ||
"type": "dir", | ||
"label": "Level 2", | ||
"name": "level-2" | ||
} | ||
] |
4 changes: 4 additions & 0 deletions
4
e2e/fixtures/nested-overview/doc/index-convention-level-1/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Level 1 | ||
overview: true | ||
--- |
8 changes: 8 additions & 0 deletions
8
e2e/fixtures/nested-overview/doc/index-convention-level-1/level-2/_meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
"two", | ||
{ | ||
"type": "dir", | ||
"name": "level-3", | ||
"label": "Level 3" | ||
} | ||
] |
4 changes: 4 additions & 0 deletions
4
e2e/fixtures/nested-overview/doc/index-convention-level-1/level-2/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Level 2 | ||
overview: true | ||
--- |
1 change: 1 addition & 0 deletions
1
e2e/fixtures/nested-overview/doc/index-convention-level-1/level-2/level-3/_meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["three", "four"] |
1 change: 1 addition & 0 deletions
1
e2e/fixtures/nested-overview/doc/index-convention-level-1/level-2/level-3/four.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Four |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...fixtures/nested-overview/doc/index-convention-level-1/level-2/level-3/three.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Three |
1 change: 1 addition & 0 deletions
1
e2e/fixtures/nested-overview/doc/index-convention-level-1/level-2/two.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
type NormalizedSidebarGroup, | ||
type SidebarDivider, | ||
type SidebarItem, | ||
withBase, | ||
} from '@rspress/shared'; | ||
import { isSidebarDivider } from '../Sidebar/utils'; | ||
|
||
function removeIndex(link: string) { | ||
if (link.endsWith('/index')) { | ||
return link.slice(0, -5); | ||
} | ||
return link; | ||
} | ||
|
||
/** | ||
* @zh_CN 如果 index 在 sidebar items 中, 则返回所有平级 item, 如果 index 在 dir 上, 则返回 items | ||
* @example | ||
*/ | ||
export function findItemByRoutePath( | ||
items: (SidebarItem | NormalizedSidebarGroup | SidebarDivider)[], | ||
routePath: string, | ||
): (SidebarItem | NormalizedSidebarGroup)[] { | ||
function isRoutePathMatch( | ||
item: SidebarItem | NormalizedSidebarGroup | SidebarDivider, | ||
) { | ||
if (isSidebarDivider(item)) { | ||
return false; | ||
} | ||
const withBaseUrl = withBase(item.link); | ||
const removeIndexUrl = removeIndex(withBaseUrl); | ||
const removeBackSlashedRoutePath = routePath.replace(/\/$/, ''); | ||
return ( | ||
// FIXME: 😅 we should refactor all the path logic, /index.html / or no /, l | ||
withBaseUrl === routePath || | ||
removeIndexUrl === routePath || | ||
withBaseUrl === removeBackSlashedRoutePath || | ||
removeIndexUrl === removeBackSlashedRoutePath | ||
); | ||
} | ||
|
||
const matchRoutePathItemIndex = items.findIndex(item => { | ||
return isRoutePathMatch(item); | ||
}); | ||
|
||
if (matchRoutePathItemIndex === -1) { | ||
return items | ||
.map(item => { | ||
if (!('items' in item)) { | ||
return []; | ||
} | ||
return findItemByRoutePath(item.items, routePath); | ||
}) | ||
.flat(); | ||
} | ||
|
||
const matchRoutePathItem = items[matchRoutePathItemIndex] as | ||
| SidebarItem | ||
| NormalizedSidebarGroup; | ||
|
||
const isArray = (i: unknown): i is Array<unknown> => | ||
Array.isArray(i) && i.length >= 1; | ||
|
||
// 1. if isDir(item) return item.items | ||
if ('items' in matchRoutePathItem && isArray(matchRoutePathItem.items)) { | ||
// 2. if isDir(item) && item.items is all files, style is different | ||
if (matchRoutePathItem.items.every(item => !('items' in item))) { | ||
return [matchRoutePathItem]; | ||
} | ||
|
||
return matchRoutePathItem.items.filter(item => !isSidebarDivider(item)) as ( | ||
| SidebarItem | ||
| NormalizedSidebarGroup | ||
)[]; | ||
} | ||
|
||
// 3. if matchRoutePathItem is a item, return other items in same level (/api/index.md is in the child sidebar) | ||
const result = [...items]; | ||
if (!('items' in matchRoutePathItem)) { | ||
result.splice(matchRoutePathItemIndex, 1); | ||
} | ||
const res = result.filter(item => !isSidebarDivider(item)) as ( | ||
| SidebarItem | ||
| NormalizedSidebarGroup | ||
)[]; | ||
|
||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.