From 35a484da7d554f923dc494792e30472154e5db82 Mon Sep 17 00:00:00 2001 From: "Ms. Haze" Date: Wed, 17 Sep 2025 18:44:05 -0400 Subject: [PATCH 1/3] Subdivided everything into Features --- Cargo.lock | 39 -------------------- Cargo.toml | 87 +++++++++++++++++++++++++-------------------- src/cached.rs | 3 ++ src/generate/mod.rs | 1 + src/lib.rs | 9 +++++ src/types.rs | 2 ++ src/utils.rs | 2 ++ 7 files changed, 66 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63f503e..b93f446 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,15 +41,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - [[package]] name = "ammonia" version = "4.0.0" @@ -902,7 +893,6 @@ dependencies = [ "markup5ever_rcdom", "mime", "rand 0.8.5", - "regex", "reqwest", "resvg", "rpassword", @@ -2089,35 +2079,6 @@ dependencies = [ "bitflags 2.9.0", ] -[[package]] -name = "regex" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" - [[package]] name = "rend" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index beaf8e1..706f51b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,42 +8,53 @@ repository = "https://github.com/QuartzLibrary/glowpub" readme = "README.md" edition = "2024" +[features] +default = ["binary"] +binary = ["epub", "auth", "dep:clap", "dep:simple_logger", "dep:slug"] +auth = ["api", "dep:rpassword", "dep:log"] +epub = ["gen", "api", "dep:epub-builder", "dep:uuid"] +api = ["types", "utils", "dep:serde_json", "dep:tokio", "dep:glob", "dep:log", "dep:rand"] +gen = ["types", "utils", "dep:fontdb", "dep:resvg", "dep:textwrap", "dep:tiny-skia", "dep:usvg", "dep:ammonia", "dep:cssparser", "dep:html-escape", "dep:html5ever", "dep:lightningcss", "dep:lol_html", "dep:markup5ever", "dep:markup5ever_rcdom", "dep:xml5ever", "dep:log", "dep:rand"] +types = ["dep:chrono", "dep:serde"] +utils = ["dep:sha2", "dep:image", "dep:mime", "dep:reqwest"] + [dependencies] -chrono = { version = "0.4", features = ["serde"] } -glob = "0.3" -log = "0.4" -mime = "0.3" -rand = "0.8" -regex = "1" -sha2 = "0.10" -uuid = { version = "1", features = ["v4"] } - -reqwest = { version = "0.12", features = ["json"] } -serde = { version = "1", features = ["derive"] } -serde_json = "1" -tokio = { version = "1", features = ["full"] } - -fontdb = "0.16" -resvg = "0.41" -textwrap = "0.16" -tiny-skia = "0.11" -usvg = "0.41" - -epub-builder = { version = "0.7", default-features = false, features = ["libzip"] } - -ammonia = "4" -cssparser = "0.33" -html-escape = "0.2" -html5ever = "0.27" -lightningcss = "1.0.0-alpha.55" -lol_html = "1" -markup5ever = "0.12" -markup5ever_rcdom = "0.3" -xml5ever = "0.18" - -image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] } - -clap = { version = "4", features = ["derive"] } -simple_logger = "4" -slug = "0.1" -rpassword = "7.3.1" +log = { version = "0.4", optional = true } +rand = { version = "0.8", optional = true } + +chrono = { version = "0.4", features = ["serde"], optional = true } +serde = { version = "1", features = ["derive"], optional = true } + +mime = { version = "0.3", optional = true } +sha2 = { version = "0.10", optional = true } +reqwest = { version = "0.12", features = ["json"], optional = true } +image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"], optional = true } + +serde_json = { version ="1", optional = true } +tokio = { version = "1", features = ["full"], optional = true } +glob = { version = "0.3", optional = true } + +fontdb = { version = "0.16", optional = true } +resvg = { version = "0.41", optional = true } +textwrap = { version = "0.16", optional = true } +tiny-skia = { version = "0.11", optional = true } +usvg = { version = "0.41", optional = true } + +ammonia = { version = "4", optional = true } +cssparser = { version = "0.33", optional = true } +html-escape = { version = "0.2", optional = true } +html5ever = { version = "0.27", optional = true } +lightningcss = { version = "1.0.0-alpha.55", optional = true } +lol_html = { version = "1", optional = true } +markup5ever = { version = "0.12", optional = true } +markup5ever_rcdom = { version = "0.3", optional = true } +xml5ever = { version = "0.18", optional = true } + +epub-builder = { version = "0.7", default-features = false, features = ["libzip"], optional = true } +uuid = { version = "1", features = ["v4"], optional = true } + +rpassword = { version = "7.3.1", optional = true } + +clap = { version = "4", features = ["derive"], optional = true } +simple_logger = { version = "4", optional = true } +slug = { version = "0.1", optional = true } diff --git a/src/cached.rs b/src/cached.rs index 1736171..6df5d46 100644 --- a/src/cached.rs +++ b/src/cached.rs @@ -162,6 +162,7 @@ impl Thread { Ok(Ok(Self { post, replies })) } + #[cfg(feature = "gen")] pub async fn cache_all_icons(&self, invalidate_cache: bool) { let icons: BTreeSet<_> = self.icons().collect(); @@ -205,6 +206,8 @@ impl Continuity { Ok(Ok(Self { board, threads })) } + + #[cfg(feature = "gen")] pub async fn cache_all_icons(&self, invalidate_cache: bool) { let icons: BTreeSet<_> = self.threads.iter().flat_map(|t| t.icons()).collect(); for icon in icons { diff --git a/src/generate/mod.rs b/src/generate/mod.rs index 09b615b..adbb372 100644 --- a/src/generate/mod.rs +++ b/src/generate/mod.rs @@ -1,5 +1,6 @@ mod cover; +#[cfg(feature = "epub")] pub mod epub; pub mod html; pub mod transform; diff --git a/src/lib.rs b/src/lib.rs index 4454ec6..2165376 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,21 @@ +#[cfg(any(feature = "api", feature = "types"))] mod rfc3339; +#[cfg(feature = "auth")] mod auth; +#[cfg(feature = "api")] pub mod api; +#[cfg(feature = "api")] pub mod cached; +#[cfg(feature = "gen")] pub mod generate; +#[cfg(all(feature = "gen", feature = "api"))] pub mod intern_images; +#[cfg(feature = "types")] pub mod types; +#[cfg(feature = "utils")] pub mod utils; +#[cfg(feature = "types")] pub use types::{Board, Post, Reply, Thread}; diff --git a/src/types.rs b/src/types.rs index 5376f88..f54e7d2 100644 --- a/src/types.rs +++ b/src/types.rs @@ -109,6 +109,7 @@ mod helpers { iter, }; + #[cfg(feature = "gen")] use crate::generate::transform; use super::*; @@ -156,6 +157,7 @@ mod helpers { (sections, sectionless_threads) } } + #[cfg(feature = "gen")] impl Thread { pub fn image_urls(&self) -> HashSet { let contents = iter::once(&self.post.content) diff --git a/src/utils.rs b/src/utils.rs index 2571d2a..1dd3633 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,10 +4,12 @@ use image::ImageReader; use mime::Mime; use sha2::{Digest, Sha256}; +#[cfg(feature = "types")] use crate::types::{Icon, Thread}; const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),); +#[cfg(feature = "types")] impl Thread { pub fn icons(&self) -> impl Iterator { std::iter::once(self.post.icon.as_ref()) From e1086c73f229f658f6ad904fda68abe3e55d60f8 Mon Sep 17 00:00:00 2001 From: "Ms. Haze" Date: Sun, 21 Sep 2025 13:33:46 -0400 Subject: [PATCH 2/3] simplified features --- Cargo.toml | 30 ++++++++++++------------------ src/lib.rs | 6 +----- src/utils.rs | 2 -- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 706f51b..33d9ea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,29 +10,25 @@ edition = "2024" [features] default = ["binary"] -binary = ["epub", "auth", "dep:clap", "dep:simple_logger", "dep:slug"] -auth = ["api", "dep:rpassword", "dep:log"] +binary = ["epub", "dep:clap", "dep:simple_logger", "dep:slug"] epub = ["gen", "api", "dep:epub-builder", "dep:uuid"] -api = ["types", "utils", "dep:serde_json", "dep:tokio", "dep:glob", "dep:log", "dep:rand"] -gen = ["types", "utils", "dep:fontdb", "dep:resvg", "dep:textwrap", "dep:tiny-skia", "dep:usvg", "dep:ammonia", "dep:cssparser", "dep:html-escape", "dep:html5ever", "dep:lightningcss", "dep:lol_html", "dep:markup5ever", "dep:markup5ever_rcdom", "dep:xml5ever", "dep:log", "dep:rand"] -types = ["dep:chrono", "dep:serde"] -utils = ["dep:sha2", "dep:image", "dep:mime", "dep:reqwest"] +api = ["dep:serde_json", "dep:tokio", "dep:glob", "dep:rpassword"] +gen = ["dep:fontdb", "dep:resvg", "dep:textwrap", "dep:tiny-skia", "dep:usvg", "dep:ammonia", "dep:cssparser", "dep:html-escape", "dep:html5ever", "dep:lightningcss", "dep:lol_html", "dep:markup5ever", "dep:markup5ever_rcdom", "dep:xml5ever"] [dependencies] -log = { version = "0.4", optional = true } -rand = { version = "0.8", optional = true } - -chrono = { version = "0.4", features = ["serde"], optional = true } -serde = { version = "1", features = ["derive"], optional = true } - -mime = { version = "0.3", optional = true } -sha2 = { version = "0.10", optional = true } -reqwest = { version = "0.12", features = ["json"], optional = true } -image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"], optional = true } +log = "0.4" +rand = "0.8" +chrono = { version = "0.4", features = ["serde"] } +serde = { version = "1", features = ["derive"] } +mime = "0.3" +sha2 = "0.10" +reqwest = { version = "0.12", features = ["json"] } +image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] } serde_json = { version ="1", optional = true } tokio = { version = "1", features = ["full"], optional = true } glob = { version = "0.3", optional = true } +rpassword = { version = "7.3.1", optional = true } fontdb = { version = "0.16", optional = true } resvg = { version = "0.41", optional = true } @@ -53,8 +49,6 @@ xml5ever = { version = "0.18", optional = true } epub-builder = { version = "0.7", default-features = false, features = ["libzip"], optional = true } uuid = { version = "1", features = ["v4"], optional = true } -rpassword = { version = "7.3.1", optional = true } - clap = { version = "4", features = ["derive"], optional = true } simple_logger = { version = "4", optional = true } slug = { version = "0.1", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 2165376..1935c48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ -#[cfg(any(feature = "api", feature = "types"))] mod rfc3339; -#[cfg(feature = "auth")] +#[cfg(feature = "api")] mod auth; #[cfg(feature = "api")] @@ -12,10 +11,7 @@ pub mod cached; pub mod generate; #[cfg(all(feature = "gen", feature = "api"))] pub mod intern_images; -#[cfg(feature = "types")] pub mod types; -#[cfg(feature = "utils")] pub mod utils; -#[cfg(feature = "types")] pub use types::{Board, Post, Reply, Thread}; diff --git a/src/utils.rs b/src/utils.rs index 1dd3633..2571d2a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,12 +4,10 @@ use image::ImageReader; use mime::Mime; use sha2::{Digest, Sha256}; -#[cfg(feature = "types")] use crate::types::{Icon, Thread}; const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),); -#[cfg(feature = "types")] impl Thread { pub fn icons(&self) -> impl Iterator { std::iter::once(self.post.icon.as_ref()) From 86c71633324a4d5d08c8d898b0f387f70da9b8bf Mon Sep 17 00:00:00 2001 From: "Ms. Haze" Date: Sun, 21 Sep 2025 13:34:09 -0400 Subject: [PATCH 3/3] fixed clippy warnings with non-default features --- src/cached.rs | 4 +++- src/generate/mod.rs | 2 +- src/types.rs | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cached.rs b/src/cached.rs index 6df5d46..13f49cb 100644 --- a/src/cached.rs +++ b/src/cached.rs @@ -1,5 +1,4 @@ use std::{ - collections::BTreeSet, error::Error, path::{Path, PathBuf}, str::FromStr, @@ -18,6 +17,9 @@ use crate::{ }, }; +#[cfg(feature = "gen")] +use std::collections::BTreeSet; + const CACHE_ROOT: &str = "./cache"; impl Board { diff --git a/src/generate/mod.rs b/src/generate/mod.rs index adbb372..d3c8769 100644 --- a/src/generate/mod.rs +++ b/src/generate/mod.rs @@ -1,4 +1,4 @@ -mod cover; +pub mod cover; #[cfg(feature = "epub")] pub mod epub; diff --git a/src/types.rs b/src/types.rs index f54e7d2..e3b25bd 100644 --- a/src/types.rs +++ b/src/types.rs @@ -104,16 +104,16 @@ pub struct Reply { } mod helpers { - use std::{ - collections::{BTreeSet, HashSet}, - iter, - }; - - #[cfg(feature = "gen")] - use crate::generate::transform; + use std::collections::BTreeSet; use super::*; + #[cfg(feature = "gen")] + use { + crate::generate::transform, + std::{collections::HashSet, iter}, + }; + // TODO: can we rely on there always being at least one thread? impl Continuity { pub fn created_at(&self) -> Option> {