Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thick-panthers-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": patch
---

fix: exclude index pages correctly
2 changes: 1 addition & 1 deletion fixture-docs/doom.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ releaseNotes:
AND project = <%= project %>
unfixed: ''
onlyIncludeRoutes:
- '*/install/**'
- '*/development/component-quickstart/*'
internalRoutes:
- '*/install/prerequisites.mdx'
- '*/internal/*.mdx'
Expand Down
36 changes: 25 additions & 11 deletions src/plugins/auto-sidebar/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,23 @@ const sidebarSorter = (a: DoomSidebar, b: DoomSidebar) => {
return aWeight - bWeight
}

const isExcluded = (
onlyIncludeRoutes: string[],
excludeRoutes: string[],
fileKey: string,
) => {
const included =
!onlyIncludeRoutes.length ||
onlyIncludeRoutes.some((glob) => picomatch.isMatch(fileKey, glob))
return (
!included || excludeRoutes.some((glob) => picomatch.isMatch(fileKey, glob))
)
}

/**
* 1. Split sideMeta into two parts: `index` and `others` and sort `others` by weight
* 2. filter out `excludeRoutes`
* 2. filter only include routes if `onlyIncludeRoutes` is not empty
* 3. filter out `excludeRoutes`
*/
const processSideMeta = (
sideMeta: Array<DoomSidebar | undefined>,
Expand All @@ -67,15 +81,11 @@ const processSideMeta = (
return acc
}

const included =
!onlyIncludeRoutes.length ||
onlyIncludeRoutes.some((glob) =>
picomatch.isMatch(curr._fileKey!, glob),
)

const excluded =
!included ||
excludeRoutes.some((glob) => picomatch.isMatch(curr._fileKey!, glob))
const excluded = isExcluded(
onlyIncludeRoutes,
excludeRoutes,
curr._fileKey,
)

let filePart: string | undefined

Expand Down Expand Up @@ -352,7 +362,11 @@ export async function walk(
excludeRoutes,
)

const sidebars = index ? [index, ...others] : others
const isIndexExcluded =
!!index?._fileKey &&
isExcluded(onlyIncludeRoutes, excludeRoutes, index._fileKey)

const sidebars = index && !isIndexExcluded ? [index, ...others] : others
Comment on lines +365 to +369
Copy link
Member Author

@JounQin JounQin May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isIndexExcluded =
!!index?._fileKey &&
isExcluded(onlyIncludeRoutes, excludeRoutes, index._fileKey)
const sidebars = index && !isIndexExcluded ? [index, ...others] : others
const sidebars = index?._fileKey &&! isExcluded(onlyIncludeRoutes, excludeRoutes, index._fileKey) ? [index, ...others] : others


if (collapsed != null) {
for (const sidebarItem of sidebars) {
Expand Down