Provide assets on all search hits

This commit is contained in:
MICHAEL JACKSON 2017-09-13 10:02:36 -07:00
parent 8ed2296b2f
commit 0bdbca30d4
1 changed files with 6 additions and 7 deletions

View File

@ -14,16 +14,17 @@ function enhanceHit(hit) {
resolve(hit)
} else {
// We don't have any global paths for this package yet. Try
// using the "bare" URL.
hit.assets = [
`https://unpkg.com/${hit.name}@${hit.version}`
]
resolve(hit)
}
})
}
function byRelevanceDescending(a, b) {
// Hits that have assets are more relevant.
return a.assets ? (b.assets ? 0 : -1) : (b.assets ? 1 : 0)
}
// add concatenated name for more relevance for people spelling without spaces
// think: createreactnative instead of create-react-native-app
function concat(string) {
@ -65,8 +66,6 @@ function search(query, page) {
Promise.all(
value.hits.map(enhanceHit)
).then(function (hits) {
hits.sort(byRelevanceDescending)
const totalHits = value.nbHits
const totalPages = value.nbPages