Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the exact property behaviour to give more flexibility to the matches #14

Merged
merged 1 commit into from
Jan 6, 2024
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ Add a file named `sidebar-order.json` or `sidebar-order.yaml` into your `<config

| Property | Type | Required | Description |
| --------- | ------- | -------- | ----------- |
| item | String | true | This is a string that will be used to match each sidebar item by its text or its `data-panel` property. In the case of the item text, it can be a substring such as `developer` instead of `Developer Tools` and it is case insensitive. |
| item | String | true | This is a string that will be used to match each sidebar item by its text or its `data-panel` property. In the case of the item text, it can be a substring such as `developer` instead of `Developer Tools`. If the `exact` property is not set, it is case insensitive. |
| name | String | false | Changes the name of the sidebar item |
| order | Number | false | Sets the order number of the sidebar item |
| bottom | Boolean | false | Setting this property to `true` will group the item with the bottom items (Configuration, Developer Tools, etc) |
| hide | Boolean | false | Setting this property to `true` will hide the sidebar item |
| exact | Boolean | false | Specifies whether the `item` string match should be an exact match of the item text instead of a substring |
| exact | Boolean | false | Specifies whether the `item` string match should be an exact match of the item text or an exact match of the `data-panel` attribute (case sensitive) |
| href | String | false | Specifies the `href` of the sidebar item |
| target | String | false | Specifies the [target property] of the sidebar item |
| icon | String | false | Specifies the icon of the sidebar item |
Expand Down
14 changes: 9 additions & 5 deletions src/custom-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,17 @@ class CustomSidebar {
? undefined
: Array.from(items).find((element: Element): boolean => {
const text = element.querySelector(SELECTOR.ITEM_TEXT).textContent.trim();
const dataPanel = element.getAttribute(ATTRIBUTE.PANEL);
if (exact) {
return text === item;
return (
text === item ||
dataPanel === item
);
}
return (
text.toLocaleLowerCase().includes(itemLowerCase) ||
element.getAttribute(ATTRIBUTE.PANEL).toLocaleLowerCase() === itemLowerCase
);
if (dataPanel.toLocaleLowerCase() === itemLowerCase) {
return true;
}
return text.toLocaleLowerCase().includes(itemLowerCase);
});
if (element) {
element.setAttribute(ATTRIBUTE.PROCESSED, 'true');
Expand Down
Loading