| 1 |
// A cache key, never a query: resolved to a real term before any request. |
| 2 |
export const DEFAULT_IMAGE_SEARCH = 'extendify-default-image-search'; |
| 3 |
|
| 4 |
// Page titles measured worse: "About" returns zero photos, and titles are localized. |
| 5 |
const NEUTRAL_TERMS = [ |
| 6 |
'office workspace', |
| 7 |
'team meeting', |
| 8 |
'city street', |
| 9 |
'modern interior', |
| 10 |
'nature landscape', |
| 11 |
]; |
| 12 |
|
| 13 |
const pickRandom = (items) => items[Math.floor(Math.random() * items.length)]; |
| 14 |
|
| 15 |
export const defaultImageSearch = () => { |
| 16 |
const terms = window.extSharedData?.siteProfile?.imageSearchTerms; |
| 17 |
const usable = Array.isArray(terms) |
| 18 |
? terms.filter((term) => typeof term === 'string' && term.trim()) |
| 19 |
: []; |
| 20 |
return usable.length ? pickRandom(usable) : pickRandom(NEUTRAL_TERMS); |
| 21 |
}; |
| 22 |
|
| 23 |
export const resolveImageSearch = (search) => |
| 24 |
!search || search === DEFAULT_IMAGE_SEARCH ? defaultImageSearch() : search; |
| 25 |
|