22 lines
639 B
TypeScript
22 lines
639 B
TypeScript
/** Recursively collect string values from nested content objects for search indexing. */
|
|
|
|
export function collectStrings(value: unknown, out: string[] = []): string[] {
|
|
if (typeof value === 'string') {
|
|
const trimmed = value.trim()
|
|
if (trimmed) out.push(trimmed)
|
|
return out
|
|
}
|
|
if (Array.isArray(value)) {
|
|
value.forEach((item) => collectStrings(item, out))
|
|
return out
|
|
}
|
|
if (value && typeof value === 'object') {
|
|
Object.values(value).forEach((item) => collectStrings(item, out))
|
|
}
|
|
return out
|
|
}
|
|
|
|
export function joinSearchText(...sources: unknown[]): string {
|
|
return collectStrings(sources).join(' ')
|
|
}
|