Add related-posts section to the post reader

Add related-posts section to the post reader

#32 in Riparion/riparion-cms — merged 2026-06-01

Brings the previously-unmerged related-posts feature (originally on feat/related-posts, commit 89f996b) onto current main. It had drifted out of the UI because it was never merged — and main has since landed the complexity-cleanup refactor (#31) that split reader.rs into reader/ and the multi-backend (sqlite + postgres) Pool abstraction. This re-applies the feature adapted to both.

What it does

Shows summary cards for the most popular published posts sharing the current post's category or tags, between the reaction bar and comments on the single-post page.

  • related_posts_db — matches on shared category or any shared tag; ranks by shared-tag count, then view count, then recency. Excludes the post itself and unpublished posts.
  • related_posts server fn (POST /api/posts/related, limit clamped 1–6).
  • RelatedPosts component in reader/post.rs, rendered only for published posts and hidden entirely when there are no matches (no empty heading).

Adapted during the rebase

  • reader.rs was split into reader/ by #31 — the RelatedPosts component and its wiring now live in src/pages/reader/post.rs, and PostCardView is re-exported from widgets/mod.rs.
  • related_posts_db rewritten to use the Pool abstraction and $N placeholders with sqlx::AssertSqlSafe (the original predated the postgres backend and used SqlitePool + ?).
  • related_posts now calls attach_card_variants so related cards get the same responsive WebP/AVIF renditions as every other card-returning feed (the original predated responsive images).

Verification

  • cargo fmt --all -- --check
  • cargo clippy server,sqlite ✓ / server,postgres ✓ / web(wasm) ✓ — all -D warnings

🤖 Generated with Claude Code

Last updated 2026-06-02