From 054968ca5d7f304a289f089959e72bffc8493f32 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 6 Aug 2025 12:57:37 +0300 Subject: [PATCH] move css to separated cachable file, update config api --- src/config.rs | 34 ++++--- src/main.rs | 10 +- static/theme/default.css | 147 ++++++++++++++++++++++++++++ templates/layout/default.html.tera | 151 +---------------------------- 4 files changed, 173 insertions(+), 169 deletions(-) create mode 100644 static/theme/default.css diff --git a/src/config.rs b/src/config.rs index a074543..df18b89 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,17 +8,9 @@ use url::Url; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct Config { - /// Path to the [aquatic-crawler](https://github.com/yggverse/aquatic-crawler) file storage - #[arg(long, short)] - pub storage: PathBuf, - - /// Default listing limit - #[arg(long, default_value_t = 50)] - pub list_limit: usize, - - /// Default capacity (estimated torrents in `storage`) - #[arg(long, default_value_t = 1000)] - pub capacity: usize, + /// Path to the [aquatic-crawler](https://github.com/yggverse/aquatic-crawler) preload files + #[arg(long)] + pub preload: PathBuf, /// Server name #[arg(long, default_value_t = String::from("βtracker"))] @@ -30,7 +22,7 @@ pub struct Config { /// Canonical URL #[arg(long)] - pub link: Option, + pub canonical_url: Option, /// Display following tracker(s) in the header, append also to the magnet links #[arg(long)] @@ -39,12 +31,24 @@ pub struct Config { /// Format timestamps (on the web view) /// /// * tip: escape with `%%d/%%m/%%Y %%H:%%M` in the CLI/bash argument - #[arg(long, short, default_value_t = String::from("%d/%m/%Y %H:%M"))] + #[arg(long, default_value_t = String::from("%d/%m/%Y %H:%M"))] pub format_time: String, + /// Path to the framework assets + #[arg(long, default_value_t = String::from("./static"))] + pub statics: String, + + /// Default listing limit + #[arg(long, default_value_t = 20)] + pub list_limit: usize, + + /// Default capacity (estimated torrents in `storage`) + #[arg(long, default_value_t = 1000)] + pub capacity: usize, + /// Bind server on given host - #[arg(long, short, default_value_t = IpAddr::V4(Ipv4Addr::LOCALHOST))] - pub address: IpAddr, + #[arg(long, default_value_t = IpAddr::V4(Ipv4Addr::LOCALHOST))] + pub host: IpAddr, /// Bind server on given port #[arg(long, short, default_value_t = 8000)] diff --git a/src/main.rs b/src/main.rs index e9f4341..948a955 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,29 +106,31 @@ fn rss(feed: &State, storage: &State) -> Result, C #[launch] fn rocket() -> _ { use clap::Parser; + use rocket::fs::FileServer; let config = Config::parse(); let feed = Feed::init( config.title.clone(), config.description.clone(), - config.link.clone(), + config.canonical_url.clone(), config.tracker.clone(), ); - let storage = Storage::init(config.storage, config.list_limit, config.capacity).unwrap(); // @TODO handle + let storage = Storage::init(config.preload, config.list_limit, config.capacity).unwrap(); // @TODO handle rocket::build() .attach(Template::fairing()) .configure(rocket::Config { port: config.port, - address: config.address, + address: config.host, ..rocket::Config::debug_default() }) .manage(feed) .manage(storage) .manage(Meta { - canonical: config.link, + canonical: config.canonical_url, description: config.description, format_time: config.format_time, title: config.title, trackers: config.tracker, }) + .mount("/", FileServer::from(config.statics)) .mount("/", routes![index, rss]) } diff --git a/static/theme/default.css b/static/theme/default.css new file mode 100644 index 0000000..fc3c709 --- /dev/null +++ b/static/theme/default.css @@ -0,0 +1,147 @@ +* { + border: 0; + margin: 0; + padding: 0; + box-sizing: border-box; + outline: none; +} +:focus, +:focus-within, +:focus-visible, +:active, +:target, +:hover { + opacity: 1; + transition: opacity .2s ease-in-out; +} + +body { + background: #282b3c; + color: #ccc; + font-family: Sans-serif; + font-size: 13px; +} + +a, +a:visited, +a:active { + color: #96d9a1; + text-decoration: none; + opacity: .9; +} + +h1, h2, h3, h4, h5 { + display: inline-block; + font-weight: normal; +} + +h1 { + font-size: 16px; +} + +h2 { + color: #ccc; + font-size: 14px; +} + +body > * { + position: relative; + overflow: hidden; + max-width: 748px; +} + +header, footer { + text-align: center; + margin: 16px auto; +} + +header > a, +header > a:active, +header > a:hover, +header > a:visited { + color: #ccc; + font-size: 20px; +} + +header::first-letter { + color: #96d9a1; +} + +header > div { + margin-top: 16px; +} + +header > div > code:not(:last-child)::after { + content: "|"; + margin: 0 6px; +} + +main { + margin: 0 auto; +} + +/* pagination */ +main > a { + background: #34384f; + border-radius: 3px; + float: right; + margin-left: 8px; + opacity: .96; + padding: 8px; +} + +/* item row */ +main > div { + background-color: #34384f; + border-radius: 3px; + margin: 8px 0; + padding: 24px; +} + +/* item row description */ +main > div > p { + margin: 8px 0; +} + +/* item row meta, controls */ +main > div > div { + border-top: 1px #4f536a solid; + margin-top: 16px; + overflow: hidden; + padding-top: 16px; +} + +main > div > div > ul { + list-style: none; +} + +main > div > div > ul > li { + cursor: default; + float: left; +} + +main > div > div > ul > li > span { + color: white; + font-size: smaller; + opacity: 0.7; +} + +main > div > div > ul > li > span:hover { + opacity: 1; +} + +main > div > div > ul > li:not(:last-child)::after { + content: "•"; + margin: 0 6px; +} + +main > div > div > a > svg { + float: right; + vertical-align: middle; +} + +/* pagination info */ +main > span { + float: right; + padding: 8px; +} \ No newline at end of file diff --git a/templates/layout/default.html.tera b/templates/layout/default.html.tera index c58562e..e24373e 100644 --- a/templates/layout/default.html.tera +++ b/templates/layout/default.html.tera @@ -6,156 +6,7 @@ {% if meta.description %} {% endif %} - +