Use maud for test page

I want to replace askama with maud completely. It's so much nicer to be
able to use Rust code and abstractions (e.g. functions) to compose HTML
than using a bespoke templating system with weird inheritance and stuff.
Even though said template system is checked at compile time. Actually,
since it doesn't do hot reloading anyways, maud requiring a recompile
for changes to become visible doesn't make the situation worse.
This commit is contained in:
Joscha 2024-05-11 22:14:46 +02:00
parent 36ce75b43d
commit cf590046e9
7 changed files with 112 additions and 0 deletions

View file

@ -31,6 +31,7 @@ use self::{
index::get_index,
queue::{get_queue, get_queue_delete, get_queue_inner},
run::get_run_by_id,
test::get_test,
worker::get_worker_by_name,
},
};
@ -57,6 +58,7 @@ pub async fn run(server: Server) -> somehow::Result<()> {
.typed_get(get_queue_delete)
.typed_get(get_queue_inner)
.typed_get(get_run_by_id)
.typed_get(get_test)
.typed_get(get_worker_by_name)
.typed_post(post_admin_queue_add)
.typed_post(post_admin_queue_add_batch)

View file

@ -1,5 +1,7 @@
use std::fmt;
use maud::{html, Markup, DOCTYPE};
use crate::config::ServerConfig;
use super::{
@ -60,6 +62,33 @@ impl Base {
pub fn link<P: fmt::Display>(&self, to: P) -> Link {
Self::link_with_base(&self.web_base, to)
}
pub fn html(&self, title: &str, head: Markup, body: Markup) -> Markup {
html!(
(DOCTYPE)
html lang="en" {
head {
meta charset="utf-8";
meta name="viewport" content="width=device-width";
title { (title) " - " (self.repo_name) }
link rel="icon" href=(self.link_logo_svg);
link rel="stylesheet" href=(self.link_base_css);
(head)
}
body {
nav {
a .current[self.tab == "index"] href=(self.link_index) {
img src=(self.link_logo_svg) alt="";
(self.repo_name)
}
a .current[self.tab == "graph"] href=(self.link_graph) { "graph" }
a .current[self.tab == "queue"] href=(self.link_queue) { "queue" }
}
(body)
}
}
)
}
}
#[derive(Clone)]

View file

@ -3,6 +3,7 @@ pub mod graph;
pub mod index;
pub mod queue;
pub mod run;
pub mod test;
pub mod worker;
// TODO Admin page with vacuum+analyze, deleting output?

View file

@ -0,0 +1,27 @@
use axum::{extract::State, response::IntoResponse};
use maud::html;
use crate::{
config::ServerConfig,
server::web::{
base::{Base, Tab},
paths::PathTest,
},
somehow,
};
pub async fn get_test(
_path: PathTest,
State(config): State<&'static ServerConfig>,
) -> somehow::Result<impl IntoResponse> {
let base = Base::new(config, Tab::Index);
Ok(base.html(
"test",
html! {},
html! {
h2 { "Test" }
p { "Hello world!" }
},
))
}

View file

@ -57,6 +57,10 @@ pub struct PathWorkerByName {
pub name: String,
}
#[derive(Deserialize, TypedPath)]
#[typed_path("/test")]
pub struct PathTest {}
///////////////////
// Admin actions //
///////////////////