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>
56 lines
2.7 KiB
Markdown
56 lines
2.7 KiB
Markdown
# v2.21.0: Paging for the homepage, likes and admin dashboard
|
|
|
|
## Why
|
|
|
|
The production site has 141 notes (140 published), but:
|
|
|
|
| Page | Showed | Cause |
|
|
|---|---|---|
|
|
| Homepage `/` | the 20 newest | `list_notes(..., limit=20)`, no paging |
|
|
| `/likes` | the 50 newest likes | `list_notes(..., limit=50)`, no paging |
|
|
| Admin dashboard | the 50 newest, as "Page 1 of 2" | it paged the result of `list_notes()`, whose default `limit` is 50 (since v1.6.0) |
|
|
|
|
So 120 published notes couldn't be reached from the homepage, and 91 notes
|
|
couldn't be reached from the admin list.
|
|
|
|
## How the homepage displays it
|
|
|
|
- The same note previews as before, 20 per page, newest first. Likes stay on
|
|
`/likes`, drafts are never shown.
|
|
- Below the last note: `← Newer` · `Page 2 of 7` · `Older →`. Page 1 has no
|
|
"Newer" link, the last page has no "Older" link, and a site with one page
|
|
of notes shows no pager at all.
|
|
- URLs: page 1 is `/` (and `/?page=1` redirects there with a 301). Later
|
|
pages are `/?page=N`. Their browser title is `Page N · <site name>`.
|
|
- `/likes` works the same way with 50 per page (`Likes · Page N · …`).
|
|
- The links are `<a rel="prev">` / `<a rel="next">` inside the h-feed, so
|
|
IndieWeb readers and Microsub clients can page back through the feed.
|
|
- A page number that isn't a positive whole number, or is past the last
|
|
page, is a 404.
|
|
|
|
## Changes
|
|
|
|
| Area | Change |
|
|
|---|---|
|
|
| `notes.count_notes(published_only, likes)` | New. `SELECT COUNT(*)` with the same filters as `list_notes()` (shared `_list_filters()`) |
|
|
| `routes/public.py` | `_paged_notes()` parses `?page=`, counts, and fetches one page with `limit`/`offset`. `_prepare_for_listing()` attaches media, tags, contexts and response counts (was duplicated in `index` and `likes`). `HOME_PER_PAGE = 20`, `LIKES_PER_PAGE = 50` |
|
|
| `templates/partials/pager.html` | `pager(endpoint, page, total_pages)` macro, used by `index.html` and `likes.html` |
|
|
| `routes/admin.py` dashboard | Counts with `count_notes()` and fetches only the requested 25. A bad or out-of-range `?page=` goes to the nearest valid page (admin only, so no 404) |
|
|
| `static/css/style.css` | `.pager` row: newer on the left, position in the middle, older on the right |
|
|
|
|
Feeds (RSS, Atom, JSON) are unchanged: they list the newest items only.
|
|
|
|
## Tests
|
|
|
|
`tests/test_paging.py`:
|
|
- `count_notes` filters;
|
|
- homepage first, middle and last pages, with `rel` links and titles;
|
|
- every published note reachable exactly once;
|
|
- drafts and likes never listed;
|
|
- the `?page=1` redirect;
|
|
- 404 for bad and out-of-range pages;
|
|
- no pager when there's a single page, and an empty site;
|
|
- likes page 2;
|
|
- the admin dashboard past 50 notes, including drafts, with bad-page
|
|
fallback.
|