From 64806dd32ece4f19b9419e556661be6ee7bcf928 Mon Sep 17 00:00:00 2001 From: Mukan Erkin Date: Sun, 19 Apr 2026 20:26:15 +0300 Subject: [PATCH] feat(mse): minijinja template engine, shared header partial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tmpl.rs: OnceLock ile build-time compile edilmiş minijinja env - _header.html: ortak header partial — logo, nav (active_page değişkeni), mode-toggle, çıkış - index.html, bots.html, positions.html: hardcoded header → {% include "_header.html" %} - bots.html: + Yeni Bot butonu header'dan page-toolbar'a taşındı Co-Authored-By: Claude Sonnet 4.6 --- src/api/routes.rs | 6 +++--- src/main.rs | 1 + src/tmpl.rs | 24 ++++++++++++++++++++++++ src/web/_header.html | 15 +++++++++++++++ src/web/bots.html | 24 ++++++++---------------- src/web/index.html | 17 ++--------------- src/web/positions.html | 17 ++--------------- 7 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 src/tmpl.rs create mode 100644 src/web/_header.html diff --git a/src/api/routes.rs b/src/api/routes.rs index 02d943f..9a64a3e 100644 --- a/src/api/routes.rs +++ b/src/api/routes.rs @@ -70,7 +70,7 @@ async fn bots_handler( Some(t) => { let db = state.db.lock().await; db.session_exists(&t).unwrap_or(false) } None => false, }; - if authed { axum::response::Html(include_str!("../web/bots.html")).into_response() } + if authed { axum::response::Html(crate::tmpl::render("bots.html", "bots")).into_response() } else { Redirect::to("/").into_response() } } @@ -83,7 +83,7 @@ async fn positions_handler( Some(t) => { let db = state.db.lock().await; db.session_exists(&t).unwrap_or(false) } None => false, }; - if authed { axum::response::Html(include_str!("../web/positions.html")).into_response() } + if authed { axum::response::Html(crate::tmpl::render("positions.html", "positions")).into_response() } else { Redirect::to("/").into_response() } } @@ -116,7 +116,7 @@ async fn dashboard_handler( None => false, }; if authed { - axum::response::Html(include_str!("../web/index.html")).into_response() + axum::response::Html(crate::tmpl::render("index.html", "dashboard")).into_response() } else { Redirect::to("/").into_response() } diff --git a/src/main.rs b/src/main.rs index 4f0b4f3..a0bf927 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod binance; mod bot; mod config; mod storage; +mod tmpl; use std::path::Path; use std::sync::Arc; diff --git a/src/tmpl.rs b/src/tmpl.rs new file mode 100644 index 0000000..036c0eb --- /dev/null +++ b/src/tmpl.rs @@ -0,0 +1,24 @@ +use std::sync::OnceLock; +use minijinja::{Environment, context}; + +static ENV: OnceLock> = OnceLock::new(); + +fn env() -> &'static Environment<'static> { + ENV.get_or_init(|| { + let mut e = Environment::new(); + e.add_template_owned("_header.html", include_str!("web/_header.html").to_string()).unwrap(); + e.add_template_owned("index.html", include_str!("web/index.html").to_string()).unwrap(); + e.add_template_owned("bots.html", include_str!("web/bots.html").to_string()).unwrap(); + e.add_template_owned("bot.html", include_str!("web/bot.html").to_string()).unwrap(); + e.add_template_owned("positions.html", include_str!("web/positions.html").to_string()).unwrap(); + e + }) +} + +pub fn render(template: &str, active_page: &str) -> String { + env() + .get_template(template) + .unwrap() + .render(context! { active_page => active_page }) + .unwrap() +} diff --git a/src/web/_header.html b/src/web/_header.html new file mode 100644 index 0000000..3434817 --- /dev/null +++ b/src/web/_header.html @@ -0,0 +1,15 @@ +
+ +
+ +
+
+ + +
+ +
diff --git a/src/web/bots.html b/src/web/bots.html index ef939f6..2f56d6f 100644 --- a/src/web/bots.html +++ b/src/web/bots.html @@ -46,6 +46,8 @@ /* ── MAIN ── */ main { padding: 24px; max-width: 1400px; margin: 0 auto; } + .page-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; } + .page-title { font-size: 16px; font-weight: 600; } /* ── GROUP HEADER ── */ .group-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; } @@ -116,24 +118,14 @@ -
- -
- -
-
- - -
- - -
+{% include "_header.html" %} +
+
+ Botlar + +
Çalışıyor 0
Çalışan bot yok
diff --git a/src/web/index.html b/src/web/index.html index c43d2ef..2deca7a 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -144,21 +144,8 @@
-
- -
- -
-
- - -
- -
+{% include "_header.html" %} +
diff --git a/src/web/positions.html b/src/web/positions.html index 8cd555a..2a79e51 100644 --- a/src/web/positions.html +++ b/src/web/positions.html @@ -45,21 +45,8 @@ -
- -
- -
-
- - -
- -
+{% include "_header.html" %} +