( items: T[], searchValue: string )
| 697 | } |
| 698 | |
| 699 | export function sortItemsForDisplay<T extends {name: string; href: string; date?: string}>( |
| 700 | items: T[], |
| 701 | searchValue: string |
| 702 | ): T[] { |
| 703 | if (searchValue.trim().length === 0) { |
| 704 | return [...items].sort((a, b) => { |
| 705 | const aIsIntro = a.href.endsWith('/'); |
| 706 | const bIsIntro = b.href.endsWith('/'); |
| 707 | |
| 708 | // Date sorting for Blog/Releases |
| 709 | if (a.date && b.date) { |
| 710 | const aDate = new Date(a.date); |
| 711 | const bDate = new Date(b.date); |
| 712 | return bDate.getTime() - aDate.getTime(); |
| 713 | } else if (a.date && !b.date) { |
| 714 | return 1; |
| 715 | } else if (!a.date && b.date) { |
| 716 | return -1; |
| 717 | } |
| 718 | |
| 719 | // Introduction first |
| 720 | if (aIsIntro && !bIsIntro) { |
| 721 | return -1; |
| 722 | } |
| 723 | if (!aIsIntro && bIsIntro) { |
| 724 | return 1; |
| 725 | } |
| 726 | // Sort alphabetically by name |
| 727 | return a.name.localeCompare(b.name); |
| 728 | }); |
| 729 | } |
| 730 | return items; |
| 731 | } |
| 732 | |
| 733 | export function createSearchOptions< |
| 734 | T extends {name: string; tags: string[]; date?: string; section?: string} |
no test coverage detected