From 02e8e1cfa73e2d385d5ac39c350cdcde7649224b Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 20 Aug 2025 14:46:29 +0300 Subject: [PATCH] use native tera filters --- Cargo.toml | 1 - src/main.rs | 11 +++-------- templates/index.html.tera | 6 +++++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f61a98c..0338fca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ repository = "https://github.com/yggverse/mb" anyhow = "1.0" chrono = { version = "0.4.41", features = ["serde"] } clap = { version = "4.5", features = ["derive"] } -plurify = "0.2" redb = "3.0" rocket = "0.5" rocket_dyn_templates = { version = "0.2", features = ["tera"] } diff --git a/src/main.rs b/src/main.rs index 4d5282d..475c64c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ mod feed; use config::Config; use db::{Db, Order, Sort}; use feed::Feed; -use plurify::Plurify; use rocket::{ State, form::Form, @@ -70,13 +69,9 @@ fn index( back: page.map(|p| uri!(index(search, if p > 2 { Some(p - 1) } else { None }, token))), next: if page.unwrap_or(1) * config.limit >= posts.total { None } else { Some(uri!(index(search, Some(page.map_or(2, |p| p + 1)), token))) }, - pagination_totals: if posts.total > 0 { Some(format!( - "Page {} / {} ({} {} total)", - page.unwrap_or(1), - (posts.total as f64 / config.limit as f64).ceil(), - posts.total, - posts.total.plurify(&["post", "posts", "posts"]) - )) } else { None }, + total: posts.total, + page: page.unwrap_or(1), + pages: (posts.total as f64 / config.limit as f64).ceil(), posts: posts.posts.into_iter().map(|p| Post { id: p.id, time: p.time().format(&config.time_format).to_string(), diff --git a/templates/index.html.tera b/templates/index.html.tera index cf358a6..7fbce0c 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -29,5 +29,9 @@ {% endif %} {% if next %}Next{% endif %} {% if back %}Back{% endif %} - {% if pagination_totals %}{{ pagination_totals }}{% endif %} + {% if total %} + + Page {{ page }} / {{ pages }} ({{ total }} post{{ total | pluralize(plural="s") }} total) + + {% endif %} {% endblock content %} \ No newline at end of file