use autumn_web::assets::{PluginAsset, PluginAssets};
use maud::Markup;
use crate::assets::{LOADER_JS, REACT_ASSETS};
#[must_use]
pub fn react_script() -> Markup {
REACT_ASSETS.deferred_script_tag(LOADER_JS)
}
#[must_use]
pub fn react_bundle(bundle: &PluginAssets) -> Markup {
let files = |ext: &'static str| {
bundle
.iter()
.filter(move |asset| asset.logical_path().ends_with(ext))
};
maud::html! {
@for asset in files(".css") { (bundle.stylesheet_tag(asset.logical_path())) }
@for asset in files(".js") { (bundle.deferred_script_tag(asset.logical_path())) }
@for asset in files(".mjs") { (module_tag(asset)) }
}
}
fn module_tag(asset: &PluginAsset) -> Markup {
maud::html! {
script type="module" src=(asset.url()) integrity=(asset.integrity())
crossorigin="anonymous" {}
}
}