From 4e17ef7dff5a389a9246bff40f7fe9647574fd2f Mon Sep 17 00:00:00 2001 From: Fries Date: Sun, 9 Jul 2023 22:09:07 -0700 Subject: [PATCH] update stylesheet and clean up asset code the stylesheet got a new update from my websites stylesheet with the bigger font sizes and i split the hyperlegible font face css into its own file and made the asset code cleaner. --- public/hyperlegible.css | 43 ++++++++++++++++++++++++ public/style.css | 73 +++++++++++++++++------------------------ src/assets.rs | 54 +++++++++++++++++++++--------- templates/base.html | 16 +++++++++ templates/error.html | 25 ++++++-------- templates/index.html | 40 +++++++++------------- 6 files changed, 152 insertions(+), 99 deletions(-) create mode 100644 public/hyperlegible.css create mode 100644 templates/base.html diff --git a/public/hyperlegible.css b/public/hyperlegible.css new file mode 100644 index 0000000..eca87f6 --- /dev/null +++ b/public/hyperlegible.css @@ -0,0 +1,43 @@ +@font-face { + font-family: Atkinson Hyperlegible; + font-style: normal; + font-display: swap; + font-weight: 400; + src: url(/public/woff2/atkinson-hyperlegible-latin-ext-400-normal.woff2) format("woff2"), + url(/public/woff/atkinson-hyperlegible-all-400-normal.woff) format("woff"); + unicode-range: U+0100-024F, + U+0259, + U+1E00-1EFF, + U+2020, + U+20A0-20AB, + U+20AD-20CF, + U+2113, + U+2C60-2C7F, + U+A720-A7FF +} + +@font-face { + font-family: Atkinson Hyperlegible; + font-style: normal; + font-display: swap; + font-weight: 400; + src: url(/public/woff2/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2"), + url(/public/woff/atkinson-hyperlegible-all-400-normal.woff) format("woff"); + unicode-range: U+0000-00FF, + U+0131, + U+0152-0153, + U+02BB-02BC, + U+02C6, + U+02DA, + U+02DC, + U+2000-206F, + U+2074, + U+20AC, + U+2122, + U+2191, + U+2193, + U+2212, + U+2215, + U+FEFF, + U+FFFD +} diff --git a/public/style.css b/public/style.css index a1019a2..2674a9d 100644 --- a/public/style.css +++ b/public/style.css @@ -14,64 +14,51 @@ } } +:root { + --h1-font-size: 3.225rem; + --h2-font-size: 2.825rem; + --h3-font-size: 2.225rem; + --h4-font-size: 1.665rem; + --default-font-size: 1.375rem; + --h6-font-size: 1.185rem; +} + body { font-family: "Atkinson Hyperlegible", sans-serif; text-align: center; + font-size: var(--default-font-size); max-width: 600px; margin: auto; background-color: var(--background-color); color: var(--text-color) } + a { + font-size: var(--default-font-size); color: var(--link-color); - font-size: 22px; } -p { - font-size: 22px; +h1 { + font-size: var(--h1-font-size); } -@font-face { - font-family: Atkinson Hyperlegible; - font-style: normal; - font-display: swap; - font-weight: 400; - src: url(/public/woff2/atkinson-hyperlegible-latin-ext-400-normal.woff2) format("woff2"), - url(/public/woff/atkinson-hyperlegible-all-400-normal.woff) format("woff"); - unicode-range: U+0100-024F, - U+0259, - U+1E00-1EFF, - U+2020, - U+20A0-20AB, - U+20AD-20CF, - U+2113, - U+2C60-2C7F, - U+A720-A7FF +h2 { + font-size: var(--h2-font-size); +} + +h3 { + font-size: var(--h3-font-size); } -@font-face { - font-family: Atkinson Hyperlegible; - font-style: normal; - font-display: swap; - font-weight: 400; - src: url(/public/woff2/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2"), - url(/public/woff/atkinson-hyperlegible-all-400-normal.woff) format("woff"); - unicode-range: U+0000-00FF, - U+0131, - U+0152-0153, - U+02BB-02BC, - U+02C6, - U+02DA, - U+02DC, - U+2000-206F, - U+2074, - U+20AC, - U+2122, - U+2191, - U+2193, - U+2212, - U+2215, - U+FEFF, - U+FFFD +h4 { + font-size: var(--h4-font-size); +} + +h5 { + font-size: var(--default-font-size); +} + +h6 { + font-size: var(--h6-font-size); } diff --git a/src/assets.rs b/src/assets.rs index 83579a0..683cd94 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -1,14 +1,29 @@ -use std::borrow::Cow; - use askama_rocket::Template; -use rocket::http::Status; -use rust_embed::RustEmbed; +use rocket::{http::Status, response::content::RawCss}; +use rust_embed::{EmbeddedFile, RustEmbed}; use shared::names::Site; +use std::borrow::Cow; #[derive(RustEmbed)] #[folder = "public/"] pub struct PublicAssets; +impl PublicAssets { + fn get_asset(file_path: &str) -> Result { + match PublicAssets::get(file_path) { + Some(asset) => Ok(asset), + None => Err(Status::NotFound), + } + } + fn get_string(file_path: &str) -> Result { + let asset = PublicAssets::get_asset(file_path)?; + match std::str::from_utf8(&asset.data) { + Ok(string) => Ok(string.to_string()), + Err(_) => Err(Status::InternalServerError), + } + } +} + #[derive(Responder)] #[response(status = 200, content_type = "font/woff2")] pub struct RawWoff2Font(pub Cow<'static, [u8]>); @@ -21,26 +36,33 @@ pub struct RawWoffFont(pub Cow<'static, [u8]>); #[template(path = "error.html")] pub struct ErrorTemplate<'a> { pub error: &'a str, - pub error_description: &'a str + pub error_description: &'a str, } #[derive(Template)] #[template(path = "index.html")] pub struct IndexTemplate { - pub sites: Vec + pub sites: Vec, } #[derive(Responder)] pub struct ErrorTemplateResponder<'a> { - template: ErrorTemplate<'a> + template: ErrorTemplate<'a>, } -#[get("/style.css")] -pub fn style() -> Result, Status> { - let style = PublicAssets::get("style.css").unwrap(); - match std::str::from_utf8(&style.data) { - Ok(style) => Ok(rocket::response::content::RawCss::(style.to_string())), - Err(_) => Err(Status::InternalServerError), +#[get("/css/