Skip to content

Commit 91f9442

Browse files
committed
package search
1 parent f8dc09b commit 91f9442

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

app/routes/PackagesRoute.res

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
let loader = async () => {
2+
let props = await Packages.getStaticProps()
3+
4+
props
5+
}
6+
17
let default = () => {
2-
<Packages packages=[] unmaintained=[] />
8+
let props = ReactRouter.useLoaderData()
9+
<Packages {...props} />
310
}

src/Packages.res

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ let parsePkgs = data => {
527527
}
528528
}
529529

530-
let getStaticProps: Next.GetStaticProps.t<props, unit> = async _ctx => {
530+
let getStaticProps = async (): props => {
531531
let baseUrl = "https://registry.npmjs.org/-/v1/search?text=keywords:rescript&size=250&maintenance=1.0&popularity=0.5&quality=0.9"
532532

533533
let (one, two, three) = await Promise.all3((
@@ -576,11 +576,19 @@ let getStaticProps: Next.GetStaticProps.t<props, unit> = async _ctx => {
576576
true
577577
}
578578
})
579+
->Array.map(pkg => {
580+
// Git urls are often prefixed with "+git", which isn't a valid browser url.
581+
let repositoryHref = pkg.repositoryHref->Null.map(href => {
582+
href->String.replaceAll("git+", "")
583+
})
584+
{
585+
...pkg,
586+
repositoryHref,
587+
}
588+
})
579589

580590
{
581-
"props": {
582-
packages: pkges,
583-
unmaintained,
584-
},
591+
packages: pkges,
592+
unmaintained,
585593
}
586594
}

src/Packages.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ type props = {
2424

2525
let make: props => React.element
2626

27-
let getStaticProps: Next.GetStaticProps.t<props, unit>
27+
let getStaticProps: unit => promise<props>

0 commit comments

Comments
 (0)