From 4b4f07308917eda30ea128e8364f19d86ce642f0 Mon Sep 17 00:00:00 2001 From: Sky Chrastina Date: Fri, 18 Nov 2022 15:38:28 -0700 Subject: [PATCH] Fix az sort (#14347) * add stopword package * sort pet and potion quests by stopword-ized text * chore(package): revert package lock Will update after merge * fix(package): Friday brain Co-authored-by: SabreCat --- website/client/package.json | 1 + .../src/components/shops/quests/index.vue | 56 ++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/website/client/package.json b/website/client/package.json index ac50e3b9a2..58fd3cfa79 100644 --- a/website/client/package.json +++ b/website/client/package.json @@ -49,6 +49,7 @@ "sass": "^1.34.0", "sass-loader": "^8.0.2", "smartbanner.js": "^1.19.1", + "stopword": "^2.0.5", "svg-inline-loader": "^0.8.2", "svg-url-loader": "^7.1.1", "svgo": "^1.3.2", diff --git a/website/client/src/components/shops/quests/index.vue b/website/client/src/components/shops/quests/index.vue index e1a9134278..49cf3eb4ff 100644 --- a/website/client/src/components/shops/quests/index.vue +++ b/website/client/src/components/shops/quests/index.vue @@ -402,6 +402,8 @@ import _sortBy from 'lodash/sortBy'; import _throttle from 'lodash/throttle'; import _groupBy from 'lodash/groupBy'; import _map from 'lodash/map'; +import _each from 'lodash/each'; +import * as stopword from 'stopword/dist/stopword.esm.mjs'; import { mapState } from '@/libs/store'; import ShopItem from '../shopItem'; @@ -426,6 +428,51 @@ import SelectTranslatedArray from '@/components/tasks/modal-controls/selectTrans import QuestPopover from './questPopover'; import { worldStateMixin } from '@/mixins/worldState'; +function splitMultipleDelims (text, delims) { + const omniDelim = 'θνι'; + let workingText = text; + for (const delim of delims) { + workingText = workingText.replace(new RegExp(delim, 'g'), omniDelim); + } + return workingText.split(omniDelim); +} + +function removeStopwordsFromText (text, language) { + // list of supported languages https://www.npmjs.com/package/stopword + const langs = { + bg: stopword.bul, + cs: stopword.ces, + da: stopword.dan, + de: stopword.deu, + en: stopword.eng, + en_GB: stopword.eng, + 'en@pirate': stopword.eng.concat(["th'"]), + es: stopword.spa, + es_419: stopword.spa, + fr: stopword.fra, + he: stopword.heb, + hu: stopword.hun, + id: stopword.ind, + it: stopword.ita, + ja: stopword.jpn, + nl: stopword.nld, + pl: stopword.pol, + pt: stopword.por, + pt_BR: stopword.porBr, + ro: stopword.ron, + ru: stopword.rus, + sk: stopword.slv, + // sr: stopword., + sv: stopword.swe, + tr: stopword.tur, + uk: stopword.ukr, + zh: stopword.zho, + zh_TW: stopword.zho, + }; + const splitText = splitMultipleDelims(text, [' ', "'"]); + return stopword.removeStopwords(splitText, langs[language] || stopword.eng).join(' ').toLowerCase(); +} + export default { components: { QuestPopover, @@ -539,7 +586,14 @@ export default { switch (sortBy) { // eslint-disable-line default-case case 'AZ': { - result = _sortBy(result, ['text']); + if (category.identifier === 'pet' || category.identifier === 'hatchingPotion') { + _each(result, item => { + item.sortText = removeStopwordsFromText(item.text, this.user.preferences.language); + }); + result = _sortBy(result, ['sortText']); + } else { + result = _sortBy(result, ['text']); + } break; }