feat: embed htmx and picocss as static routes
This commit is contained in:
parent
2c44f788d9
commit
ad015b47e4
6 changed files with 431 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
mod error;
|
||||
mod gpodder;
|
||||
mod r#static;
|
||||
|
||||
use axum::{
|
||||
body::Body,
|
||||
|
|
@ -20,6 +21,7 @@ pub struct Context {
|
|||
pub fn app(ctx: Context) -> Router {
|
||||
Router::new()
|
||||
.merge(gpodder::router(ctx.clone()))
|
||||
.nest("/static", r#static::router())
|
||||
.layer(axum::middleware::from_fn(header_logger))
|
||||
.layer(axum::middleware::from_fn(body_logger))
|
||||
.layer(TraceLayer::new_for_http())
|
||||
|
|
|
|||
1
src/server/static/htmx_2.0.4.min.js
vendored
Normal file
1
src/server/static/htmx_2.0.4.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
34
src/server/static/mod.rs
Normal file
34
src/server/static/mod.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use std::io::Cursor;
|
||||
|
||||
use axum::{routing::get, Router};
|
||||
use axum_extra::{headers::Range, TypedHeader};
|
||||
use axum_range::{KnownSize, Ranged};
|
||||
|
||||
use super::Context;
|
||||
|
||||
const HTMX: &str = include_str!("./htmx_2.0.4.min.js");
|
||||
const PICOCSS: &str = include_str!("./pico_2.1.1.classless.jade.min.css");
|
||||
|
||||
type RangedResponse = Ranged<KnownSize<Cursor<&'static str>>>;
|
||||
|
||||
pub fn router() -> Router<Context> {
|
||||
Router::new()
|
||||
.route("/htmx_2.0.4.min.js", get(get_htmx))
|
||||
.route("/pico_2.1.1.classless.jade.min.css", get(get_picocss))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn serve_static(data: &'static str, range: Option<Range>) -> RangedResponse {
|
||||
let cursor = Cursor::new(data);
|
||||
let body = KnownSize::sized(cursor, data.len() as u64);
|
||||
|
||||
Ranged::new(range, body)
|
||||
}
|
||||
|
||||
async fn get_htmx(range: Option<TypedHeader<Range>>) -> RangedResponse {
|
||||
serve_static(HTMX, range.map(|TypedHeader(range)| range))
|
||||
}
|
||||
|
||||
async fn get_picocss(range: Option<TypedHeader<Range>>) -> RangedResponse {
|
||||
serve_static(PICOCSS, range.map(|TypedHeader(range)| range))
|
||||
}
|
||||
4
src/server/static/pico_2.1.1.classless.jade.min.css
vendored
Normal file
4
src/server/static/pico_2.1.1.classless.jade.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue