Files
gooseek/apps/posts-mcs/src/lib/content.ts
home 783569b8e7 feat: монорепо миграция, Discover/SearxNG улучшения
- Миграция на монорепозиторий (apps/frontend, apps/chat-service, etc.)
- Discover: проверка SearxNG, понятное empty state при ненастроенном поиске
- searxng.ts: валидация URL, проверка JSON-ответа, авто-добавление http://
- docker/searxng-config: настройки для JSON API SearxNG

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-20 17:03:45 +03:00

23 lines
937 B
TypeScript

import type { ContentBlock } from '../db/schema.js';
/** Извлекает поисковый текст из блоков контента */
export function blocksToSearchText(blocks: ContentBlock[] | null): string {
if (!blocks || !Array.isArray(blocks)) return '';
return blocks
.map((b) => {
if (b.type === 'text' && b.data?.html) return stripHtml(String(b.data.html));
if (b.type === 'heading' && b.data?.text) return b.data.text;
if (b.type === 'image' && b.data?.caption) return b.data.caption;
if (b.type === 'video' && b.data?.caption) return b.data.caption;
if (b.type === 'audio' && b.data?.caption) return b.data.caption;
if (b.type === 'table' && b.data?.html) return stripHtml(String(b.data.html));
return '';
})
.filter(Boolean)
.join(' ');
}
function stripHtml(html: string): string {
return html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
}