diff options
Diffstat (limited to 'src/layout.rs')
-rw-r--r-- | src/layout.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/layout.rs b/src/layout.rs index 421f50e..efab6b8 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -7,11 +7,12 @@ Copyright (C) 2023 metamuffin <metamuffin.org> use crate::blog::rocket_uri_macro_r_blog; use crate::pages::{ rocket_uri_macro_r_about, rocket_uri_macro_r_contact, rocket_uri_macro_r_pgp_key, - rocket_uri_macro_r_projects, + rocket_uri_macro_r_projects, rocket_uri_macro_r_toggle_css, }; use crate::source::rocket_uri_macro_r_source; use crate::uri; use markup::Render; +use rocket::http::CookieJar; use rocket::{ http::ContentType, response::{self, Responder}, @@ -20,11 +21,17 @@ use rocket::{ use std::io::Cursor; markup::define! { - ScaffoldImpl<Main: Render>(title: String, main: Main, noimg: bool) { + ScaffoldImpl<Main: Render>( + title: String, + main: Main, + noimg: bool, + include_css: bool + ) { @markup::doctype() html { head { title { @title " - " "metamuffin's website" } + @if *include_css { link[rel="stylesheet", href="/style.css"]; } } body { @if !noimg { img[src="https://s.metamuffin.org/avatar/default-512.webp", align="left", height=80, hspace=10]; } @@ -38,7 +45,7 @@ markup::define! { a[href=uri!(r_pgp_key())] { "PGP-Key" } " " } hr; - section { @main } + article { @main } hr; footer { p { @@ -46,6 +53,10 @@ markup::define! { "sources available on " a[href=uri!(r_source())] { "this page itself" } " and on " a[href="https://codeberg.org/metamuffin/website"] { "codeberg" } } + p { "In case you " i {"really"} " want to, you can enable stylesheets." } + form[action=uri!(r_toggle_css()), method="POST"] { + input[type="submit", value="Toggle CSS (uses a cookie)"]; + } } } } @@ -60,12 +71,14 @@ pub struct Scaffold<T> { } impl<'r, Main: Render> Responder<'r, 'static> for Scaffold<Main> { - fn respond_to(self, _req: &'r Request<'_>) -> response::Result<'static> { + fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> { + let jar = async_std::task::block_on(req.guard::<&CookieJar>()).unwrap(); let mut out = String::new(); ScaffoldImpl { main: self.content, noimg: self.title == "Source", title: self.title, + include_css: jar.get("css").map(|v| v.value() == "yes").unwrap_or(false), } .render(&mut out) .unwrap(); |