Rust library to generate static websites
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: css for website

+51 -40
+25 -8
crates/maudit/src/assets.rs
··· 14 14 pub use script::Script; 15 15 pub use style::{Style, StyleOptions}; 16 16 17 - use crate::AssetHashingStrategy; 18 - use crate::build::options::AssetsOptions; 17 + use crate::{AssetHashingStrategy, BuildOptions}; 19 18 20 19 #[derive(Default)] 21 20 pub struct PageAssets { ··· 29 28 #[derive(Clone)] 30 29 pub struct PageAssetsOptions { 31 30 pub assets_dir: PathBuf, 31 + pub output_assets_dir: PathBuf, 32 32 pub hashing_strategy: AssetHashingStrategy, 33 33 } 34 34 35 35 impl Default for PageAssetsOptions { 36 36 fn default() -> Self { 37 - let default_assets_options = AssetsOptions::default(); 37 + let default_build_options = BuildOptions::default(); 38 + let page_assets_optiosn = default_build_options.page_assets_options(); 39 + 38 40 Self { 39 - assets_dir: default_assets_options.assets_dir, 40 - hashing_strategy: default_assets_options.hashing_strategy, 41 + assets_dir: default_build_options.assets.assets_dir, 42 + output_assets_dir: page_assets_optiosn.assets_dir, 43 + hashing_strategy: page_assets_optiosn.hashing_strategy, 41 44 } 42 45 } 43 46 } ··· 92 95 let image = Image { 93 96 path: image_path.clone(), 94 97 assets_dir: self.options.assets_dir.clone(), 98 + output_assets_dir: self.options.output_assets_dir.clone(), 95 99 hash: calculate_hash( 96 100 &image_path, 97 101 Some(&HashConfig { ··· 132 136 let script = Script { 133 137 path: path.clone(), 134 138 assets_dir: self.options.assets_dir.clone(), 139 + output_assets_dir: self.options.output_assets_dir.clone(), 135 140 hash: calculate_hash(&path, None), 136 141 included: false, 137 142 }; ··· 154 159 let script = Script { 155 160 path: path.clone(), 156 161 assets_dir: self.options.assets_dir.clone(), 162 + output_assets_dir: self.options.output_assets_dir.clone(), 157 163 hash: calculate_hash(&path, None), 158 164 included: true, 159 165 }; ··· 187 193 let style = Style { 188 194 path: path.clone(), 189 195 assets_dir: self.options.assets_dir.clone(), 196 + output_assets_dir: self.options.output_assets_dir.clone(), 190 197 hash: calculate_hash( 191 198 &path, 192 199 Some(&HashConfig { ··· 235 242 let style = Style { 236 243 path: path.clone(), 237 244 assets_dir: self.options.assets_dir.clone(), 245 + output_assets_dir: self.options.output_assets_dir.clone(), 238 246 hash, 239 247 tailwind: options.tailwind, 240 248 included: true, ··· 247 255 #[allow(private_bounds)] // Users never interact with the internal trait, so it's fine 248 256 pub trait Asset: DynEq + InternalAsset + Sync + Send { 249 257 fn build_path(&self) -> PathBuf { 250 - self.assets_dir().join(self.final_file_name()) 258 + self.output_assets_dir().join(self.final_file_name()) 251 259 } 252 - fn url(&self) -> Option<String>; 253 - fn path(&self) -> &PathBuf; 260 + fn url(&self) -> Option<String> { 261 + format!( 262 + "/{}/{}", 263 + self.assets_dir().to_string_lossy(), 264 + self.final_file_name() 265 + ) 266 + .into() 267 + } 254 268 269 + fn path(&self) -> &PathBuf; 255 270 fn hash(&self) -> String; 256 271 257 272 // TODO: I don't like these next two methods for scripts and styles, we should get this from Rolldown somehow, but I don't know how. ··· 359 374 360 375 trait InternalAsset { 361 376 fn assets_dir(&self) -> &PathBuf; 377 + fn output_assets_dir(&self) -> &PathBuf; 362 378 } 363 379 364 380 impl Hash for dyn Asset { ··· 649 665 let style2 = Style { 650 666 path: style_path.clone(), 651 667 assets_dir: assets_options.assets_dir.clone(), 668 + output_assets_dir: assets_options.output_assets_dir.clone(), 652 669 hash: calculate_hash( 653 670 &style_path, 654 671 Some(&HashConfig {
+5 -9
crates/maudit/src/assets/image.rs
··· 64 64 pub struct Image { 65 65 pub path: PathBuf, 66 66 pub(crate) assets_dir: PathBuf, 67 + pub(crate) output_assets_dir: PathBuf, 67 68 pub(crate) hash: String, 68 69 pub(crate) options: Option<ImageOptions>, 69 70 } ··· 385 386 fn assets_dir(&self) -> &PathBuf { 386 387 &self.assets_dir 387 388 } 389 + 390 + fn output_assets_dir(&self) -> &PathBuf { 391 + &self.output_assets_dir 392 + } 388 393 } 389 394 390 395 impl Asset for Image { 391 - fn url(&self) -> Option<String> { 392 - format!( 393 - "/{}/{}", 394 - self.assets_dir().to_string_lossy(), 395 - self.final_file_name() 396 - ) 397 - .into() 398 - } 399 - 400 396 fn path(&self) -> &PathBuf { 401 397 &self.path 402 398 }
+5 -9
crates/maudit/src/assets/script.rs
··· 7 7 pub struct Script { 8 8 pub path: PathBuf, 9 9 pub(crate) assets_dir: PathBuf, 10 + pub(crate) output_assets_dir: PathBuf, 10 11 pub(crate) hash: String, 11 12 pub(crate) included: bool, 12 13 } ··· 15 16 fn assets_dir(&self) -> &PathBuf { 16 17 &self.assets_dir 17 18 } 18 - } 19 19 20 - impl Asset for Script { 21 - fn url(&self) -> Option<String> { 22 - format!( 23 - "/{}/{}", 24 - self.assets_dir().to_string_lossy(), 25 - self.final_file_name() 26 - ) 27 - .into() 20 + fn output_assets_dir(&self) -> &PathBuf { 21 + &self.output_assets_dir 28 22 } 23 + } 29 24 25 + impl Asset for Script { 30 26 fn path(&self) -> &PathBuf { 31 27 &self.path 32 28 }
+5 -9
crates/maudit/src/assets/style.rs
··· 12 12 pub struct Style { 13 13 pub path: PathBuf, 14 14 pub(crate) assets_dir: PathBuf, 15 + pub(crate) output_assets_dir: PathBuf, 15 16 pub(crate) hash: String, 16 17 pub(crate) tailwind: bool, 17 18 pub(crate) included: bool, ··· 21 22 fn assets_dir(&self) -> &PathBuf { 22 23 &self.assets_dir 23 24 } 24 - } 25 25 26 - impl Asset for Style { 27 - fn url(&self) -> Option<String> { 28 - format!( 29 - "/{}/{}", 30 - self.assets_dir().to_string_lossy(), 31 - self.final_file_name() 32 - ) 33 - .into() 26 + fn output_assets_dir(&self) -> &PathBuf { 27 + &self.output_assets_dir 34 28 } 29 + } 35 30 31 + impl Asset for Style { 36 32 fn path(&self) -> &PathBuf { 37 33 &self.path 38 34 }
+7 -2
crates/maudit/src/build.rs
··· 313 313 || !build_pages_styles.is_empty() 314 314 || !build_pages_scripts.is_empty() 315 315 { 316 - fs::create_dir_all(&page_assets_options.assets_dir)?; 316 + fs::create_dir_all(&page_assets_options.output_assets_dir)?; 317 317 } 318 318 319 319 if !build_pages_styles.is_empty() || !build_pages_scripts.is_empty() { ··· 365 365 BundlerOptions { 366 366 input: Some(bundler_inputs), 367 367 minify: Some(rolldown::RawMinifyOptions::Bool(!is_dev())), 368 - dir: Some(page_assets_options.assets_dir.to_string_lossy().to_string()), 368 + dir: Some( 369 + page_assets_options 370 + .output_assets_dir 371 + .to_string_lossy() 372 + .to_string(), 373 + ), 369 374 module_types: Some(module_types_hashmap), 370 375 ..Default::default() 371 376 },
+4 -3
crates/maudit/src/build/options.rs
··· 55 55 } 56 56 57 57 impl BuildOptions { 58 - /// Returns the fully resolved assets options, with the `assets_dir` set to be inside the `output_dir`. 59 - /// e.g. if `output_dir` is `dist` and `assets.assets_dir` is `_maudit`, this will return `dist/_maudit`. 58 + /// Returns the fully resolved assets options, with the `output_assets_dir` property resolved to be inside `output_dir`. 59 + /// e.g. if `output_dir` is `dist` and `assets.assets_dir` is `_maudit`, `output_assets_dir` will return `dist/_maudit`. The user-entered `assets.assets_dir` is also available and unchanged. 60 60 pub fn page_assets_options(&self) -> PageAssetsOptions { 61 61 PageAssetsOptions { 62 - assets_dir: self.output_dir.join(&self.assets.assets_dir), 62 + assets_dir: self.assets.assets_dir.clone(), 63 + output_assets_dir: self.output_dir.join(&self.assets.assets_dir), 63 64 hashing_strategy: self.assets.hashing_strategy, 64 65 } 65 66 }