提交正式官网
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/** 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(' ')
|
||||
}
|
||||
Reference in New Issue
Block a user