39 lines
989 B
TypeScript
39 lines
989 B
TypeScript
/**
|
|
* 各索引对应的转换函数表
|
|
*/
|
|
export const converters: {
|
|
[K in keyof MeiliIndexMap]: (item: MeiliIndexMap[K]) => SearchItemView;
|
|
} = {
|
|
products: (item: MeiliIndexMap['products']): SearchItemView => ({
|
|
id: item.id,
|
|
type: 'product',
|
|
title: item.name,
|
|
summary: item?.summary ?? '',
|
|
thumbnail: item?.cover ? `/api/assets/${item.cover}` : undefined,
|
|
}),
|
|
|
|
solutions: (item: MeiliIndexMap['solutions']): SearchItemView => ({
|
|
id: item.id,
|
|
type: 'solution',
|
|
title: item.title,
|
|
summary: item?.summary ?? '',
|
|
thumbnail: item?.cover ? `/api/assets/${item.cover}` : undefined,
|
|
}),
|
|
|
|
questions: (item: MeiliIndexMap['questions']): SearchItemView => ({
|
|
id: item.id,
|
|
type: 'question',
|
|
title: item.title,
|
|
summary: '',
|
|
}),
|
|
|
|
product_documents: (
|
|
item: MeiliIndexMap['product_documents']
|
|
): SearchItemView => ({
|
|
id: item.fileUUID || item.id,
|
|
type: 'document',
|
|
title: item.title,
|
|
summary: '',
|
|
}),
|
|
};
|