Skip to content

Commit

Permalink
Add alias for docs sidebar filtering (#2581)
Browse files Browse the repository at this point in the history
* add alias for docs sidebar filtering

* remove extra log
  • Loading branch information
im2nguyen authored Oct 3, 2024
1 parent 24b378a commit dbd10fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/sidebar/helpers/get-filtered-nav-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ export const getFilteredNavItems = (
?.toLowerCase()
.includes(filterValue.toLowerCase())

// Check and filter alias
const hasAlias = item.hasOwnProperty('alias')
if (hasAlias) {
const doesAliasMatchFilter = (
item as SubmenuNavItemWithMetaData | LinkNavItemWithMetaData
).alias
?.toLowerCase()
.includes(filterValue.toLowerCase())

// Add to filtered items if filter value is in alias
if (doesAliasMatchFilter) {
filteredItems.push({ ...item, matchesFilter: true })
}
}

/**
* If an item's title matches the filter, we want to include it and its
* children in the filter results. `matchesFilter` is added to all items
Expand Down
1 change: 1 addition & 0 deletions src/components/sidebar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface HeadingNavItem {
interface BaseNavItem {
badge?: SidebarNavMenuItemBadgeProps
hidden?: boolean
alias?: string
title: string
}

Expand Down

0 comments on commit dbd10fc

Please sign in to comment.