From 5a6d1e8fc70cc4c8cfa34cdc7921afbebcc68b1f Mon Sep 17 00:00:00 2001 From: Bauke Date: Mon, 30 Aug 2021 16:35:59 +0200 Subject: [PATCH] Add userstyles back. --- Cargo.toml | 5 +++ index.html | 1 + package.json | 2 +- source/build.rs | 23 ++++++++++ source/main.rs | 5 +++ source/routes/mod.rs | 3 ++ source/routes/userstyles.rs | 57 +++++++++++++++++++++++++ source/scss/components/_userstyles.scss | 36 ++++++++++++++++ source/scss/index.scss | 2 + 9 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 source/build.rs create mode 100644 source/routes/userstyles.rs create mode 100644 source/scss/components/_userstyles.scss diff --git a/Cargo.toml b/Cargo.toml index 700ccda..b9deca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ version = "1.0.0" edition = "2018" repository = "https://git.holllo.cc/Bauke/bauke.xyz" license = "AGPL-3.0-or-later" +build = "source/build.rs" [[bin]] name = "bauke-xyz" @@ -17,6 +18,7 @@ gloo-console = "0.1.0" gloo-timers = "0.2.1" log = "0.4.14" rand = "0.8.4" +userstyles = { git = "https://git.holllo.cc/Bauke/userstyles" } wasm-logger = "0.2.0" yew = "0.18.0" yew-router = "0.15.0" @@ -24,3 +26,6 @@ yew-router = "0.15.0" [dependencies.getrandom] version = "0.2.3" features = ["js"] + +[build-dependencies] +userstyles = { git = "https://git.holllo.cc/Bauke/userstyles" } diff --git a/index.html b/index.html index 2b21ae1..e0c8e0c 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,7 @@ + diff --git a/package.json b/package.json index ba0a79c..a09616b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "license": "AGPL-3.0-or-later", "scripts": { - "deploy": "trunk clean && trunk build --release && yarn deploy:netlify", + "deploy": "trunk clean && cargo build -q && trunk build --release && yarn deploy:netlify", "deploy:netlify": "netlify deploy --prod --dir 'public/' -s bauke.xyz", "test": "stylelint 'source/**/*.scss'" }, diff --git a/source/build.rs b/source/build.rs new file mode 100644 index 0000000..b9cd1ef --- /dev/null +++ b/source/build.rs @@ -0,0 +1,23 @@ +/// Build script for the website. + +fn main() { + println!("cargo:rerun-if-changed=source/**"); + let build_dir = std::path::PathBuf::from("target"); + + for target in userstyles::ALL_USERSTYLES { + let style = userstyles::Userstyle::load(target).unwrap(); + let style_name = style.metadata.name.to_lowercase().replace(" ", "-"); + + let style_dir = build_dir.join("userstyles"); + std::fs::create_dir_all(&style_dir).unwrap(); + + let style_file = style_dir.join(format!("{}.user.css", style_name)); + let formatted = style.format(); + std::fs::write(style_file, formatted).unwrap(); + + if let Some(image) = style.image { + let image_file = style_dir.join(format!("{}.png", style_name)); + std::fs::write(image_file, image).unwrap(); + } + } +} diff --git a/source/main.rs b/source/main.rs index 86da266..2d6d7cd 100644 --- a/source/main.rs +++ b/source/main.rs @@ -14,6 +14,8 @@ pub(crate) mod routes; /// All routes. #[derive(Clone, yew_router::Switch)] pub(crate) enum Route { + #[to = "/userstyles"] + Userstyles, #[to = "/{}"] NotFound(String), #[to = "/"] @@ -51,6 +53,9 @@ impl Component for Model { }, Route::Home => html! { + }, + Route::Userstyles => html! { + } } }) diff --git a/source/routes/mod.rs b/source/routes/mod.rs index 7eedb86..4e25e8a 100644 --- a/source/routes/mod.rs +++ b/source/routes/mod.rs @@ -1,4 +1,7 @@ /// The route for `/`. mod home; +/// The route for `/userstyles`. +mod userstyles; +pub(crate) use self::userstyles::UserstylesRoute; pub(crate) use home::HomeRoute; diff --git a/source/routes/userstyles.rs b/source/routes/userstyles.rs new file mode 100644 index 0000000..78e2d64 --- /dev/null +++ b/source/routes/userstyles.rs @@ -0,0 +1,57 @@ +use yew::prelude::*; + +use crate::components::PageHeader; + +/// The route for `/userstyles`. +pub(crate) struct UserstylesRoute; + +impl Component for UserstylesRoute { + type Message = (); + type Properties = (); + + fn create(_props: Self::Properties, _link: ComponentLink) -> Self { + log::trace!("Creating UserstylesRoute"); + + Self + } + + fn update(&mut self, _msg: Self::Message) -> ShouldRender { + unimplemented!() + } + + fn change(&mut self, _props: Self::Properties) -> ShouldRender { + false + } + + fn view(&self) -> Html { + let styles = userstyles::ALL_USERSTYLES + .iter() + .map(|target| userstyles::Userstyle::load(target)) + .flatten() + .map(|style| { + let style_name = style.metadata.name.to_lowercase().replace(" ", "-"); + + html! { +
+
+ +

{style.metadata.name}

+ {"Install"} +
+ +

{style.metadata.description}

+
+ } + }) + .collect::>(); + + html! { + <> + +
+ {styles} +
+ + } + } +} diff --git a/source/scss/components/_userstyles.scss b/source/scss/components/_userstyles.scss new file mode 100644 index 0000000..67fdf84 --- /dev/null +++ b/source/scss/components/_userstyles.scss @@ -0,0 +1,36 @@ +.userstyles { + background-color: transparent; + display: grid; + gap: 1rem; + grid-template-columns: repeat(2, 1fr); + padding: 0; + + .style { + background-color: #333; + padding: 1rem; + + .header { + align-items: center; + display: flex; + margin-bottom: 0.5rem; + + img { + height: 4rem; + margin-right: 0.5rem; + } + + a { + border: 2px solid; + margin-left: auto; + padding: 0.5rem; + text-decoration: none; + + &:hover { + background-color: #ff0; + border-color: #ff0; + color: #000; + } + } + } + } +} diff --git a/source/scss/index.scss b/source/scss/index.scss index 405db7e..8154259 100644 --- a/source/scss/index.scss +++ b/source/scss/index.scss @@ -29,3 +29,5 @@ button { @import 'components/page-footer'; @import 'components/page-header'; @import 'components/page-main'; + +@import 'components/userstyles';