From 1838fdaea44b6aa25a8cc738341896209972a359 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 2 Oct 2024 23:43:13 +0200 Subject: [PATCH] Replace `askama` with `rinja` (#276) --- Cargo.lock | 115 +++++++++++++++++++++++++++---------------- Cargo.toml | 2 +- README.md | 2 +- src/duplicates.rs | 2 +- src/instance_info.rs | 2 +- src/post.rs | 2 +- src/search.rs | 2 +- src/settings.rs | 2 +- src/subreddit.rs | 2 +- src/user.rs | 2 +- src/utils.rs | 2 +- 11 files changed, 82 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9cdb90f..8a3a6f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -77,45 +78,6 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" -[[package]] -name = "askama" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" -dependencies = [ - "askama_derive", - "askama_escape", -] - -[[package]] -name = "askama_derive" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" -dependencies = [ - "askama_parser", - "mime", - "mime_guess", - "proc-macro2", - "quote", - "syn 2.0.68", -] - -[[package]] -name = "askama_escape" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" - -[[package]] -name = "askama_parser" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" -dependencies = [ - "nom", -] - [[package]] name = "async-recursion" version = "1.1.1" @@ -253,7 +215,7 @@ dependencies = [ "cached_proc_macro", "cached_proc_macro_types", "futures", - "hashbrown", + "hashbrown 0.14.5", "instant", "once_cell", "thiserror", @@ -767,6 +729,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -876,7 +844,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -937,7 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e0d73b369f386f1c44abd9c570d5318f55ccde816ff4b562fa452e5182863d" dependencies = [ "core2", - "hashbrown", + "hashbrown 0.14.5", "rle-decode-fast", ] @@ -1086,6 +1054,18 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "once_map" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed29bb6f7d6ac14023acb332a356f3891265d780e254057c866dbe7a909d2d2d" +dependencies = [ + "ahash", + "hashbrown 0.15.0", + "parking_lot", + "stable_deref_trait", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -1235,7 +1215,6 @@ name = "redlib" version = "0.35.1" dependencies = [ "arc-swap", - "askama", "async-recursion", "base64 0.22.1", "brotli", @@ -1255,6 +1234,7 @@ dependencies = [ "percent-encoding", "pretty_env_logger", "regex", + "rinja", "route-recognizer", "rss", "rust-embed", @@ -1323,6 +1303,43 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rinja" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28580fecce391f3c0e65a692e5f2b5db258ba2346ee04f355ae56473ab973dc" +dependencies = [ + "itoa", + "rinja_derive", +] + +[[package]] +name = "rinja_derive" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f1ae91455a4c82892d9513fcfa1ac8faff6c523602d0041536341882714aede" +dependencies = [ + "memchr", + "mime", + "mime_guess", + "once_map", + "proc-macro2", + "quote", + "rinja_parser", + "rustc-hash", + "syn 2.0.68", +] + +[[package]] +name = "rinja_parser" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea17639e1f35032e1c67539856e498c04cd65fe2a45f55ec437ec55e4be941" +dependencies = [ + "memchr", + "nom", +] + [[package]] name = "rle-decode-fast" version = "1.0.3" @@ -1388,6 +1405,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustix" version = "0.38.34" @@ -1698,6 +1721,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 06f6025..cac6f7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ authors = [ edition = "2021" [dependencies] -askama = { version = "0.12.1", default-features = false } +rinja = { version = "0.3.4", default-features = false } cached = { version = "0.51.3", features = ["async"] } clap = { version = "4.4.11", default-features = false, features = [ "std", diff --git a/README.md b/README.md index 4809b6c..040b44a 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Redlib currently implements most of Reddit's (signed-out) functionalities but st - [Rust](https://www.rust-lang.org/) - Programming language - [Hyper](https://github.com/hyperium/hyper) - HTTP server and client -- [Askama](https://github.com/djc/askama) - Templating engine +- [Rinja](https://github.com/rinja-rs/rinja) - Templating engine - [Rustls](https://github.com/rustls/rustls) - TLS library ## How is it different from other Reddit front ends? diff --git a/src/duplicates.rs b/src/duplicates.rs index 5a7653e..b533198 100644 --- a/src/duplicates.rs +++ b/src/duplicates.rs @@ -5,8 +5,8 @@ use crate::server::RequestExt; use crate::subreddit::{can_access_quarantine, quarantine}; use crate::utils::{error, filter_posts, get_filters, nsfw_landing, parse_post, template, Post, Preferences}; -use askama::Template; use hyper::{Body, Request, Response}; +use rinja::Template; use serde_json::Value; use std::borrow::ToOwned; use std::collections::HashSet; diff --git a/src/instance_info.rs b/src/instance_info.rs index 36182c1..c05ce5c 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -3,10 +3,10 @@ use crate::{ server::RequestExt, utils::{ErrorTemplate, Preferences}, }; -use askama::Template; use build_html::{Container, Html, HtmlContainer, Table}; use hyper::{http::Error, Body, Request, Response}; use once_cell::sync::Lazy; +use rinja::Template; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; diff --git a/src/post.rs b/src/post.rs index 2642d24..c887ed6 100644 --- a/src/post.rs +++ b/src/post.rs @@ -8,9 +8,9 @@ use crate::utils::{ }; use hyper::{Body, Request, Response}; -use askama::Template; use once_cell::sync::Lazy; use regex::Regex; +use rinja::Template; use std::collections::{HashMap, HashSet}; // STRUCTS diff --git a/src/search.rs b/src/search.rs index d30b146..f48b699 100644 --- a/src/search.rs +++ b/src/search.rs @@ -5,10 +5,10 @@ use crate::{ subreddit::{can_access_quarantine, quarantine}, RequestExt, }; -use askama::Template; use hyper::{Body, Request, Response}; use once_cell::sync::Lazy; use regex::Regex; +use rinja::Template; // STRUCTS struct SearchParams { diff --git a/src/settings.rs b/src/settings.rs index 6c0480c..5db1a03 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -3,10 +3,10 @@ use std::collections::HashMap; // CRATES use crate::server::ResponseExt; use crate::utils::{redirect, template, Preferences}; -use askama::Template; use cookie::Cookie; use futures_lite::StreamExt; use hyper::{Body, Request, Response}; +use rinja::Template; use time::{Duration, OffsetDateTime}; // STRUCTS diff --git a/src/subreddit.rs b/src/subreddit.rs index 8a9270e..a98455d 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -4,9 +4,9 @@ use crate::utils::{ catch_random, error, filter_posts, format_num, format_url, get_filters, nsfw_landing, param, redirect, rewrite_urls, setting, template, val, Post, Preferences, Subreddit, }; use crate::{client::json, server::ResponseExt, RequestExt}; -use askama::Template; use cookie::Cookie; use hyper::{Body, Request, Response}; +use rinja::Template; use once_cell::sync::Lazy; use regex::Regex; diff --git a/src/user.rs b/src/user.rs index 6ad8fbd..f141591 100644 --- a/src/user.rs +++ b/src/user.rs @@ -3,8 +3,8 @@ use crate::client::json; use crate::server::RequestExt; use crate::utils::{error, filter_posts, format_url, get_filters, nsfw_landing, param, setting, template, Post, Preferences, User}; use crate::{config, utils}; -use askama::Template; use hyper::{Body, Request, Response}; +use rinja::Template; use time::{macros::format_description, OffsetDateTime}; // STRUCTS diff --git a/src/utils.rs b/src/utils.rs index 987565f..6f97775 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,12 +4,12 @@ use crate::config::{self, get_setting}; // CRATES // use crate::{client::json, server::RequestExt}; -use askama::Template; use cookie::Cookie; use hyper::{Body, Request, Response}; use log::error; use once_cell::sync::Lazy; use regex::Regex; +use rinja::Template; use rust_embed::RustEmbed; use serde_json::Value; use serde_json_path::{JsonPath, JsonPathExt};