Provide assets on all search hits
This commit is contained in:
parent
8ed2296b2f
commit
0bdbca30d4
@ -14,16 +14,17 @@ function enhanceHit(hit) {
|
|||||||
|
|
||||||
resolve(hit)
|
resolve(hit)
|
||||||
} else {
|
} 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)
|
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
|
// add concatenated name for more relevance for people spelling without spaces
|
||||||
// think: createreactnative instead of create-react-native-app
|
// think: createreactnative instead of create-react-native-app
|
||||||
function concat(string) {
|
function concat(string) {
|
||||||
@ -65,8 +66,6 @@ function search(query, page) {
|
|||||||
Promise.all(
|
Promise.all(
|
||||||
value.hits.map(enhanceHit)
|
value.hits.map(enhanceHit)
|
||||||
).then(function (hits) {
|
).then(function (hits) {
|
||||||
hits.sort(byRelevanceDescending)
|
|
||||||
|
|
||||||
const totalHits = value.nbHits
|
const totalHits = value.nbHits
|
||||||
const totalPages = value.nbPages
|
const totalPages = value.nbPages
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user