fix pager

This commit is contained in:
Lera Elvoé 2025-07-01 19:02:47 +03:00
parent 18f4b026ea
commit f9256b70db
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
3 changed files with 6 additions and 6 deletions

View File

@ -31,7 +31,7 @@ def thread(slug):
("id", "<=", after_id), ("id", "<=", after_id),
]) ])
print(post_position) print(post_position)
page = math.floor((post_position + 1) / POSTS_PER_PAGE) + 1 page = math.ceil((post_position) / POSTS_PER_PAGE)
else: else:
page = max(1, min(page_count, int(request.args.get("page", default = 1)))) page = max(1, min(page_count, int(request.args.get("page", default = 1))))

View File

@ -1,6 +1,6 @@
{% macro pager(current_page, page_count) %} {% macro pager(current_page, page_count) %}
{% set left_start = (1, current_page - 5) | max %} {% set left_start = [1, current_page - 5] | max %}
{% set right_end = (page_count, current_page + 5) | min %} {% set right_end = [page_count, current_page + 5] | min %}
<div class="pager"> <div class="pager">
<span>Page:</span> <span>Page:</span>
{% if current_page > 5 %} {% if current_page > 5 %}
@ -9,13 +9,13 @@
<span class="currentpage">&hellip;</span> <span class="currentpage">&hellip;</span>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% for i in range(left_start, current_page - 1) %} {% for i in range(left_start, current_page) %}
<a href="?page={{i}}" class="pagebutton">{{i}}</a> <a href="?page={{i}}" class="pagebutton">{{i}}</a>
{% endfor %} {% endfor %}
{% if page_count > 0 %} {% if page_count > 0 %}
<span class="currentpage">{{current_page}}</span> <span class="currentpage">{{current_page}}</span>
{% endif %} {% endif %}
{% for i in range(current_page + 1, right_end) %} {% for i in range(current_page + 1, right_end + 1) %}
<a href="?page={{i}}" class="pagebutton">{{i}}</a> <a href="?page={{i}}" class="pagebutton">{{i}}</a>
{% endfor %} {% endfor %}
{% if right_end < page_count %} {% if right_end < page_count %}

View File

@ -45,7 +45,7 @@
</span> </span>
<span> <span>
Latest post by <a href="{{ url_for("users.page", username=thread['latest_post_username']) }}">{{ thread['latest_post_username'] }}</a> Latest post by <a href="{{ url_for("users.page", username=thread['latest_post_username']) }}">{{ thread['latest_post_username'] }}</a>
on <a href="{{ url_for("threads.thread", slug=thread['slug']) }}">on {{ timestamp(thread['latest_post_created_at'] )}}</a>: on <a href="{{ url_for("threads.thread", slug=thread['slug']) }}">on {{ timestamp(thread['latest_post_created_at']) }}</a>:
</span> </span>
<span class="thread-info-post-preview"> <span class="thread-info-post-preview">
{{ thread['latest_post_content'] | safe }} {{ thread['latest_post_content'] | safe }}