Refactor, create service-assets

This commit is contained in:
2026-03-23 09:46:37 -07:00
parent 368034a177
commit 67e63019c5
61 changed files with 482 additions and 785 deletions

View File

@@ -0,0 +1,71 @@
use axum::Router;
use libservice::ToService;
use servable::ServableRouter;
use tower_http::compression::{CompressionLayer, DefaultPredicate};
pub mod assets;
pub mod components;
pub struct AssetService {}
impl AssetService {
#[inline]
pub fn new() -> Self {
Self {}
}
}
impl ToService for AssetService {
#[inline]
fn make_router(&self) -> Option<Router<()>> {
use assets::*;
let router = ServableRouter::new()
.add_page_with_route(&HTMX)
.add_page_with_route(&HTMX_JSON)
.add_page_with_route(&IMG_ICON)
// fira
.add_page_with_route(&CSS_FIRA)
.add_page_with_route(&FONT_FIRACODE_BOLD)
.add_page_with_route(&FONT_FIRACODE_LIGHT)
.add_page_with_route(&FONT_FIRACODE_MEDIUM)
.add_page_with_route(&FONT_FIRACODE_REGULAR)
.add_page_with_route(&FONT_FIRACODE_SEMIBOLD)
.add_page_with_route(&FONT_FIRACODE_VF)
// fa
.add_page_with_route(&CSS_FONTAWESOME)
.add_page_with_route(&FONT_FA_BRANDS_WOFF2)
.add_page_with_route(&FONT_FA_REGULAR_WOFF2)
.add_page_with_route(&FONT_FA_SOLID_WOFF2)
.add_page_with_route(&*FONT_FA_BRANDS_TTF)
.add_page_with_route(&*FONT_FA_REGULAR_TTF)
.add_page_with_route(&*FONT_FA_SOLID_TTF)
.into_router();
let compression: CompressionLayer = CompressionLayer::new()
.br(true)
.deflate(true)
.gzip(true)
.zstd(true)
.compress_when(DefaultPredicate::new());
Some(router.layer(compression))
}
#[inline]
fn service_name(&self) -> Option<String> {
Some("assets".to_owned())
}
}
#[test]
#[expect(clippy::unwrap_used)]
fn server_builds_without_panic() {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
let router = AssetService {}.make_router();
assert!(router.is_some())
});
}