replaced askama with tera, reworked the whole website and added nixos module

This commit is contained in:
2026-03-26 13:24:13 +01:00
parent 0670589b5e
commit 81686d6fb8
12 changed files with 888 additions and 621 deletions

View File

@@ -1,26 +1,55 @@
use clap::Parser;
use axum::{Router, routing::get};
use lazy_static::lazy_static;
use std::sync::Arc;
use tera::Tera;
use mycoolwebsite::run_server;
mod handlers;
use handlers::{home_handler, showcase_handler};
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[arg(short, long)]
verbose: bool,
lazy_static! {
pub static ref TEMPLATES: Tera = {
let mut tera = Tera::default();
tera.add_raw_templates(vec![
("_layout.html", include_str!("../templates/_layout.html")),
("_base.css", include_str!("../templates/_base.css")),
("index.html", include_str!("../templates/homepage.html")),
("showcase.html", include_str!("../templates/showcase.html")),
])
.unwrap();
tera
};
}
struct AppState {
app_name: String,
}
/// Cli handler
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.init();
let subscriber = tracing_subscriber::FmtSubscriber::new();
tracing::subscriber::set_global_default(subscriber).ok();
let shared_state = Arc::new(AppState {
app_name: "Quick rust website template".to_string(),
});
let port = std::env::var("SERVER_PORT").unwrap_or("8081".to_string());
let addr = format!("127.0.0.1:{port}");
let app = Router::new()
.route("/", get(home_handler))
.route("/showcase", get(showcase_handler))
.with_state(shared_state);
run_server(&addr, cli.verbose).await?;
let host = false;
let port = "8000";
let addr = if host {
format!("0.0.0.0:{}", port)
} else {
format!("127.0.0.1:{}", port)
};
let listener = tokio::net::TcpListener::bind(&addr).await?;
tracing::info!("Listening on http://{}", addr);
axum::serve(listener, app).await?;
Ok(())
}