diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common-util/search-shape.js | 2 | ||||
| -rw-r--r-- | src/content/dependencies/generateSearchSidebarBox.js | 19 | ||||
| -rw-r--r-- | src/search-select.js | 23 | ||||
| -rw-r--r-- | src/static/js/client/sidebar-search.js | 90 | ||||
| -rw-r--r-- | src/strings-default.yaml | 7 | ||||
| -rw-r--r-- | src/urls-default.yaml | 2 |
6 files changed, 117 insertions, 26 deletions
diff --git a/src/common-util/search-shape.js b/src/common-util/search-shape.js index dada5003..3f1d9ed2 100644 --- a/src/common-util/search-shape.js +++ b/src/common-util/search-shape.js @@ -8,7 +8,7 @@ const baselineStore = [ 'primaryName', - 'disambiguator', + 'disambiguators', 'classification', 'artwork', 'color', diff --git a/src/content/dependencies/generateSearchSidebarBox.js b/src/content/dependencies/generateSearchSidebarBox.js index 03aefc78..7d5fe127 100644 --- a/src/content/dependencies/generateSearchSidebarBox.js +++ b/src/content/dependencies/generateSearchSidebarBox.js @@ -69,17 +69,26 @@ export default { language.encapsulate(capsule, 'resultDisambiguator', capsule => [ html.tag('template', {class: 'wiki-search-group-result-disambiguator-string'}, language.$(capsule, 'group', { - disambiguator: html.tag('slot', {name: 'disambiguator'}), + category: + html.tag('slot', {name: 'disambiguator'}), })), html.tag('template', {class: 'wiki-search-flash-result-disambiguator-string'}, language.$(capsule, 'flash', { - disambiguator: html.tag('slot', {name: 'disambiguator'}), + act: + html.tag('slot', {name: 'disambiguator'}), })), - html.tag('template', {class: 'wiki-search-track-result-disambiguator-string'}, - language.$(capsule, 'track', { - disambiguator: html.tag('slot', {name: 'disambiguator'}), + html.tag('template', {class: 'wiki-search-track-result-album-disambiguator-string'}, + language.$(capsule, 'track.album', { + album: + html.tag('slot', {name: 'disambiguator'}), + })), + + html.tag('template', {class: 'wiki-search-track-result-artist-disambiguator-string'}, + language.$(capsule, 'track.artists', { + artists: + html.tag('slot', {name: 'disambiguator'}), })), ]), diff --git a/src/search-select.js b/src/search-select.js index a7dcf81a..81734140 100644 --- a/src/search-select.js +++ b/src/search-select.js @@ -3,7 +3,7 @@ // These files totally go together, so read them side by side, okay? import baseSearchSpec from '#search-shape'; -import {unique} from '#sugar'; +import {empty, unique} from '#sugar'; import {compareKebabCase} from '#wiki-data'; function prepareArtwork(artwork, thing, { @@ -127,8 +127,8 @@ function baselineProcess(thing, _opts) { fields.color = thing.color; - fields.disambiguator = - null; + fields.disambiguators = + []; return fields; } @@ -209,8 +209,21 @@ function genericProcess(thing, opts) { : 'track') : null); - fields.disambiguator = - fields.parentName; + fields.disambiguators = + (thing.isTrack + ? [ + (fields.classification === 'single' + ? null + : fields.parentName), + + (empty(thing.artistContribs) + ? null + : thing.artistContribs + .map(contrib => contrib.artist.name) + .join(', ')), + ] + + : [thing.parentName]); fields.artTags = (Array.from(new Set( diff --git a/src/static/js/client/sidebar-search.js b/src/static/js/client/sidebar-search.js index a06c95fd..5b3c0ee1 100644 --- a/src/static/js/client/sidebar-search.js +++ b/src/static/js/client/sidebar-search.js @@ -1,5 +1,11 @@ import {getColors} from '../../shared-util/colors.js'; -import {accumulateSum, empty, unique} from '../../shared-util/sugar.js'; + +import { + accumulateSum, + compareArrays, + empty, + unique, +} from '../../shared-util/sugar.js'; import { cssProp, @@ -80,7 +86,8 @@ export const info = { groupResultDisambiguatorString: null, flashResultDisambiguatorString: null, - trackResultDisambiguatorString: null, + trackResultDisambiguatorString1: null, + trackResultDisambiguatorString2: null, albumResultFilterString: null, artistResultFilterString: null, @@ -224,8 +231,11 @@ export function getPageReferences() { info.flashResultDisambiguatorString = findString('flash-result-disambiguator'); - info.trackResultDisambiguatorString = - findString('track-result-disambiguator'); + info.trackResultDisambiguatorString1 = + findString('track-result-album-disambiguator'); + + info.trackResultDisambiguatorString2 = + findString('track-result-artist-disambiguator'); info.albumResultFilterString = findString('album-result-filter'); @@ -1087,18 +1097,76 @@ function generateSidebarSearchResult(result, results) { const compareName = otherResult => getSearchResultName(otherResult) === getSearchResultName(result); - const ambiguous = - results.some(otherResult => + const ambiguousWith = + results.filter(otherResult => otherResult !== result && compareReferenceType(otherResult) && compareName(otherResult)); - if (ambiguous) { - preparedSlots.disambiguate = - result.data.disambiguator; + if (!empty(ambiguousWith)) disambiguate: { + const allAmbiguous = [result, ...ambiguousWith]; + + // First search for an ideal disambiguation, which disambiguates + // all ambiguous results in the same way. + let disambiguation = null, i; + for (i = 0; i < result.data.disambiguators.length; i++) { + const disambiguations = + allAmbiguous.map(r => r.data.disambiguators[i]); + + if (unique(disambiguations).length === allAmbiguous.length) { + disambiguation = result.data.disambiguators[i]; + break; + } + } + + // Otherwise, search for a disambiguation which disambiguates + // *this result* with at least one other result which it is + // *otherwise* ambiguous with. + if (!disambiguation) { + for (i = 1; i < result.data.disambiguators.length; i++) { + const otherwiseAmbiguousWith = + ambiguousWith.filter(otherResult => + compareArrays( + otherResult.data.disambiguators.slice(0, i), + result.data.disambiguators.slice(0, i))); + + if ( + otherwiseAmbiguousWith.find(otherResult => + otherResult.data.disambiguators[i] !== + result.data.disambiguators[i]) + ) { + disambiguation = result.data.disambiguators[i]; + break; + } + } + } + + // Otherwise, search for a disambiguation which disambiguates + // this result at all. + if (!disambiguation) { + for (i = 0; i < result.data.disambiguators.length; i++) { + if ( + ambiguousWith.find(otherResult => + otherResult.data.disambiguators[i] !== + result.data.disambiguators[i]) + ) { + disambiguation = result.data.disambiguators[i]; + break; + } + } + } + + if (!disambiguation) { + break disambiguate; + } + + const string = + info[result.referenceType + 'ResultDisambiguatorString' + (i + 1)]; + + if (!string) break disambiguate; - preparedSlots.disambiguatorString = - info[result.referenceType + 'ResultDisambiguatorString']; + preparedSlots.disambiguate = disambiguation; + preparedSlots.disambiguatorString = string; } return generateSidebarSearchResultTemplate(preparedSlots); diff --git a/src/strings-default.yaml b/src/strings-default.yaml index efa5f5f0..44768897 100644 --- a/src/strings-default.yaml +++ b/src/strings-default.yaml @@ -844,9 +844,10 @@ misc: single: "(single)" resultDisambiguator: - group: "({DISAMBIGUATOR})" - flash: "(in {DISAMBIGUATOR})" - track: "(from {DISAMBIGUATOR})" + group: "({CATEGORY})" + flash: "(in {ACT})" + track.album: "(from {ALBUM})" + track.artists: "(by {ARTISTS})" resultFilter: album: "Albums" diff --git a/src/urls-default.yaml b/src/urls-default.yaml index 6a2b3140..d105dd34 100644 --- a/src/urls-default.yaml +++ b/src/urls-default.yaml @@ -11,7 +11,7 @@ yamlAliases: # part of a build. This is so that multiple builds of a wiki can coexist # served from the same server / file system root: older builds' HTML files # refer to earlier values of STATIC_VERSION, avoiding name collisions. - - &staticVersion 5p3 + - &staticVersion 5p4 data: prefix: 'data/' |