diff --git a/tests/page-unit.js b/tests/page-unit.js index f87ce2c..563b660 100644 --- a/tests/page-unit.js +++ b/tests/page-unit.js @@ -190,5 +190,12 @@ test('Jev is offered the icons found for each word of a Signal', () => { ]); const ids = JSON.parse(run(`JSON.stringify(iconCandidates(${all}, 'AI Development', ['programming'], 'The tools', 40).map(c => c[0]))`)); assert.deepEqual(ids, ['solid/robot', 'solid/code'], 'each word its icons, "the" none'); + const brands = JSON.stringify([ + ['brands/mandalorian', 'Mandalorian', 'disney plus helmet star wars'], ['brands/apple', 'Apple', 'fruit ios mac'], + ['solid/fort-awesome', 'Fort', 'castle'], ['solid/apple-whole', 'Apple Whole', 'fruit'], + ]); + const offered = q => JSON.parse(run(`JSON.stringify(iconCandidates(${brands}, ${JSON.stringify(q)}, [], null, 40).map(c => c[0]))`)); + assert.deepEqual(offered('Disney castle'), ['solid/fort-awesome'], 'a brand only by its own name, never its search terms (#264)'); + assert.deepEqual(offered('Apple'), ['brands/apple', 'solid/apple-whole']); assert.equal(run(`signalCounts({items: 12, unread: 1})`), '12 items ยท 1 unread'); }); diff --git a/web/src/signals.ts b/web/src/signals.ts index 9953c0e..73009df 100644 --- a/web/src/signals.ts +++ b/web/src/signals.ts @@ -258,8 +258,12 @@ const ICON_STOP=new Set(['the','and','for','not','with','about','their','own','f function iconCandidates(all: [string,string,string][], name: string, keywords: string[], description: string|null, max=40){ const words=[name,...keywords,description||''].join(' ').toLowerCase().split(/[^a-z0-9]+/).filter(w=>w.length>1&&!ICON_STOP.has(w)); const out=new Map(); + // A brand's icon stands for that brand, so it is offered only when its name is one of the + // Signal's words: by its search terms, "disney" brought the Mandalorian, a Disney+ show (#264). + const brandFor=(id: string, w: string)=>!id.startsWith('brands/')||id.slice(7).split('-').includes(w); for(const w of [...new Set(words)]) - for(const [id,label,terms] of iconMatches(all,w,6)) if(out.sizebrandFor(id,w)),w,6)) + if(out.size