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