diff --git a/app/templates/post/_post_voting_buttons.html b/app/templates/post/_post_voting_buttons.html index 516c2fa4..0ccd990b 100644 --- a/app/templates/post/_post_voting_buttons.html +++ b/app/templates/post/_post_voting_buttons.html @@ -3,7 +3,7 @@
- {{ post.up_votes }} + {{ shorten_number(post.up_votes) }}
{% endif %} @@ -11,17 +11,17 @@
- {{ post.down_votes }} + {{ shorten_number(post.down_votes) }}
{% endif %} {% else %}
- {{ post.up_votes }} + {{ shorten_number(post.up_votes) }}
- {{ post.down_votes }} + {{ shorten_number(post.down_votes) }}
{% endif %} diff --git a/app/utils.py b/app/utils.py index 0297bfc4..7bbf55f0 100644 --- a/app/utils.py +++ b/app/utils.py @@ -483,6 +483,16 @@ def awaken_dormant_instance(instance): db.session.commit() +def shorten_number(number): + if number < 1000: + return str(number) + elif number < 1000000: + return f'{number / 1000:.1f}k' + else: + return f'{number / 1000000:.1f}M' + + + # All the following post/comment ranking math is explained at https://medium.com/hacking-and-gonzo/how-reddit-ranking-algorithms-work-ef111e33d0d9 epoch = datetime(1970, 1, 1) diff --git a/pyfedi.py b/pyfedi.py index 0da039e0..19520d5e 100644 --- a/pyfedi.py +++ b/pyfedi.py @@ -8,7 +8,7 @@ from flask import session, g, json from app.constants import POST_TYPE_LINK, POST_TYPE_IMAGE, POST_TYPE_ARTICLE from app.models import Site from app.utils import getmtime, gibberish, shorten_string, shorten_url, digits, user_access, community_membership, \ - can_create, can_upvote, can_downvote + can_create, can_upvote, can_downvote, shorten_number app = create_app() cli.register(app) @@ -31,6 +31,7 @@ with app.app_context(): app.jinja_env.globals['len'] = len app.jinja_env.globals['digits'] = digits app.jinja_env.globals['str'] = str + app.jinja_env.globals['shorten_number'] = shorten_number app.jinja_env.globals['community_membership'] = community_membership app.jinja_env.globals['json_loads'] = json.loads app.jinja_env.globals['user_access'] = user_access