diff options
author | metamuffin <metamuffin@disroot.org> | 2023-02-13 22:10:45 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-02-13 22:10:45 +0100 |
commit | 4298b09bdbf2650130c03b753a6738911e1d45ef (patch) | |
tree | 326473c2cdb7f9399d6025ccb6e63b05d387e0a0 | |
parent | 143ff63acd01300b23178a2a4c08ece78cc83bd2 (diff) | |
download | metamuffin-website-4298b09bdbf2650130c03b753a6738911e1d45ef.tar metamuffin-website-4298b09bdbf2650130c03b753a6738911e1d45ef.tar.bz2 metamuffin-website-4298b09bdbf2650130c03b753a6738911e1d45ef.tar.zst |
optional css
-rw-r--r-- | assets/style.css | 61 | ||||
-rw-r--r-- | src/layout.rs | 21 | ||||
-rw-r--r-- | src/main.rs | 6 | ||||
-rw-r--r-- | src/pages.rs | 24 |
4 files changed, 105 insertions, 7 deletions
diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..9646d87 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,61 @@ +@import url("https://s.metamuffin.org/static/font-ubuntu/include.css"); + +:root { + --bg1: #090909; + --bg2: #141414; +} + +img[align=left] { + border-radius: 1em; + width: 7em; + height: 7em; + display: block; +} + +body { + margin: 3em; + background-color: var(--bg1); +} + +nav { + margin: 1em 1em 1em 9em; + background-color: var(--bg2); + padding: 1em; + border: 0px solid transparent; + border-radius: 1em; +} + +h1 {font-size: xx-large } +h2 {font-size: x-large } +h3 {font-size: large } +h4 {font-size: medium } + +p,h1,h2,h3,h4,h5,h6,li { font-family: "Ubuntu", sans-serif; } +h1,h2 { color: #b575ff } +h3 { color: #ff83fd; margin-left: 1em } +h4 { color: #ff82b2; margin-left: 2em } +p,li { color: white; margin-left: 3em } +a { color: #82a8ff; font-style: italic; text-decoration: underline } +hr { border: 1px solid grey } + +math {color:white} + +pre,code { + color: #eeeeee; + font-family: monospace; + background-color: black; + border: 0px solid transparent; + border-radius: 5px; + padding: 0.2em; +} +pre { margin-left: 4em; margin-right: 4em; overflow-y: auto; } + +input[type=submit] { + background-color: black; + color: white; + border-radius: 1em; + padding: 0.5em; + border: 1px solid white; + margin-left: 4em; +} + 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(); diff --git a/src/main.rs b/src/main.rs index 70646c3..da03c61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,18 +4,18 @@ Copyright (C) 2023 metamuffin <metamuffin.org> */ pub mod blog; +pub mod error; pub mod layout; pub mod pages; pub mod source; pub mod wellknown; -pub mod error; use blog::*; +use error::*; use pages::*; use rocket::{catchers, fairing::AdHoc, http::Header, routes}; use source::*; use wellknown::*; -use error::*; #[tokio::main] async fn main() { @@ -39,6 +39,8 @@ async fn main() { r_blog_index, r_blog_article, r_blog_atom, + r_style, + r_toggle_css, r_wellknown_security, r_wellknown_matrix_server, r_wellknown_matrix_client, diff --git a/src/pages.rs b/src/pages.rs index 482e254..7c92c4b 100644 --- a/src/pages.rs +++ b/src/pages.rs @@ -1,5 +1,11 @@ use crate::layout::{DynScaffold, Scaffold}; -use rocket::{get, response::Redirect, uri}; +use rocket::{ + get, + http::{ContentType, Cookie, CookieJar}, + post, + response::Redirect, + uri, +}; #[get("/")] pub fn r_root() -> Redirect { @@ -95,3 +101,19 @@ pub fn r_contact() -> DynScaffold<'static> { pub fn r_pgp_key() -> &'static str { include_str!("../assets/key.asc") } + +#[get("/style.css")] +pub fn r_style() -> (ContentType, &'static str) { + (ContentType::CSS, include_str!("../assets/style.css")) +} + +#[post("/toggle_css")] +pub fn r_toggle_css(jar: &CookieJar) -> Redirect { + let has_css = jar.get("css").map(|v| v.value() == "yes").unwrap_or(false); + jar.add( + Cookie::build("css", if has_css { "no" } else { "yes" }) + .permanent() + .finish(), + ); + Redirect::to(rocket::uri!(r_root())) +} |