Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ For every single NPM package, we create a record in the Algolia index. The resul
"objectID": "babel-core",
"_searchInternal": {
"popularName": "babel-core",
"downloadsMagnitude": 8
"downloadsMagnitude": 8,
"jsDelivrPopularity": 5
}
}
```
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/config.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Object {
],
"customRanking": Array [
"desc(_searchInternal.downloadsMagnitude)",
"desc(_searchInternal.jsDelivrPopularity)",
"desc(dependents)",
"desc(downloadsLast30Days)",
],
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const defaultConfig = {
],
customRanking: [
'desc(_searchInternal.downloadsMagnitude)',
'desc(_searchInternal.jsDelivrPopularity)',
'desc(dependents)',
'desc(downloadsLast30Days)',
],
Expand Down
13 changes: 12 additions & 1 deletion src/jsDelivr.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@ export async function loadHits() {
}

export function getHits(pkgs) {
return pkgs.map(({ name }) => ({ jsDelivrHits: hits.get(name) || 0 }));
return pkgs.map(({ name }) => {
const jsDelivrHits = hits.get(name) || 0;

return {
jsDelivrHits,
_searchInternal: {
// anything below 1000 hits/month is likely to mean that
// someone just made a few random requests so we count that as 0
jsDelivrPopularity: Math.max(jsDelivrHits.toString().length - 3, 0),
},
};
});
}