feat: v2.21.0 paging for homepage, likes and admin dashboard

The homepage showed only the 20 newest notes and /likes the 50 newest,
with no way back. The admin dashboard paged list_notes()'s default 50
newest, so it always said 'Page 1 of 2'. All three now count with
count_notes() and fetch one page with limit/offset. Public pages get
'<- Newer / Page N of M / Older ->' with rel=prev/next (h-feed paging),
?page=1 redirects to the bare URL, bad pages 404; the dashboard falls
back to the nearest valid page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-27 20:51:30 -07:00
1 parent 9074c9a08c
commit 615354d17e
11 files changed
+373 -60

No files matched your search

+10 -12
View File
@@ -14,6 +14,7 @@ logger = logging.getLogger(__name__)
from starpunk.auth import require_auth
from starpunk.notes import (
count_notes,
create_note,
delete_note,
list_notes,
@@ -60,21 +61,18 @@ def dashboard():
from flask import current_app
import math
# Get pagination params (v1.6.0)
page = int(request.args.get('page', 1))
# Pagination (v1.6.0). Until v2.21.0 this paged list_notes()'s default
# 50 newest notes, so older notes never showed; now it counts all notes
# and fetches only the requested page. A bad ?page= falls back to the
# nearest valid page instead of a server error.
per_page = 25
# Get all notes (published and drafts)
all_notes = list_notes()
# Calculate pagination
total_notes = len(all_notes)
total_notes = count_notes()
total_pages = math.ceil(total_notes / per_page) if total_notes > 0 else 1
raw_page = request.args.get('page', '1')
page = int(raw_page) if raw_page.isdigit() else 1
page = min(max(page, 1), total_pages)
# Slice for current page
start_idx = (page - 1) * per_page
end_idx = start_idx + per_page
notes = all_notes[start_idx:end_idx]
notes = list_notes(limit=per_page, offset=(page - 1) * per_page)
# Get pending webmention count (v1.6.0)
webmention_pending_count = 0