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

@ -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)]