diff --git a/src/args.rs b/src/args.rs index 4eeb9a2..e5d4f45 100644 --- a/src/args.rs +++ b/src/args.rs @@ -31,8 +31,8 @@ pub struct Args { pub editable: bool, /// The text displayed in the browser navigation bar. - #[clap(long, env = "MICROBIN_TITLE")] - pub title: Option, + #[clap(long, env = "MICROBIN_TITLE", default_value = " MicroBin")] + pub title: String, /// The web interfaces' footer text. #[clap(long, env = "MICROBIN_FOOTER_TEXT")] diff --git a/src/main.rs b/src/main.rs index fd4f412..b7da678 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,18 +7,21 @@ use crate::endpoints::{ use crate::pasta::Pasta; use crate::util::dbio; use actix_web::middleware::Condition; -use actix_web::{middleware, web, App, HttpServer}; +use actix_web::{middleware, web, App, HttpServer, HttpResponse, get}; use actix_web_httpauth::middleware::HttpAuthentication; use chrono::Local; use env_logger::Builder; use futures::lock::Mutex; use log::LevelFilter; +use templates::BasePage; use std::fs; use std::io::Write; pub mod args; pub mod pasta; +pub mod templates; + pub mod util { pub mod pasta_id_converter; pub mod auth; @@ -108,6 +111,7 @@ async fn main() -> std::io::Result<()> { .wrap(middleware::Logger::default()) .service(remove::remove) .service(pastalist::list) + .service(testtemplate) .wrap(Condition::new( ARGS.auth_username.is_some(), HttpAuthentication::basic(util::auth::auth_validator), @@ -118,3 +122,14 @@ async fn main() -> std::io::Result<()> { .run() .await } + +#[get("/testtemplate")] +async fn testtemplate() -> HttpResponse { + HttpResponse::Ok() + .content_type("text/html") + .body(BasePage { + body: markup::new! { + p "Test content!" + } + }.to_string()) +} diff --git a/src/templates/mod.rs b/src/templates/mod.rs new file mode 100644 index 0000000..04e21fa --- /dev/null +++ b/src/templates/mod.rs @@ -0,0 +1,80 @@ +use crate::args::ARGS; + +markup::define!{ + Create() { + @BasePage { + body: markup::new! { + form [ + id = "pasta-form", + action = "upload", + method = "POST", + enctype = "multipart/form-data", + ] { + br; + } + } + } + } + BasePage( body: Body ) { + @markup::doctype() + html { + head { + title { @ARGS.title } + meta[charset = "utf-8"]; + meta[ + name = "viewport", + content = "width=device-width, initial-scale=1.0" + ]; + link[ + rel = "stylesheet", + href = if let Some(custom_css_url) = ARGS.custom_css.as_ref() { + custom_css_url.clone() + } else { + format!("{}/static/water.css", ARGS.public_path) + } + ]; + } + body[ + style = format!( + "margin:auto;padding-left: 0.5rem;padding-right: 0.5rem;line-height:1.5;font-size: 1.1em;{}", + if ARGS.wide { "1080px" } else { "800px" } + ) + ] { + br; + b[ style = "margin-right: 0.5rem" ] { + @if !ARGS.hide_logo { + a[ href = format!("{}/", ARGS.public_path) ] { + img[ + width = 26, + style = "margin-bottom: -6px; margin-right: 0.5rem;", + src = format!("{}/static/logo.png", ARGS.public_path) + ]; + } + @ARGS.title + } + } + a[ href = format!("{}/", ARGS.public_path), style = "margin-right: 0.5rem; margin-left: 0.5rem" ] "New" + a[ href = format!("{}/pastalist", ARGS.public_path), style = "margin-right: 0.5rem; margin-left: 0.5rem" ] "List" + a[ href = format!("{}/info", ARGS.public_path), style = "margin-right: 0.5rem; margin-left: 0.5rem" ] "Info" + hr; + + @body + + hr; + // TODO: footer text but like with proper markdown and customizability + p[ style = "font-size:smaller" ] { + @if let Some(footer_text) = ARGS.footer_text.as_ref() { + @footer_text + } else { + a[ href = "https://microbin.eu" ] "MicroBin" + " by Dániel Szabó and the FOSS Community." + "Let's keep the Web " + b "compact" ", " + b "accessible" " and " + b "humane" "!" + } + } + } + } + } +} diff --git a/templates/footer.html b/templates/footer.html index ae7f14e..de2895d 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -14,4 +14,5 @@ - \ No newline at end of file + + diff --git a/templates/header.html b/templates/header.html index dc003d7..b7895b6 100644 --- a/templates/header.html +++ b/templates/header.html @@ -2,11 +2,7 @@ - {% if args.title.as_ref().is_none() %} - MicroBin - {%- else %} - {{ args.title.as_ref().unwrap() }} - {%- endif %} + MicroBin @@ -55,8 +51,8 @@ src="{{ args.public_path }}/static/logo.png" > - {%- endif %} {% if args.title.as_ref().is_none() %} - MicroBin {%- else %} {{ args.title.as_ref().unwrap() }} {%- endif %} + {%- endif %} + MicroBin New