mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 07:10:41 +00:00
Add generator aliases for search
This commit is contained in:
@@ -22,6 +22,7 @@ export interface ConfigGenerator {
|
||||
path?: string,
|
||||
noPath?: boolean,
|
||||
tags?: string[],
|
||||
aliases?: string[],
|
||||
dependency?: string,
|
||||
minVersion?: string,
|
||||
maxVersion?: string,
|
||||
|
||||
@@ -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<string, keyof typeof Octicon> = {
|
||||
@@ -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 [<span class="note">{locale('generators.no_results')}</span>]
|
||||
}
|
||||
|
||||
@@ -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 <div class="generator-list">
|
||||
@@ -52,3 +45,18 @@ export function GeneratorList({ predicate }: Props) {
|
||||
</div>}
|
||||
</div>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user