Hashless assets (#4312)

* add support for external assets

* fix playwright tests

* add more documentation to with_hash_suffix

* restore external asset hashing tests

* Update gtk workflow dependencies

* fix doc test

* multiple versions of libgtk

* clear dx in playwright tests

* fix fullstack caching test

* try without apt cache

* cache everything except libxdo-dev

* revert ci changes

* fix wasm asset options

* fix merge conflict

* recommend the used attribute instead

* Move options to AssetOptionsBuilder

* Don't deprecate non-canonical new asset options functions

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2025-06-30 19:21:49 -07:00
1 parent 0bd376b873
commit e74c838441
22 files changed
+569 -316

No files matched your search

@@ -1,4 +1,4 @@
use crate::AssetOptions;
use crate::{AssetOptions, AssetOptionsBuilder, AssetVariant};
use const_serialize::SerializeConst;
use std::collections::HashSet;
@@ -24,48 +24,70 @@ pub struct CssModuleAssetOptions {
impl Default for CssModuleAssetOptions {
fn default() -> Self {
Self::new()
Self::default()
}
}
impl CssModuleAssetOptions {
/// Create a new css asset using the builder
pub const fn new() -> Self {
pub const fn new() -> AssetOptionsBuilder<CssModuleAssetOptions> {
AssetOptions::css_module()
}
/// Create a default css module asset options
pub const fn default() -> Self {
Self {
preload: false,
minify: true,
}
}
/// Sets whether the css should be minified (default: true)
///
/// Minifying the css can make your site load faster by loading less data
#[allow(unused)]
pub const fn with_minify(self, minify: bool) -> Self {
Self { minify, ..self }
}
/// Check if the asset is minified
pub const fn minified(&self) -> bool {
self.minify
}
/// Make the asset preloaded
///
/// Preloading css will make the image start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner
#[allow(unused)]
pub const fn with_preload(self, preload: bool) -> Self {
Self { preload, ..self }
}
/// Check if the asset is preloaded
pub const fn preloaded(&self) -> bool {
self.preload
}
}
impl AssetOptions {
/// Create a new css module asset builder
///
/// ```rust
/// # use manganis::{asset, Asset, CssModuleAssetOptions};
/// const _: Asset = asset!("/assets/style.css", AssetOptions::css_module());
/// ```
pub const fn css_module() -> AssetOptionsBuilder<CssModuleAssetOptions> {
AssetOptionsBuilder::variant(CssModuleAssetOptions::default())
}
}
impl AssetOptionsBuilder<CssModuleAssetOptions> {
/// Sets whether the css should be minified (default: true)
///
/// Minifying the css can make your site load faster by loading less data
pub const fn with_minify(mut self, minify: bool) -> Self {
self.variant.minify = minify;
self
}
/// Make the asset preloaded
///
/// Preloading css will make the image start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner
pub const fn with_preload(mut self, preload: bool) -> Self {
self.variant.preload = preload;
self
}
/// Convert the options into options for a generic asset
pub const fn into_asset_options(self) -> AssetOptions {
AssetOptions::CssModule(self)
AssetOptions {
add_hash: self.add_hash,
variant: AssetVariant::CssModule(self.variant),
}
}
}