use native tera filters

This commit is contained in:
yggverse 2025-08-20 14:46:29 +03:00
parent 59b1df76c9
commit 02e8e1cfa7
3 changed files with 8 additions and 10 deletions

View file

@ -14,7 +14,6 @@ repository = "https://github.com/yggverse/mb"
anyhow = "1.0" anyhow = "1.0"
chrono = { version = "0.4.41", features = ["serde"] } chrono = { version = "0.4.41", features = ["serde"] }
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
plurify = "0.2"
redb = "3.0" redb = "3.0"
rocket = "0.5" rocket = "0.5"
rocket_dyn_templates = { version = "0.2", features = ["tera"] } rocket_dyn_templates = { version = "0.2", features = ["tera"] }

View file

@ -8,7 +8,6 @@ mod feed;
use config::Config; use config::Config;
use db::{Db, Order, Sort}; use db::{Db, Order, Sort};
use feed::Feed; use feed::Feed;
use plurify::Plurify;
use rocket::{ use rocket::{
State, State,
form::Form, form::Form,
@ -70,13 +69,9 @@ fn index(
back: page.map(|p| uri!(index(search, if p > 2 { Some(p - 1) } else { None }, token))), 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 } 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))) }, else { Some(uri!(index(search, Some(page.map_or(2, |p| p + 1)), token))) },
pagination_totals: if posts.total > 0 { Some(format!( total: posts.total,
"Page {} / {} ({} {} total)", page: page.unwrap_or(1),
page.unwrap_or(1), pages: (posts.total as f64 / config.limit as f64).ceil(),
(posts.total as f64 / config.limit as f64).ceil(),
posts.total,
posts.total.plurify(&["post", "posts", "posts"])
)) } else { None },
posts: posts.posts.into_iter().map(|p| Post { posts: posts.posts.into_iter().map(|p| Post {
id: p.id, id: p.id,
time: p.time().format(&config.time_format).to_string(), time: p.time().format(&config.time_format).to_string(),

View file

@ -29,5 +29,9 @@
{% endif %} {% endif %}
{% if next %}<a href="{{ next }}">Next</a>{% endif %} {% if next %}<a href="{{ next }}">Next</a>{% endif %}
{% if back %}<a href="{{ back }}">Back</a>{% endif %} {% if back %}<a href="{{ back }}">Back</a>{% endif %}
{% if pagination_totals %}<span>{{ pagination_totals }}</span>{% endif %} {% if total %}
<span>
Page {{ page }} / {{ pages }} ({{ total }} post{{ total | pluralize(plural="s") }} total)
</span>
{% endif %}
{% endblock content %} {% endblock content %}