mirror of
https://github.com/daylinmorgan/nimpkgs.git
synced 2024-12-21 18:50:43 -06:00
purposeless refactorings
This commit is contained in:
parent
97134d4ea8
commit
a3d31ad8b1
3 changed files with 29 additions and 23 deletions
|
@ -1,4 +1,4 @@
|
|||
import std/[strutils, sequtils, uri]
|
||||
import std/[strutils, uri]
|
||||
|
||||
import karax/[kbase, karax, karaxdsl, vdom, jstrutils]
|
||||
|
||||
|
@ -23,35 +23,36 @@ proc parseQuery*(s: kstring): Query =
|
|||
k = subparts[0]
|
||||
v = subparts[1]
|
||||
case k:
|
||||
of "name":
|
||||
result.name = v
|
||||
of "tag":
|
||||
result.tag = v.replace("-")
|
||||
of "license":
|
||||
result.license = v
|
||||
else: discard
|
||||
of "name":
|
||||
result.name = v
|
||||
of "tag":
|
||||
result.tag = v.replace("-")
|
||||
of "license":
|
||||
result.license = v
|
||||
else: discard
|
||||
else:
|
||||
result.all &= part
|
||||
|
||||
proc toLowerAscii(ks: kstring): kstring {.inline.} =
|
||||
($ks).toLowerAscii().kstring
|
||||
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():
|
||||
result = ctx.nimpkgs.packages.values.toSeq()
|
||||
proc `~=`(q: Query, pkg: NimPackage): bool =
|
||||
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)):
|
||||
return
|
||||
|
||||
for name, pkg in ctx.nimpkgs.packages:
|
||||
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.toLowerAscii() in searchStr:
|
||||
return true
|
||||
|
||||
if q.all in searchStr:
|
||||
result.add pkg
|
||||
proc searchPackages*(q: Query): seq[NimPackage] =
|
||||
if q == Query(): return nimpkgsList()
|
||||
|
||||
collect:
|
||||
for _, pkg in ctx.nimpkgs.packages:
|
||||
if q ~= pkg: pkg
|
||||
|
||||
proc getSearchFromUri*(): kstring =
|
||||
var url = currentUri()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import std/[
|
||||
asyncjs, jsconsole, jsfetch, sugar, tables
|
||||
asyncjs, jsconsole, jsfetch, sequtils, sugar, tables
|
||||
]
|
||||
|
||||
import karax/[kbase, karax]
|
||||
|
@ -14,6 +14,8 @@ type
|
|||
nimpkgs*: NimPkgs
|
||||
loaded*: bool
|
||||
|
||||
var ctx* = Context()
|
||||
|
||||
let nimpkgsUrl =
|
||||
when defined(debug): "http://localhost:8080/nimpkgs.json"
|
||||
else: "https://raw.githubusercontent.com/nimpkgs/nimpkgs/main/nimpkgs.json"
|
||||
|
@ -29,5 +31,8 @@ proc fetchPackages*(ctx: var Context){.async.} =
|
|||
)
|
||||
.catch((err: Error) => console.log err
|
||||
)
|
||||
var ctx* = Context()
|
||||
|
||||
discard ctx.fetchPackages
|
||||
|
||||
proc nimpkgsList*(): seq[NimPackage] {.inline.} =
|
||||
ctx.nimpkgs.packages.values.toSeq()
|
||||
|
|
|
@ -90,7 +90,7 @@ proc filteredPackagesDom(): VNode =
|
|||
pkg.card
|
||||
|
||||
proc update(pgCtx: var PageContext) =
|
||||
pgCtx.filteredPackages = ctx.nimpkgs.packages.values().toSeq()
|
||||
pgCtx.filteredPackages = nimpkgsList()
|
||||
pgCtx.search = getSearchFromUri()
|
||||
pgCtx.filteredPackages = searchPackages(parseQuery(pgCtx.search))
|
||||
|
||||
|
|
Loading…
Reference in a new issue