From 4e734a470b3e07ae76f294d7847bc441be3148c0 Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 12 Sep 2021 09:00:36 +1000 Subject: [PATCH] Package Index tweaks --- data/packages_url_resources.json | 7 ------- src/Packages.mjs | 11 +++++------ src/Packages.res | 12 +++++------- src/bindings/Fuse.res | 2 ++ 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/data/packages_url_resources.json b/data/packages_url_resources.json index 16d2c2746..ae95b4c95 100644 --- a/data/packages_url_resources.json +++ b/data/packages_url_resources.json @@ -12,12 +12,5 @@ "keywords": ["rescript", "typescript"], "urlHref": "https://github.com/reason-association/genType", "official": true - }, - { - "name": "re-schema-form", - "description": "Re-schema-form is a meta based render.", - "keywords": ["rescript"], - "urlHref": "https://github.com/jongleb/re-schema-form", - "official": false } ] diff --git a/src/Packages.mjs b/src/Packages.mjs index 03b15197f..efe54cdeb 100644 --- a/src/Packages.mjs +++ b/src/Packages.mjs @@ -48,6 +48,8 @@ function filterKeywords(keywords) { })); } +var uniqueKeywords = ((keywords) => [...new Set(keywords)]); + function isOfficial(res) { if (res.TAG !== /* Npm */0) { return res._0.official; @@ -65,8 +67,7 @@ function applyNpmSearch(packages, pattern) { shouldSort: true, includeScore: true, threshold: 0.2, - location: 0, - distance: 30, + ignoreLocation: true, minMatchCharLength: 1, keys: [ "meta.uid", @@ -83,8 +84,7 @@ function applyUrlResourceSearch(urls, pattern) { shouldSort: true, includeScore: true, threshold: 0.2, - location: 0, - distance: 30, + ignoreLocation: true, minMatchCharLength: 1, keys: [ "name", @@ -516,13 +516,12 @@ function getStaticProps(_ctx) { return { name: pkg.name, version: pkg.version, - keywords: filterKeywords(pkg.keywords), + keywords: uniqueKeywords(filterKeywords(pkg.keywords)), description: Belt_Option.getWithDefault(pkg.description, ""), repositoryHref: Js_null.fromOption(pkg.links.repository), npmHref: pkg.links.npm }; })); - console.log(pkges); var index_data_dir = Path.join(Process.cwd(), "./data"); var urlResources = JSON.parse(Fs.readFileSync(Path.join(index_data_dir, "packages_url_resources.json"), "utf8")); var props = { diff --git a/src/Packages.res b/src/Packages.res index b7fcc79ef..17932a9fb 100644 --- a/src/Packages.res +++ b/src/Packages.res @@ -67,6 +67,8 @@ module Resource = { }) } + let uniqueKeywords: array => array = %raw(`(keywords) => [...new Set(keywords)]`) + let isOfficial = (res: t) => { switch res { | Npm(pkg) => @@ -84,8 +86,7 @@ module Resource = { ~shouldSort=true, ~includeScore=true, ~threshold=0.2, - ~location=0, - ~distance=30, + ~ignoreLocation=true, ~minMatchCharLength=1, ~keys=["meta.uid", "name", "keywords"], (), @@ -103,8 +104,7 @@ module Resource = { ~shouldSort=true, ~includeScore=true, ~threshold=0.2, - ~location=0, - ~distance=30, + ~ignoreLocation=true, ~minMatchCharLength=1, ~keys=["name", "keywords"], (), @@ -529,15 +529,13 @@ let getStaticProps: Next.GetStaticProps.revalidate = _ctx => { { name: pkg["name"], version: pkg["version"], - keywords: Resource.filterKeywords(pkg["keywords"]), + keywords: Resource.filterKeywords(pkg["keywords"])->Resource.uniqueKeywords, description: Belt.Option.getWithDefault(pkg["description"], ""), repositoryHref: Js.Null.fromOption(pkg["links"]["repository"]), npmHref: pkg["links"]["npm"], } }) - Js.log(pkges) - let index_data_dir = Node.Path.join2(Node.Process.cwd(), "./data") let urlResources = Node.Path.join2(index_data_dir, "packages_url_resources.json") diff --git a/src/bindings/Fuse.res b/src/bindings/Fuse.res index 95e0a60f8..f29d3f564 100644 --- a/src/bindings/Fuse.res +++ b/src/bindings/Fuse.res @@ -12,6 +12,8 @@ module Options = { @optional distance: int, @optional + ignoreLocation: bool, + @optional minMatchCharLength: int, @optional keys: array,