diff --git a/src/app/Config.ts b/src/app/Config.ts index 41780376..77dc2627 100644 --- a/src/app/Config.ts +++ b/src/app/Config.ts @@ -22,6 +22,7 @@ export interface ConfigGenerator { path?: string, noPath?: boolean, tags?: string[], + aliases?: string[], dependency?: string, minVersion?: string, maxVersion?: string, diff --git a/src/app/components/Header.tsx b/src/app/components/Header.tsx index 7f76c1f6..3e660c7b 100644 --- a/src/app/components/Header.tsx +++ b/src/app/components/Header.tsx @@ -5,6 +5,7 @@ import config from '../Config.js' import { useLocale, useTheme, useTitle, useVersion } from '../contexts/index.js' import { cleanUrl, getGenerator, SOURCE_REPO_URL } from '../Utils.js' import { FancyMenu } from './FancyMenu.jsx' +import { searchGenerators } from './generator/GeneratorList.jsx' import { Btn, BtnMenu, Icons, Octicon } from './index.js' const Themes: Record = { @@ -69,15 +70,7 @@ function GeneratorTitle({ title, gen }: GeneratorTitleProps) { let results = config.generators .filter(g => !g.dependency) .map(g => ({ ...g, name: locale(`generator.${g.id}`).toLowerCase() })) - if (search) { - const parts = search.split(' ') - results = results.filter(g => parts.some(p => g.name.includes(p)) - || parts.some(p => g.tags?.some(t => t.includes(p)) ?? false)) - } - results.sort((a, b) => a.name.localeCompare(b.name)) - if (search) { - results.sort((a, b) => (b.name.startsWith(search) ? 1 : 0) - (a.name.startsWith(search) ? 1 : 0)) - } + results = searchGenerators(results, search) if (results.length === 0) { return [{locale('generators.no_results')}] } diff --git a/src/app/components/generator/GeneratorList.tsx b/src/app/components/generator/GeneratorList.tsx index 13addca2..2afd20cb 100644 --- a/src/app/components/generator/GeneratorList.tsx +++ b/src/app/components/generator/GeneratorList.tsx @@ -26,16 +26,9 @@ export function GeneratorList({ predicate }: Props) { }, [version, versionFilter]) const filteredGenerators = useMemo(() => { - const query = search.split(' ').map(q => q.trim().toLowerCase()).filter(q => q.length > 0) - return versionedGenerators.filter(gen => { - const content = `${gen.id} ${gen.tags?.join(' ') ?? ''} ${gen.path ?? ''} ${locale(`generator.${gen.id}`).toLowerCase()}` - return query.every(q => { - if (q.startsWith('!')) { - return q.length === 1 || !content.includes(q.slice(1)) - } - return content.includes(q) - }) - }) + const results = versionedGenerators + .map(g => ({ ...g, name: locale(`generator.${g.id}`).toLowerCase() })) + return searchGenerators(results, search) }, [versionedGenerators, search, locale]) return
@@ -52,3 +45,18 @@ export function GeneratorList({ predicate }: Props) {
} } + +export function searchGenerators(generators: (ConfigGenerator & { name: string})[], search?: string) { + if (search) { + const parts = search.split(' ').map(q => q.trim().toLowerCase()).filter(q => q.length > 0) + generators = generators.filter(g => parts.some(p => g.name.includes(p)) + || parts.some(p => g.path?.includes(p) ?? false) + || parts.some(p => g.tags?.some(t => t.includes(p)) ?? false) + || parts.some(p => g.aliases?.some(a => a.includes(p)) ?? false)) + } + generators.sort((a, b) => a.name.localeCompare(b.name)) + if (search) { + generators.sort((a, b) => (b.name.startsWith(search) ? 1 : 0) - (a.name.startsWith(search) ? 1 : 0)) + } + return generators +} diff --git a/src/config.json b/src/config.json index 7646134a..b01c35f4 100644 --- a/src/config.json +++ b/src/config.json @@ -587,6 +587,7 @@ "url": "assets/item", "path": "items", "tags": ["assets"], + "aliases": ["item model"], "minVersion": "1.21.4", "wiki": "https://minecraft.wiki/w/Items_model_definition" },