docs: prettify github count (close #5356) (#5357)

This commit is contained in:
sezgi 2020-07-14 01:29:27 -07:00 committed by GitHub
parent 28984500fb
commit c962253c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

25
docs/_static/utils.js vendored Normal file
View File

@ -0,0 +1,25 @@
const hasuraUtils = {
formatNumber: function(number) {
if (typeof number !== "number") return number;
const SIsymbol = ["", "k", "M", "G", "T", "P", "E"];
const absNumber = Math.abs(number);
const sign = Math.sign(number);
// what tier? (determines SI symbol)
const tier = Math.log10(absNumber) / 3 | 0;
// if zero, we don't need a suffix
if (tier === 0) return sign * absNumber;
// get suffix and determine scale
const suffix = SIsymbol[tier];
const scale = Math.pow(10, tier * 3);
// scale the number
const scaled = absNumber / scale;
// format number and add suffix
return sign * scaled.toFixed(1) + suffix;
}
}

View File

@ -6,6 +6,8 @@
{% set css_files = css_files + ['_static/djangosite.css', '_static/hasura-custom.css'] %}
{% set script_files = script_files + ['_static/utils.js'] %}
{%- if is_landing_page %}
{% set css_files = css_files + ['_static/landing.css'] %}
{%- endif %}
@ -751,7 +753,7 @@
})
.then(data => {
const githubStar = data[0].star_count
$(".gitHubCount").html(githubStar);
$(".gitHubCount").html(hasuraUtils.formatNumber(githubStar));
$(".gitHubBtn").removeClass("hide");
})
.catch(e => {