From 52b78b8f60feb4ed1f79080df3d8717ec983fb1f Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sat, 17 Aug 2024 09:13:19 -0500 Subject: [PATCH] make general search case insensi --- src/components/search.nim | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/search.nim b/src/components/search.nim index 7c2dbc2..165941b 100644 --- a/src/components/search.nim +++ b/src/components/search.nim @@ -1,6 +1,6 @@ -import std/[strutils, sequtils, dom, uri] +import std/[strutils, sequtils, uri] -import karax/[kbase, karax, karaxdsl, vdom, jstrutils, kdom] +import karax/[kbase, karax, karaxdsl, vdom, jstrutils] import ../[packages, style, context] # import ../components/package @@ -33,6 +33,11 @@ proc parseQuery*(s: kstring): Query = else: result.all &= part +proc toLowerAscii(ks: kstring): kstring {.inline.} = + ($ks).toLowerAscii().kstring + +proc genericSearchString(p: NimPackage): kstring = + (@[p.url, p.name, p.description, p.tags.join(" ").kstring].join(" ").kstring).toLowerAscii() proc searchPackages*(q: Query): seq[NimPackage] = if q == Query(): @@ -40,11 +45,10 @@ proc searchPackages*(q: Query): seq[NimPackage] = return for name, pkg in ctx.nimpkgs.packages: - let searchStr = ((pkg.url & " " & pkg.name & " " & pkg.description & " " & ( - pkg.tags).join(" ").kstring)) - if (q.name notin pkg.name) or - (q.license notin pkg.license) or - (q.tag != "".kstring and (q.tag notin pkg.tags)): continue + let searchStr = pkg.genericSearchString() + if (q.name notin pkg.name) or (q.license notin pkg.license) or + (q.tag != "".kstring and (q.tag notin pkg.tags)): + continue if q.all in searchStr: result.add pkg