Add generator aliases for search
Some checks failed
Deploy to GitHub Pages / build (push) Has been cancelled
Deploy to GitHub Pages / deploy (push) Has been cancelled

This commit is contained in:
Misode
2025-01-30 00:10:06 +01:00
parent c44678818d
commit 0dee553d7e
4 changed files with 22 additions and 19 deletions

View File

@@ -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>]
}