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! {{style.metadata.description}
+