From d827614581694002a9528de645ef2a178fa79e94 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 12 Jan 2024 15:21:40 +0100 Subject: [PATCH 1/5] try hypertext crate --- Cargo.lock | 124 +++++++++++++++++++++++++++++------- Cargo.toml | 2 +- src/main.rs | 51 +++++++-------- src/routes/about.rs | 10 +-- src/routes/article.rs | 48 ++++++++------ src/routes/internet_news.rs | 32 ++++++---- src/routes/markets.rs | 15 +++-- src/routes/search.rs | 24 ++++--- 8 files changed, 201 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ca069d..f9a847c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,6 +349,15 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +[[package]] +name = "html-escape" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" +dependencies = [ + "utf8-width", +] + [[package]] name = "httparse" version = "1.8.0" @@ -361,6 +370,32 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "hypertext" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "433ad9f0cbac05d49d694122b745f827171f85b244d39b5fae196d103982b1e4" +dependencies = [ + "html-escape", + "hypertext-macros", + "itoa", + "ryu", +] + +[[package]] +name = "hypertext-macros" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3364b8fdf51347ebfcf472ccb715e6944b555bdc0ed208fecccae91ff0061db7" +dependencies = [ + "html-escape", + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "rstml", + "syn 2.0.27", +] + [[package]] name = "iana-time-zone" version = "0.1.57" @@ -457,28 +492,6 @@ version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" -[[package]] -name = "maud" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0bab19cef8a7fe1c18a43e881793bfc9d4ea984befec3ae5bd0415abf3ecf00" -dependencies = [ - "itoa", - "maud_macros", -] - -[[package]] -name = "maud_macros" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0be95d66c3024ffce639216058e5bae17a83ecaf266ffc6e4d060ad447c9eed2" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "memchr" version = "2.5.0" @@ -535,7 +548,7 @@ dependencies = [ "chrono", "glob", "grass", - "maud", + "hypertext", "pico-args", "rouille", "rustls", @@ -657,7 +670,6 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn 1.0.109", "version_check", ] @@ -687,6 +699,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "proc-macro2-diagnostics" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", + "version_check", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -787,6 +811,20 @@ dependencies = [ "url", ] +[[package]] +name = "rstml" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe542870b8f59dd45ad11d382e5339c9a1047cde059be136a7016095bbdefa77" +dependencies = [ + "proc-macro2", + "proc-macro2-diagnostics", + "quote", + "syn 2.0.27", + "syn_derive", + "thiserror", +] + [[package]] name = "rustix" version = "0.38.4" @@ -984,6 +1022,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.27", +] + [[package]] name = "tempfile" version = "3.7.0" @@ -997,6 +1047,26 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "thiserror" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.27", +] + [[package]] name = "threadpool" version = "1.8.1" @@ -1131,6 +1201,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index c182327..af57d4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,13 +7,13 @@ edition = "2021" rouille = { version = "3.6", default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -maud = "0.25" chrono = { version = "0.4", default-features = false, features = ["clock"] } ureq = { version = "2.7", features = ["json", "tls", "rustls"] } rustls = { version = "0.21", default-features = false } rustls-native-certs = "0.6" pico-args = "0.5.0" tl = "0.7.7" +hypertext = "0.3.1" [build-dependencies] grass = "0.13" diff --git a/src/main.rs b/src/main.rs index e47920b..68f073a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,34 +10,34 @@ use routes::{ markets::render_market, search::{render_search, render_section, render_topic}, }; +use hypertext::{html_elements, maud, GlobalAttributes, Rendered, Raw}; const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/main.css")); -macro_rules! document { - ($title:expr, $content:expr, $( $head:expr )? ) => { - maud::html! { - (maud::DOCTYPE) - html lang="en" { - head { - title { ($title) } - link rel="stylesheet" href="/main.css?v=0"; - meta name="viewport" content="width=device-width, initial-scale=1"; - $( ($head) )? - } - body { - main { ($content) } - footer { div { - a href="/" { "Home" } - " - " - a href="/search" { "Search" } - " - " - a href="/about" { "About" } } } +pub fn document(title: &str, content: &str, head: Option<&str>) -> Rendered { + maud! { + !DOCTYPE + html lang="en" { + head { + title { (title) } + link rel="stylesheet" href="/main.css?v=0"; + meta name="viewport" content="width=device-width, initial-scale=1"; + @if let Some(head) = head { + (Raw(head)) } } + body { + main { (Raw(content)) } + footer { div { + a href="/" { "Home" } + " - " + a href="/search" { "Search" } + " - " + a href="/about" { "About" } } } + } } - }; + }.render() } -pub(crate) use document; fn main() { let mut pargs = pico_args::Arguments::from_env(); @@ -147,14 +147,15 @@ fn main() { fn render_error(code: u16, message: &str, path: &str) -> rouille::Response { let title = format!("{} - {}", code, message); - let doc = document!( + let doc = document( &title, - maud::html! { - h1 { (&title) } + maud! { + h1 { (title.as_str()) } p { "You tried to access \"" (path) "\"" } p { a href="/" { "Go home" } } p { a href=(path) { "Try again" } } - }, + }.render().as_str(), + None ); rouille::Response::html(doc.into_string()).with_status_code(code) diff --git a/src/routes/about.rs b/src/routes/about.rs index 6b03a23..cdacd28 100644 --- a/src/routes/about.rs +++ b/src/routes/about.rs @@ -1,14 +1,13 @@ use crate::api::error::ApiResult; use crate::document; -use maud::html; +use hypertext::{html_elements, maud}; use std::env; - const GIT_HASH: &str = env!("GIT_HASH"); pub fn render_about() -> ApiResult { - let doc = document!( + let doc = document( "About", - html! { + maud! { h1 { "About" } p { "This is an alternative frontend to " a href="https://www.reuters.com/" { "Reuters" } ". It is intented to be lightweight, fast and was heavily inspired by " a href="https://nitter.net/" { "Nitter" } "." } ul { @@ -34,7 +33,8 @@ pub fn render_about() -> ApiResult { h2 { "Build information" } p { "This version is based off the git commit " a href=(format!("https://github.com/HookedBehemoth/neuters/commit/{}", GIT_HASH)) { (GIT_HASH) }} - }, + }.render().as_str(), + None ); Ok(doc.into_string()) diff --git a/src/routes/article.rs b/src/routes/article.rs index 10a02c2..e9d6152 100644 --- a/src/routes/article.rs +++ b/src/routes/article.rs @@ -3,7 +3,13 @@ use crate::{ render::byline, }; use chrono::{DateTime, Utc}; -use maud::{html, PreEscaped}; +use hypertext::{html_elements, maud, GlobalAttributes, Rendered, Raw, Attribute}; + +trait HtmxAttributes: GlobalAttributes { + const property: Attribute = Attribute; +} + +impl HtmxAttributes for T {} pub fn render_article(client: &ureq::Agent, path: &str) -> ApiResult { let article = fetch_article_by_url(client, path)?; @@ -13,34 +19,36 @@ pub fn render_article(client: &ureq::Agent, path: &str) -> ApiResult { .parse::>() .map(|time| time.format("%Y-%m-%d %H:%M").to_string()); - let doc = crate::document!( + let doc = crate::document( &article.title, - html!( - h1 { (&article.title) } + maud!( + h1 { (article.title.as_str()) } p class="byline" { @if let Some(authors) = &article.authors { @let byline = byline::render_byline(authors); - @if let Ok(time) = published_time { - (time) " - " + @if let Ok(time) = &published_time { + (time.as_str()) " - " } - (PreEscaped(byline)) + (Raw(byline)) } } - (render_items(&article.content_elements.unwrap_or_default())) - ), - html! { - meta property="og:title" content=(&article.title); + @if let Some(articles) = &article.content_elements { + (Raw(render_items(&articles))) + } + ).render().as_str(), + Some(maud! { + meta property="og:title" content=(article.title.as_str()); meta property="og:type" content="article"; - meta property="og:description" content=(&article.description); + meta property="og:description" content=(article.description.as_str()); meta property="og:url" content=(path); - } + }.render().as_str()) ); Ok(doc.into_string()) } -fn render_items(items: &[serde_json::Value]) -> maud::Markup { - html! { +fn render_items(items: &[serde_json::Value]) -> Rendered { + maud! { @for content in items { @match content["type"].as_str() { Some("header") => { @@ -54,7 +62,7 @@ fn render_items(items: &[serde_json::Value]) -> maud::Markup { } Some("paragraph") => { @if let Some(content) = content["content"].as_str() { - p { (PreEscaped(&content)) } + p { (Raw(&content)) } } } Some("image") => { @@ -94,7 +102,7 @@ fn render_items(items: &[serde_json::Value]) -> maud::Markup { tr { @let cells = match row.as_array() { Some(cells) => cells, None => continue }; @for cell in cells { - td { (PreEscaped(cell.as_str().unwrap_or_default())) } + td { (Raw(cell.as_str().unwrap_or_default())) } } } } @@ -103,7 +111,7 @@ fn render_items(items: &[serde_json::Value]) -> maud::Markup { } Some("list") => { @if let Some(items) = content["items"].as_array() { - (render_items(items)) + (Raw(render_items(items))) } } Some("social_media") => { @@ -113,12 +121,12 @@ fn render_items(items: &[serde_json::Value]) -> maud::Markup { } else { markup }; - (maud::PreEscaped(embed)) + (Raw(embed)) } } Some(unknown) => { p { "Unknown type: " (unknown) } } None => { p { "Failed to parse content element" } } } } - } + }.render() } diff --git a/src/routes/internet_news.rs b/src/routes/internet_news.rs index 8402d91..4d12dec 100644 --- a/src/routes/internet_news.rs +++ b/src/routes/internet_news.rs @@ -1,5 +1,5 @@ use chrono::{DateTime, Utc}; -use maud::{html, PreEscaped}; +use hypertext::{html_elements, maud, GlobalAttributes, Attribute, Raw}; use crate::{ api::{ @@ -9,6 +9,12 @@ use crate::{ render::legacy_article_byline::render_byline, }; +trait HtmxAttributes: GlobalAttributes { + const property: Attribute = Attribute; +} + +impl HtmxAttributes for T {} + pub fn render_legacy_article( client: &ureq::Agent, path: &str, @@ -56,22 +62,22 @@ pub fn render_legacy_article( .parse::>() .map(|time| time.format("%Y-%m-%d %H:%M").to_string()); - let doc = crate::document!( + let doc = crate::document( &article.headline, - html! { - h1 { (&article.headline) } + maud! { + h1 { (article.headline.as_str()) } p class="byline" { @let byline = render_byline(&article.authors); - @if let Ok(time) = published_time { - (time) " - " + @if let Ok(time) = &published_time { + (time.as_str()) " - " } - (PreEscaped(byline)) + (Raw(byline)) } @for content in article.body_items.iter() { @match content.r#type.as_str() { "paragraph" => { p { - (content.content) + (content.content.as_str()) } } t => { @@ -81,13 +87,13 @@ pub fn render_legacy_article( } } } - }, - html! { - meta property="og:title" content=(&article.headline); + }.render().as_str(), + Some(maud! { + meta property="og:title" content=(article.headline.as_str()); meta property="og:type" content="article"; - meta property="og:description" content=(&article.description); + meta property="og:description" content=(article.description.as_str()); meta property="og:url" content=(path); - } + }.render().as_str()) ); Ok(Ok(doc.into_string())) diff --git a/src/routes/markets.rs b/src/routes/markets.rs index 082cb46..7083077 100644 --- a/src/routes/markets.rs +++ b/src/routes/markets.rs @@ -1,4 +1,5 @@ use crate::api::{error::ApiResult, markit::fetch_by_stock_symbol}; +use hypertext::{html_elements, maud, GlobalAttributes}; pub fn render_market(client: &ureq::Agent, path: &str) -> ApiResult { let company = if let Some(end) = path.find('/') { @@ -9,17 +10,17 @@ pub fn render_market(client: &ureq::Agent, path: &str) -> ApiResult { let articles = fetch_by_stock_symbol(client, company)?; - let document = crate::document! { + let document = crate::document( company, - maud::html! { - company + maud! { + (company) ul { @for article in articles.articles.iter() { - li { a href=(&article.canonical_url) { (&article.title) } } + li { a href=(article.canonical_url.as_str()) { (article.title.as_str()) } } } } - }, - - }; + }.render().as_str(), + None + ); Ok(document.into_string()) } diff --git a/src/routes/search.rs b/src/routes/search.rs index 9a0c0fa..652d199 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -3,7 +3,7 @@ use crate::api::{ section::fetch_articles_by_section, topic::fetch_articles_by_topic, }; use crate::document; -use maud::html; +use hypertext::{html_elements, maud, GlobalAttributes, maud_static}; #[derive(PartialEq)] enum SearchType { @@ -43,15 +43,16 @@ pub fn render_search(client: &ureq::Agent, request: &rouille::Request) -> ApiRes render_articles(articles, &query, offset, size, SearchType::Query) } _ => { - let doc = document!( + let doc = document( "Neuters - Reuters Proxy - Search", - html! { + maud_static! { h1 { "Search:" } form { input type="text" name="query" placeholder="Keywords..." required=""; button type="submit" { "Search" } } - }, + }.as_str(), + None ); Ok(doc.into_string()) @@ -99,16 +100,18 @@ fn render_articles( } else { None }; + let prev_page = prev_page.as_ref().map(|p| p.as_str()); let next_page = if has_next { let offset = offset.saturating_add(steps).min(total - 1); Some(format!("{url}steps={steps}&offset={offset}")) } else { None }; + let next_page = next_page.as_ref().map(|p| p.as_str()); - let doc = document!( + let doc = document( "Neuters - Reuters Proxy", - html! { + maud! { h1 { (title) } @if search_type == SearchType::Query { form { @@ -116,23 +119,24 @@ fn render_articles( button type="submit" { "Search" } } } - @if let Some(articles) = articles.articles { + @if let Some(articles) = &articles.articles { ul { @for article in articles.iter() { - li { a href=(&article.canonical_url) { (&article.title) } } + li { a href=(article.canonical_url.as_str()) { (article.title.as_str()) } } } } @if total != 0 { div.nav { a href=[prev_page] { "<" } - ((offset + 1)) " to " ((offset + count)) " of " (total) + (offset + 1) " to " (offset + count) " of " (total) a href=[next_page] { ">" } } } } @else { p { "No results found!" } } - }, + }.render().as_str(), + None ); Ok(doc.into_string()) From b000aaff081cf5925bfe906d28798ee560549474 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 12 Jan 2024 15:39:02 +0100 Subject: [PATCH 2/5] hypertext: use old macro again --- src/main.rs | 56 +++++++++++++++++++------------------ src/routes/about.rs | 9 +++--- src/routes/article.rs | 12 ++++---- src/routes/internet_news.rs | 12 ++++---- src/routes/markets.rs | 7 ++--- src/routes/search.rs | 12 ++++---- 6 files changed, 53 insertions(+), 55 deletions(-) diff --git a/src/main.rs b/src/main.rs index 68f073a..7ae160e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,35 +10,38 @@ use routes::{ markets::render_market, search::{render_search, render_section, render_topic}, }; -use hypertext::{html_elements, maud, GlobalAttributes, Rendered, Raw}; +use hypertext::{html_elements, maud, GlobalAttributes, Rendered, Raw, Render}; const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/main.css")); -pub fn document(title: &str, content: &str, head: Option<&str>) -> Rendered { - maud! { - !DOCTYPE - html lang="en" { - head { - title { (title) } - link rel="stylesheet" href="/main.css?v=0"; - meta name="viewport" content="width=device-width, initial-scale=1"; - @if let Some(head) = head { - (Raw(head)) +// pub fn document(title: &str, content: &Render, head: Option<&Render>) -> Rendered { +macro_rules! document { + ($title:expr, $content:expr, $( $head:expr )? ) => { + maud! { + !DOCTYPE + html lang="en" { + head { + title { ($title) } + link rel="stylesheet" href="/main.css?v=0"; + meta name="viewport" content="width=device-width, initial-scale=1"; + $( ($head) )? + } + body { + main { ($content) } + footer { div { + a href="/" { "Home" } + " - " + a href="/search" { "Search" } + " - " + a href="/about" { "About" } } } } - } - body { - main { (Raw(content)) } - footer { div { - a href="/" { "Home" } - " - " - a href="/search" { "Search" } - " - " - a href="/about" { "About" } } } } } - }.render() + } } +pub(crate) use document; + fn main() { let mut pargs = pico_args::Arguments::from_env(); let list_address: String = pargs @@ -147,18 +150,17 @@ fn main() { fn render_error(code: u16, message: &str, path: &str) -> rouille::Response { let title = format!("{} - {}", code, message); - let doc = document( - &title, - maud! { + let doc = document!( + title.as_str(), + &maud! { h1 { (title.as_str()) } p { "You tried to access \"" (path) "\"" } p { a href="/" { "Go home" } } p { a href=(path) { "Try again" } } - }.render().as_str(), - None + }, ); - rouille::Response::html(doc.into_string()).with_status_code(code) + rouille::Response::html(doc.render()).with_status_code(code) } fn render_api_error(err: &ApiError, path: &str) -> rouille::Response { diff --git a/src/routes/about.rs b/src/routes/about.rs index cdacd28..32d9fe2 100644 --- a/src/routes/about.rs +++ b/src/routes/about.rs @@ -1,11 +1,11 @@ use crate::api::error::ApiResult; use crate::document; -use hypertext::{html_elements, maud}; +use hypertext::{html_elements, maud, GlobalAttributes}; use std::env; const GIT_HASH: &str = env!("GIT_HASH"); pub fn render_about() -> ApiResult { - let doc = document( + let doc = document!( "About", maud! { h1 { "About" } @@ -33,9 +33,8 @@ pub fn render_about() -> ApiResult { h2 { "Build information" } p { "This version is based off the git commit " a href=(format!("https://github.com/HookedBehemoth/neuters/commit/{}", GIT_HASH)) { (GIT_HASH) }} - }.render().as_str(), - None + }, ); - Ok(doc.into_string()) + Ok(doc.render().0) } diff --git a/src/routes/article.rs b/src/routes/article.rs index e9d6152..cb6ab74 100644 --- a/src/routes/article.rs +++ b/src/routes/article.rs @@ -19,8 +19,8 @@ pub fn render_article(client: &ureq::Agent, path: &str) -> ApiResult { .parse::>() .map(|time| time.format("%Y-%m-%d %H:%M").to_string()); - let doc = crate::document( - &article.title, + let doc = crate::document!( + article.title.as_str(), maud!( h1 { (article.title.as_str()) } p class="byline" { @@ -35,16 +35,16 @@ pub fn render_article(client: &ureq::Agent, path: &str) -> ApiResult { @if let Some(articles) = &article.content_elements { (Raw(render_items(&articles))) } - ).render().as_str(), - Some(maud! { + ), + maud! { meta property="og:title" content=(article.title.as_str()); meta property="og:type" content="article"; meta property="og:description" content=(article.description.as_str()); meta property="og:url" content=(path); - }.render().as_str()) + } ); - Ok(doc.into_string()) + Ok(doc.render().0) } fn render_items(items: &[serde_json::Value]) -> Rendered { diff --git a/src/routes/internet_news.rs b/src/routes/internet_news.rs index 4d12dec..4907ac6 100644 --- a/src/routes/internet_news.rs +++ b/src/routes/internet_news.rs @@ -62,8 +62,8 @@ pub fn render_legacy_article( .parse::>() .map(|time| time.format("%Y-%m-%d %H:%M").to_string()); - let doc = crate::document( - &article.headline, + let doc = crate::document!( + article.headline.as_str(), maud! { h1 { (article.headline.as_str()) } p class="byline" { @@ -87,14 +87,14 @@ pub fn render_legacy_article( } } } - }.render().as_str(), - Some(maud! { + }, + maud! { meta property="og:title" content=(article.headline.as_str()); meta property="og:type" content="article"; meta property="og:description" content=(article.description.as_str()); meta property="og:url" content=(path); - }.render().as_str()) + } ); - Ok(Ok(doc.into_string())) + Ok(Ok(doc.render().0)) } diff --git a/src/routes/markets.rs b/src/routes/markets.rs index 7083077..2c5acb9 100644 --- a/src/routes/markets.rs +++ b/src/routes/markets.rs @@ -10,7 +10,7 @@ pub fn render_market(client: &ureq::Agent, path: &str) -> ApiResult { let articles = fetch_by_stock_symbol(client, company)?; - let document = crate::document( + let document = crate::document!( company, maud! { (company) @@ -19,8 +19,7 @@ pub fn render_market(client: &ureq::Agent, path: &str) -> ApiResult { li { a href=(article.canonical_url.as_str()) { (article.title.as_str()) } } } } - }.render().as_str(), - None + }, ); - Ok(document.into_string()) + Ok(document.render().0) } diff --git a/src/routes/search.rs b/src/routes/search.rs index 652d199..e254598 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -43,7 +43,7 @@ pub fn render_search(client: &ureq::Agent, request: &rouille::Request) -> ApiRes render_articles(articles, &query, offset, size, SearchType::Query) } _ => { - let doc = document( + let doc = document!( "Neuters - Reuters Proxy - Search", maud_static! { h1 { "Search:" } @@ -52,10 +52,9 @@ pub fn render_search(client: &ureq::Agent, request: &rouille::Request) -> ApiRes button type="submit" { "Search" } } }.as_str(), - None ); - Ok(doc.into_string()) + Ok(doc.render().0) } } } @@ -109,7 +108,7 @@ fn render_articles( }; let next_page = next_page.as_ref().map(|p| p.as_str()); - let doc = document( + let doc = document!( "Neuters - Reuters Proxy", maud! { h1 { (title) } @@ -135,9 +134,8 @@ fn render_articles( } @else { p { "No results found!" } } - }.render().as_str(), - None + }, ); - Ok(doc.into_string()) + Ok(doc.render().0) } From 31b1d164dade1ddad89de81698e7302506980ee3 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 12 Jan 2024 15:42:28 +0100 Subject: [PATCH 3/5] misc format --- build.rs | 4 ++-- src/main.rs | 3 +-- src/routes/article.rs | 3 ++- src/routes/internet_news.rs | 1 + src/routes/search.rs | 8 +++----- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index 4a68d71..eff69fb 100644 --- a/build.rs +++ b/build.rs @@ -6,7 +6,7 @@ use std::process::Command; fn main() { let output = Command::new("git") - .args(&["rev-parse", "HEAD"]) + .args(["rev-parse", "HEAD"]) .output() .unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap(); @@ -30,5 +30,5 @@ fn main() { let css = grass::from_path(src, &options).unwrap(); let dst = out_dir.join(dst); - fs::write(dst, &css).unwrap(); + fs::write(dst, css).unwrap(); } diff --git a/src/main.rs b/src/main.rs index 7ae160e..d21e20b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,11 +10,10 @@ use routes::{ markets::render_market, search::{render_search, render_section, render_topic}, }; -use hypertext::{html_elements, maud, GlobalAttributes, Rendered, Raw, Render}; +use hypertext::{html_elements, maud, GlobalAttributes}; const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/main.css")); -// pub fn document(title: &str, content: &Render, head: Option<&Render>) -> Rendered { macro_rules! document { ($title:expr, $content:expr, $( $head:expr )? ) => { maud! { diff --git a/src/routes/article.rs b/src/routes/article.rs index cb6ab74..d684824 100644 --- a/src/routes/article.rs +++ b/src/routes/article.rs @@ -6,6 +6,7 @@ use chrono::{DateTime, Utc}; use hypertext::{html_elements, maud, GlobalAttributes, Rendered, Raw, Attribute}; trait HtmxAttributes: GlobalAttributes { + #[allow(non_upper_case_globals)] const property: Attribute = Attribute; } @@ -33,7 +34,7 @@ pub fn render_article(client: &ureq::Agent, path: &str) -> ApiResult { } } @if let Some(articles) = &article.content_elements { - (Raw(render_items(&articles))) + (Raw(render_items(articles))) } ), maud! { diff --git a/src/routes/internet_news.rs b/src/routes/internet_news.rs index 4907ac6..d308320 100644 --- a/src/routes/internet_news.rs +++ b/src/routes/internet_news.rs @@ -10,6 +10,7 @@ use crate::{ }; trait HtmxAttributes: GlobalAttributes { + #[allow(non_upper_case_globals)] const property: Attribute = Attribute; } diff --git a/src/routes/search.rs b/src/routes/search.rs index e254598..bd04c36 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -79,7 +79,7 @@ fn render_articles( articles .topics .as_ref() - .and_then(|t| t.get(0).map(|t| t.name.as_str())) + .and_then(|t| t.first().map(|t| t.name.as_str())) .unwrap_or(""), format!("{path}?"), ), @@ -99,14 +99,12 @@ fn render_articles( } else { None }; - let prev_page = prev_page.as_ref().map(|p| p.as_str()); let next_page = if has_next { let offset = offset.saturating_add(steps).min(total - 1); Some(format!("{url}steps={steps}&offset={offset}")) } else { None }; - let next_page = next_page.as_ref().map(|p| p.as_str()); let doc = document!( "Neuters - Reuters Proxy", @@ -126,9 +124,9 @@ fn render_articles( } @if total != 0 { div.nav { - a href=[prev_page] { "<" } + a href=[prev_page.as_deref()] { "<" } (offset + 1) " to " (offset + count) " of " (total) - a href=[next_page] { ">" } + a href=[next_page.as_deref()] { ">" } } } } @else { From 486a475c31551adaf16e50135ec00c9f633a496e Mon Sep 17 00:00:00 2001 From: Vidhan Bhatt Date: Fri, 12 Jan 2024 11:45:01 -0500 Subject: [PATCH 4/5] feat: enhance hypertext usage --- Cargo.lock | 540 ++++++++++++++-------------- Cargo.toml | 2 +- src/main.rs | 10 +- src/render/byline.rs | 51 ++- src/render/legacy_article_byline.rs | 55 ++- src/routes/about.rs | 4 +- src/routes/article.rs | 35 +- src/routes/internet_news.rs | 27 +- src/routes/markets.rs | 9 +- src/routes/mod.rs | 9 + src/routes/search.rs | 8 +- 11 files changed, 376 insertions(+), 374 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9a847c..248118a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" dependencies = [ "getrandom", "once_cell", @@ -36,51 +36,50 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "1.0.1" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -103,9 +102,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bitflags" @@ -115,9 +114,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "buf_redux" @@ -131,15 +130,18 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -149,36 +151,36 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "winapi", + "windows-targets 0.48.5", ] [[package]] name = "chunked_transfer" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cca491388666e04d7248af3f60f0c40cfb0991c72205595d7c396e3510207d1a" +checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" [[package]] name = "clap" -version = "4.3.19" +version = "4.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +checksum = "58e54881c004cec7895b0068a0a954cd5d62da01aef83fa35b1e594497bf5445" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.3.19" +version = "4.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +checksum = "59cb82d7f531603d2fd1f507441cdd35184fa81beff7bd489570de7f773460bb" dependencies = [ "anstream", "anstyle", @@ -188,9 +190,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "codemap" @@ -206,9 +208,9 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -216,9 +218,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "crc32fast" @@ -230,49 +232,47 @@ dependencies = [ ] [[package]] -name = "errno" -version = "0.3.2" +name = "deranged" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys", + "powerfmt", ] [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "errno" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "filetime" -version = "0.2.21" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.2.16", - "windows-sys", + "redox_syscall", + "windows-sys 0.52.0", ] [[package]] name = "flate2" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -280,18 +280,18 @@ dependencies = [ [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -345,9 +345,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "html-escape" @@ -366,15 +366,15 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hypertext" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433ad9f0cbac05d49d694122b745f827171f85b244d39b5fae196d103982b1e4" +checksum = "73311860b34048c57abe0f2c425e971c175954b5fec2fdb8141d439f20454eeb" dependencies = [ "html-escape", "hypertext-macros", @@ -384,30 +384,30 @@ dependencies = [ [[package]] name = "hypertext-macros" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3364b8fdf51347ebfcf472ccb715e6944b555bdc0ed208fecccae91ff0061db7" +checksum = "b99f9f43f32d1e8ed1dec71a1d8ca9de5c078f0dde5388fcd1cd7b94d0e9ef7a" dependencies = [ "html-escape", "proc-macro2", "proc-macro2-diagnostics", "quote", "rstml", - "syn 2.0.27", + "syn 2.0.48", ] [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -421,9 +421,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -439,28 +439,17 @@ dependencies = [ "hashbrown 0.12.3", ] -[[package]] -name = "is-terminal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix", - "windows-sys", -] - [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -476,27 +465,27 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.147" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" @@ -561,9 +550,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -589,9 +578,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl-probe" @@ -601,9 +590,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "phf" @@ -655,6 +644,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -692,9 +687,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -707,7 +702,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.48", "version_check", ] @@ -719,9 +714,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.32" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -758,35 +753,25 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ "bitflags 1.3.2", ] [[package]] name = "ring" -version = "0.16.20" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", + "getrandom", "libc", - "once_cell", "spin", "untrusted", - "web-sys", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -820,33 +805,33 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.27", + "syn 2.0.48", "syn_derive", "thiserror", ] [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "rustls" -version = "0.21.5" +version = "0.21.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" dependencies = [ "log", "ring", - "rustls-webpki 0.101.2", + "rustls-webpki", "sct", ] @@ -864,28 +849,18 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" -dependencies = [ - "base64 0.21.2", -] - -[[package]] -name = "rustls-webpki" -version = "0.100.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "ring", - "untrusted", + "base64 0.21.7", ] [[package]] name = "rustls-webpki" -version = "0.101.2" +version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513722fd73ad80a71f72b61009ea1b584bcfa1483ca93949c8f290298837fa59" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ "ring", "untrusted", @@ -893,9 +868,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "safemem" @@ -905,18 +880,18 @@ checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" [[package]] name = "schannel" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "sct" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ "ring", "untrusted", @@ -947,29 +922,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.178" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60363bdd39a7be0266a520dab25fdc9241d2f987b08a01e01f0ec6d06a981348" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.178" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28482318d6641454cb273da158647922d1be6b5a2fcc6165cd89ebdd7ed576b" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.104" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "itoa", "ryu", @@ -984,15 +959,15 @@ checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" [[package]] name = "siphasher" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "spin" -version = "0.5.2" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "strsim" @@ -1013,9 +988,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.27" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -1031,40 +1006,40 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.48", ] [[package]] name = "tempfile" -version = "3.7.0" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.3.5", + "redox_syscall", "rustix", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "thiserror" -version = "1.0.55" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3de26b0965292219b4287ff031fcba86837900fe9cd2b34ea8ad893c0953d2" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.55" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "268026685b2be38d7103e9e507c938a1fcb3d7e6eb15e87870b617bf37b6d581" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.48", ] [[package]] @@ -1078,21 +1053,23 @@ dependencies = [ [[package]] name = "time" -version = "0.3.23" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" dependencies = [ + "deranged", "libc", "num_threads", + "powerfmt", "serde", "time-core", ] [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "tiny_http" @@ -1138,24 +1115,24 @@ dependencies = [ [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" @@ -1168,22 +1145,22 @@ dependencies = [ [[package]] name = "untrusted" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.7.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b11c96ac7ee530603dcdf68ed1557050f374ce55a5a07193ebf8cbc9f8927e9" +checksum = "f5ccd538d4a604753ebc2f17cd9946e89b77bf87f6a8e2309667c6f2e87855e3" dependencies = [ - "base64 0.21.2", + "base64 0.21.7", "flate2", "log", "once_cell", "rustls", - "rustls-webpki 0.100.1", + "rustls-webpki", "serde", "serde_json", "url", @@ -1192,9 +1169,9 @@ dependencies = [ [[package]] name = "url" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", @@ -1227,9 +1204,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1237,24 +1214,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1262,135 +1239,166 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.27", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] -name = "web-sys" -version = "0.3.64" +name = "webpki-roots" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" -dependencies = [ - "js-sys", - "wasm-bindgen", -] +checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" [[package]] -name = "webpki-roots" -version = "0.23.1" +name = "windows-core" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "rustls-webpki 0.100.1", + "windows-targets 0.52.0", ] [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows-targets 0.48.5", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows" -version = "0.48.0" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.0", ] [[package]] -name = "windows-sys" -version = "0.48.0" +name = "windows-targets" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows-targets", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/Cargo.toml b/Cargo.toml index af57d4c..d44e02d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ rustls = { version = "0.21", default-features = false } rustls-native-certs = "0.6" pico-args = "0.5.0" tl = "0.7.7" -hypertext = "0.3.1" +hypertext = "0.4" [build-dependencies] grass = "0.13" diff --git a/src/main.rs b/src/main.rs index d21e20b..50467a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod render; mod routes; use api::error::ApiError; +use hypertext::{html_elements, maud, GlobalAttributes, Renderable}; use routes::{ about::render_about, article::render_article, @@ -10,7 +11,6 @@ use routes::{ markets::render_market, search::{render_search, render_section, render_topic}, }; -use hypertext::{html_elements, maud, GlobalAttributes}; const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/main.css")); @@ -147,12 +147,12 @@ fn main() { } fn render_error(code: u16, message: &str, path: &str) -> rouille::Response { - let title = format!("{} - {}", code, message); + let title = maud!((code) " - " (message)); let doc = document!( - title.as_str(), - &maud! { - h1 { (title.as_str()) } + title, + maud! { + h1 { (title) } p { "You tried to access \"" (path) "\"" } p { a href="/" { "Go home" } } p { a href=(path) { "Try again" } } diff --git a/src/render/byline.rs b/src/render/byline.rs index 1391dd9..ad95a74 100644 --- a/src/render/byline.rs +++ b/src/render/byline.rs @@ -1,35 +1,34 @@ -use crate::api::common::Topic; -use std::fmt::Write; +use hypertext::{maud, Renderable}; -pub fn render_byline(authors: &[Topic]) -> String { - match authors.len() { - 0 => "".to_string(), - 1 => format_author(&authors[0]), - author_count => { - /* Chain author names together */ - let mut byline = "By ".to_string(); +use crate::api::common::Topic; +use hypertext::html_elements; - for author in authors[..author_count - 2].iter() { - byline.push_str(&format_author(author)); - byline.push_str(", "); +pub fn render_byline(authors: &[Topic]) -> impl Renderable + '_ { + maud! { + @match authors.len() { + 0 => {}, + 1 => (format_author(&authors[0])), + author_count => { + "By " + @for author in &authors[..author_count - 2] { + (format_author(author)) ", " + } + (format_author(&authors[author_count - 2])) + " and " + (format_author(&authors[author_count - 1])) } - - let _ = write!( - byline, - "{} and {}", - format_author(&authors[author_count - 2]), - format_author(&authors[author_count - 1]) - ); - - byline } } } -pub fn format_author(author: &Topic) -> String { - if let Some(url) = &author.topic_url { - format!("{}", url, author.byline) - } else { - author.byline.clone() +pub fn format_author(author: &Topic) -> impl Renderable + '_ { + maud! { + @if let Some(url) = &author.topic_url { + a href=(url) { + (&author.byline) + } + } @else { + (&author.byline) + } } } diff --git a/src/render/legacy_article_byline.rs b/src/render/legacy_article_byline.rs index dc53173..5e343eb 100644 --- a/src/render/legacy_article_byline.rs +++ b/src/render/legacy_article_byline.rs @@ -1,38 +1,37 @@ -use std::fmt::Write; +use hypertext::{html_elements, maud, Renderable}; use crate::api::legacy_article::LegacyArticleAuthor; -pub fn render_byline(authors: &[LegacyArticleAuthor]) -> String { - match authors.len() { - 0 => "".to_string(), - 1 => format_author(&authors[0]), - author_count => { - /* Chain author names together */ - let mut byline = "By ".to_string(); - - for author in authors[..author_count - 2].iter() { - byline.push_str(&format_author(author)); - byline.push_str(", "); +pub fn render_byline(authors: &[LegacyArticleAuthor]) -> impl Renderable + '_ { + maud! { + @match authors.len() { + 0 => {}, + 1 => (format_author(&authors[0])), + author_count => { + "By " + @for author in &authors[..author_count - 2] { + (format_author(author)) ", " + } + (format_author(&authors[author_count - 2])) + " and " + (format_author(&authors[author_count - 1])) } - - let _ = write!( - byline, - "{} and {}", - format_author(&authors[author_count - 2]), - format_author(&authors[author_count - 1]) - ); - - byline } } } -pub fn format_author(author: &LegacyArticleAuthor) -> String { - match author - .url - .strip_prefix("https://www.reuters.com/journalists/") - { - Some(path) => format!("{}", path, author.name), - None => format!("{}", author.url, author.name), +pub fn format_author(author: &LegacyArticleAuthor) -> impl Renderable + '_ { + maud! { + a href=@if let Some(path) = author + .url + .strip_prefix("https://www.reuters.com/journalists/") + { + "/journalists/" (path) "/" + } @else { + (&author.url) + } + { + (&author.name) + } } } diff --git a/src/routes/about.rs b/src/routes/about.rs index 32d9fe2..8cf5575 100644 --- a/src/routes/about.rs +++ b/src/routes/about.rs @@ -1,6 +1,6 @@ use crate::api::error::ApiResult; use crate::document; -use hypertext::{html_elements, maud, GlobalAttributes}; +use hypertext::{html_elements, maud, GlobalAttributes, Renderable}; use std::env; const GIT_HASH: &str = env!("GIT_HASH"); @@ -36,5 +36,5 @@ pub fn render_about() -> ApiResult { }, ); - Ok(doc.render().0) + Ok(doc.render().into_inner()) } diff --git a/src/routes/article.rs b/src/routes/article.rs index d684824..0996c0e 100644 --- a/src/routes/article.rs +++ b/src/routes/article.rs @@ -1,16 +1,10 @@ use crate::{ api::{article::fetch_article_by_url, error::ApiResult}, render::byline, + routes::HtmxAttributes, }; use chrono::{DateTime, Utc}; -use hypertext::{html_elements, maud, GlobalAttributes, Rendered, Raw, Attribute}; - -trait HtmxAttributes: GlobalAttributes { - #[allow(non_upper_case_globals)] - const property: Attribute = Attribute; -} - -impl HtmxAttributes for T {} +use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable}; pub fn render_article(client: &ureq::Agent, path: &str) -> ApiResult { let article = fetch_article_by_url(client, path)?; @@ -21,35 +15,34 @@ pub fn render_article(client: &ureq::Agent, path: &str) -> ApiResult { .map(|time| time.format("%Y-%m-%d %H:%M").to_string()); let doc = crate::document!( - article.title.as_str(), + &article.title, maud!( - h1 { (article.title.as_str()) } + h1 { (&article.title) } p class="byline" { @if let Some(authors) = &article.authors { - @let byline = byline::render_byline(authors); @if let Ok(time) = &published_time { - (time.as_str()) " - " + (time) " - " } - (Raw(byline)) + (byline::render_byline(authors)) } } @if let Some(articles) = &article.content_elements { - (Raw(render_items(articles))) + (render_items(articles)) } ), maud! { - meta property="og:title" content=(article.title.as_str()); + meta property="og:title" content=(&article.title); meta property="og:type" content="article"; - meta property="og:description" content=(article.description.as_str()); + meta property="og:description" content=(&article.description); meta property="og:url" content=(path); } ); - Ok(doc.render().0) + Ok(doc.render().into_inner()) } -fn render_items(items: &[serde_json::Value]) -> Rendered { - maud! { +fn render_items(items: &[serde_json::Value]) -> impl Renderable + '_ { + maud_move! { @for content in items { @match content["type"].as_str() { Some("header") => { @@ -112,7 +105,7 @@ fn render_items(items: &[serde_json::Value]) -> Rendered { } Some("list") => { @if let Some(items) = content["items"].as_array() { - (Raw(render_items(items))) + (render_items(items)) } } Some("social_media") => { @@ -129,5 +122,5 @@ fn render_items(items: &[serde_json::Value]) -> Rendered { None => { p { "Failed to parse content element" } } } } - }.render() + } } diff --git a/src/routes/internet_news.rs b/src/routes/internet_news.rs index d308320..94a3def 100644 --- a/src/routes/internet_news.rs +++ b/src/routes/internet_news.rs @@ -1,5 +1,5 @@ use chrono::{DateTime, Utc}; -use hypertext::{html_elements, maud, GlobalAttributes, Attribute, Raw}; +use hypertext::{html_elements, maud, GlobalAttributes, Renderable}; use crate::{ api::{ @@ -7,15 +7,9 @@ use crate::{ legacy_article::{fetch_legacy_article, parse_legacy_article}, }, render::legacy_article_byline::render_byline, + routes::HtmxAttributes, }; -trait HtmxAttributes: GlobalAttributes { - #[allow(non_upper_case_globals)] - const property: Attribute = Attribute; -} - -impl HtmxAttributes for T {} - pub fn render_legacy_article( client: &ureq::Agent, path: &str, @@ -64,21 +58,20 @@ pub fn render_legacy_article( .map(|time| time.format("%Y-%m-%d %H:%M").to_string()); let doc = crate::document!( - article.headline.as_str(), + &article.headline, maud! { - h1 { (article.headline.as_str()) } + h1 { (&article.headline) } p class="byline" { - @let byline = render_byline(&article.authors); @if let Ok(time) = &published_time { - (time.as_str()) " - " + (time) " - " } - (Raw(byline)) + (render_byline(&article.authors)) } @for content in article.body_items.iter() { @match content.r#type.as_str() { "paragraph" => { p { - (content.content.as_str()) + (&content.content) } } t => { @@ -90,12 +83,12 @@ pub fn render_legacy_article( } }, maud! { - meta property="og:title" content=(article.headline.as_str()); + meta property="og:title" content=(&article.headline); meta property="og:type" content="article"; - meta property="og:description" content=(article.description.as_str()); + meta property="og:description" content=(&article.description); meta property="og:url" content=(path); } ); - Ok(Ok(doc.render().0)) + Ok(Ok(doc.render().into_inner())) } diff --git a/src/routes/markets.rs b/src/routes/markets.rs index 2c5acb9..db3f05e 100644 --- a/src/routes/markets.rs +++ b/src/routes/markets.rs @@ -1,5 +1,5 @@ use crate::api::{error::ApiResult, markit::fetch_by_stock_symbol}; -use hypertext::{html_elements, maud, GlobalAttributes}; +use hypertext::{html_elements, maud, GlobalAttributes, Renderable}; pub fn render_market(client: &ureq::Agent, path: &str) -> ApiResult { let company = if let Some(end) = path.find('/') { @@ -10,16 +10,17 @@ pub fn render_market(client: &ureq::Agent, path: &str) -> ApiResult { let articles = fetch_by_stock_symbol(client, company)?; - let document = crate::document!( + let doc = crate::document!( company, maud! { (company) ul { @for article in articles.articles.iter() { - li { a href=(article.canonical_url.as_str()) { (article.title.as_str()) } } + li { a href=(&article.canonical_url) { (&article.title) } } } } }, ); - Ok(document.render().0) + + Ok(doc.render().into_inner()) } diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 840e3a6..093eded 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,5 +1,14 @@ +use hypertext::{Attribute, GlobalAttributes}; + pub mod about; pub mod article; pub mod internet_news; pub mod markets; pub mod search; + +trait HtmxAttributes: GlobalAttributes { + #[allow(non_upper_case_globals)] + const property: Attribute = Attribute; +} + +impl HtmxAttributes for T {} diff --git a/src/routes/search.rs b/src/routes/search.rs index bd04c36..0d56a23 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -3,7 +3,7 @@ use crate::api::{ section::fetch_articles_by_section, topic::fetch_articles_by_topic, }; use crate::document; -use hypertext::{html_elements, maud, GlobalAttributes, maud_static}; +use hypertext::{html_elements, maud, GlobalAttributes, Renderable}; #[derive(PartialEq)] enum SearchType { @@ -45,13 +45,13 @@ pub fn render_search(client: &ureq::Agent, request: &rouille::Request) -> ApiRes _ => { let doc = document!( "Neuters - Reuters Proxy - Search", - maud_static! { + maud! { h1 { "Search:" } form { input type="text" name="query" placeholder="Keywords..." required=""; button type="submit" { "Search" } } - }.as_str(), + }, ); Ok(doc.render().0) @@ -119,7 +119,7 @@ fn render_articles( @if let Some(articles) = &articles.articles { ul { @for article in articles.iter() { - li { a href=(article.canonical_url.as_str()) { (article.title.as_str()) } } + li { a href=(&article.canonical_url) { (&article.title) } } } } @if total != 0 { From fc1a5e7a704f216664498954ac5707211177a1a6 Mon Sep 17 00:00:00 2001 From: Vidhan Bhatt Date: Fri, 12 Jan 2024 11:47:46 -0500 Subject: [PATCH 5/5] refactor: more format! replaced with splices --- src/routes/about.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/about.rs b/src/routes/about.rs index 8cf5575..c3a7dba 100644 --- a/src/routes/about.rs +++ b/src/routes/about.rs @@ -32,7 +32,7 @@ pub fn render_about() -> ApiResult { p { "This project is licensed under the " a href="https://www.gnu.org/licenses/licenses.html#AGPL" { "GNU Affero General Public License" } "." } h2 { "Build information" } - p { "This version is based off the git commit " a href=(format!("https://github.com/HookedBehemoth/neuters/commit/{}", GIT_HASH)) { (GIT_HASH) }} + p { "This version is based off the git commit " a href={ "https://github.com/HookedBehemoth/neuters/commit/" (GIT_HASH) } { (GIT_HASH) }} }, );