Replace askama with rinja (#276)

This commit is contained in:
Guillaume Gomez 2024-10-02 23:43:13 +02:00 committed by GitHub
parent f71b0cd178
commit 1838fdaea4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 82 additions and 53 deletions

115
Cargo.lock generated
View File

@ -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"

View File

@ -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",

View File

@ -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?

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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};