servable/
lib.rs

1#![doc = include_str!("../README.md")]
2// readme is symlinked to the root of this repo
3// because `cargo publish` works from a different dir,
4// and needs a different relative path than cargo build.
5// https://github.com/rust-lang/cargo/issues/13309
6
7pub mod mime;
8
9mod types;
10
11use rand::{Rng, distr::Alphanumeric};
12pub use types::*;
13
14mod router;
15pub use router::*;
16
17mod servable;
18pub use servable::*;
19
20#[cfg(test)] // Used in doctests
21use tower_http as _;
22
23//
24//
25//
26
27#[cfg(feature = "image")]
28pub mod transform;
29
30/// A unique string that can be used for cache-busting.
31///
32/// Note that this string changes every time this code is started,
33/// even if the data inside the program did not change.
34pub static CACHE_BUST_STR: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
35	rand::rng()
36		.sample_iter(&Alphanumeric)
37		.take(10)
38		.map(char::from)
39		.collect()
40});
41
42//
43//
44//
45
46/// HTMX 2.0.8, minified
47#[cfg(feature = "htmx-2.0.8")]
48pub const HTMX_2_0_8: servable::StaticAsset = servable::StaticAsset {
49	bytes: include_str!("../htmx/htmx-2.0.8.min.js").as_bytes(),
50	mime: mime::MimeType::Javascript,
51	ttl: StaticAsset::DEFAULT_TTL,
52};
53
54/// HTMX json extension, 1.19.2.
55/// Compatible with:
56/// - [HTMX_2_0_8]
57#[cfg(feature = "htmx-2.0.8")]
58pub const EXT_JSON_1_19_12: servable::StaticAsset = servable::StaticAsset {
59	bytes: include_str!("../htmx/json-enc-1.9.12.js").as_bytes(),
60	mime: mime::MimeType::Javascript,
61	ttl: StaticAsset::DEFAULT_TTL,
62};