feat: allow more tags in findTags

This commit is contained in:
xHyroM 2022-07-11 08:31:11 +02:00
parent f69c0b97f1
commit 119d8dee7b

View file

@ -13,10 +13,15 @@ for (const [key, value] of Object.entries(tags)) {
tagCache.set(key, value as unknown as Tag); tagCache.set(key, value as unknown as Tag);
} }
export const getTag = (name: string) => { export const getTag = (name: string, more?: boolean) => {
if (more) {
const tags = [...tagCache.filter(tag => tag.keywords.some(k => k.includes(name))).values()];
return tags;
} else {
const tag = tagCache.get(name) || tagCache.find(tag => tag.keywords.some(k => k.includes(name))); const tag = tagCache.get(name) || tagCache.find(tag => tag.keywords.some(k => k.includes(name)));
return tag; return tag;
} }
}
export const findTags = (name: string) => { export const findTags = (name: string) => {
if (!name) if (!name)
@ -27,14 +32,12 @@ export const findTags = (name: string) => {
})).slice(0, 25) })).slice(0, 25)
]; ];
else { else {
const tag = getTag(name); const tags: Tag[] = getTag(name, true) as Tag[];
if (tag) if (tags.length > 0)
return [ return tags.map(tag => new Object({
{
name: tag.keywords[0], name: tag.keywords[0],
value: tag.keywords[0], value: tag.keywords[0]
} }));
];
else return findTags(null); else return findTags(null);
} }
} }