web/src/utils/do-searchy-searchy.ts
76 lines · 2143 bytes
1import type { Category } from '../types/Service';
2
3export interface SearchItem {
4 type: 'Category' | 'Section' | 'Service';
5 category: string;
6 itemCount?: number;
7 sectionName?: string;
8 description?: string;
9 name?: string;
10 url?: string;
11 github?: string;
12 codeberg?: string;
13 git?: string;
14 logo?: string;
15}
16
17export const prepareSearchItems = (categories: Category[]): SearchItem[] => {
18 const items: SearchItem[] = [];
19 // Add each category
20 categories.forEach((category) => {
21 items.push({
22 type: 'Category',
23 category: category.name,
24 itemCount: (category.sections || []).reduce((acc, section) => {
25 return acc + (section.services || []).length;
26 }, 0),
27 });
28
29 // Add section with category context
30 category.sections.forEach((section) => {
31 items.push({
32 type: 'Section',
33 sectionName: section.name,
34 description: section.intro || '',
35 category: category.name,
36 itemCount: (section.services || []).length,
37 });
38
39 // Add service with section and category context
40 (section.services || []).forEach((service) => {
41 items.push({
42 type: 'Service',
43 name: service.name,
44 description: service.description,
45 url: service.url,
46 github: service.github || '',
47 codeberg: service.codeberg || '',
48 git: service.git || '',
49 category: category.name,
50 sectionName: section.name,
51 logo: service.icon || '',
52 });
53 });
54 });
55 });
56 return items;
57};
58
59export const searchOptions = {
60 includeScore: true,
61 keys: [
62 { name: 'name', weight: 0.9 },
63 { name: 'sectionName', weight: 0.8 },
64 { name: 'category', weight: 0.7 },
65 { name: 'notableMentions', weight: 0.5 },
66 { name: 'alternativeTo', weight: 0.5 },
67 { name: 'github', weight: 0.4 },
68 { name: 'codeberg', weight: 0.4 },
69 { name: 'git', weight: 0.3 },
70 { name: 'url', weight: 0.2 },
71 { name: 'description', weight: 0.1 },
72 { name: 'intro', weight: 0.1 },
73 { name: 'furtherInfo', weight: 0.1 },
74 { name: 'wordOfWarning', weight: 0.1 },
75 ],
76};