/* This file is part of metamuffins website (https://codeberg.org/metamuffin/website) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin */ use crate::pages::*; use crate::uri; use crate::animation::*; use markup::Render; use rocket::{ http::ContentType, response::{self, Responder}, Request, Response, }; use std::io::Cursor; markup::define! { Layout(title: String, main: Main) { @markup::doctype() html { head { title { @title " - " "metamuffin's website" } } body { img[src="https://s.metamuffin.org/avatar/default-512.webp", align="left", height=80, hspace=10]; h1 { "metamuffin's personal website" } nav { a[href=uri!(r_about())] { "About" } " " a[href=uri!(r_projects())] { "Projects" } " " a[href=uri!(r_contact())] { "Contact" } " " a[href="https://codeberg.org/metamuffin"] { "Codeberg" } " " a[href=uri!(r_pgp_key())] { "PGP-Key" } " " a[href=uri!(r_wubbel())] { i {"wubbel"} } " " } hr; section { @main } hr; footer { p { "metamuffin's website; version " @include_str!("../.git/refs/heads/main")[0..10] "; " "sources available on " a[href="https://codeberg.org/metamuffin/website"] { "codeberg" } } } } } } } pub type DynLayoutPage<'a> = LayoutPage>; pub struct LayoutPage { pub title: String, pub content: T, } impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage
{ fn respond_to(self, _req: &'r Request<'_>) -> response::Result<'static> { let mut out = String::new(); Layout { main: self.content, title: self.title, } .render(&mut out) .unwrap(); Response::build() .header(ContentType::HTML) .streamed_body(Cursor::new(out)) .ok() } }