1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
#[cfg(feature = "warp")] use warp::{ http::header::{HeaderValue, CACHE_CONTROL, CONTENT_TYPE}, hyper::Body, reply::Response, Filter, Rejection, Reply, }; #[cfg(feature = "warp")] pub fn route() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { assets().or(fonts()).or(min_assets()) } pub static CSS: &str = include_str!("../css/stylus.css"); pub static MAP: &str = include_str!("../css/stylus.css.map"); #[cfg(feature = "warp")] pub fn assets() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { warp::path("assets").and( warp::path("stylus.css") .map(|| Css { body: CSS }) .or(warp::path("stylus.css.map").map(|| Map { body: MAP })), ) } pub static MIN_CSS: &str = include_str!("../css/stylus.min.css"); pub static MIN_MAP: &str = include_str!("../css/stylus.min.css.map"); #[cfg(feature = "warp")] pub fn min_assets() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { warp::path("assets").and( warp::path("stylus.min.css") .map(|| Css { body: MIN_CSS }) .or(warp::path("stylus.min.css.map").map(|| Map { body: MIN_MAP })), ) } pub static FONT_REGULAR_TTF: &[u8] = include_bytes!("../fonts/noto-sans-regular.ttf"); pub static FONT_REGULAR_WOFF: &[u8] = include_bytes!("../fonts/noto-sans-regular.woff"); pub static FONT_REGULAR_WOFF2: &[u8] = include_bytes!("../fonts/noto-sans-regular.woff2"); pub static FONT_ITALIC_TTF: &[u8] = include_bytes!("../fonts/noto-sans-italic.ttf"); pub static FONT_ITALIC_WOFF: &[u8] = include_bytes!("../fonts/noto-sans-italic.woff"); pub static FONT_ITALIC_WOFF2: &[u8] = include_bytes!("../fonts/noto-sans-italic.woff2"); pub static FONT_BOLD_TTF: &[u8] = include_bytes!("../fonts/noto-sans-bold.ttf"); pub static FONT_BOLD_WOFF: &[u8] = include_bytes!("../fonts/noto-sans-bold.woff"); pub static FONT_BOLD_WOFF2: &[u8] = include_bytes!("../fonts/noto-sans-bold.woff2"); pub static FONT_BOLD_ITALIC_TTF: &[u8] = include_bytes!("../fonts/noto-sans-bold-italic.ttf"); pub static FONT_BOLD_ITALIC_WOFF: &[u8] = include_bytes!("../fonts/noto-sans-bold-italic.woff"); pub static FONT_BOLD_ITALIC_WOFF2: &[u8] = include_bytes!("../fonts/noto-sans-bold-italic.woff2"); #[cfg(feature = "warp")] pub fn fonts() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { warp::path("fonts").and(ttf().or(woff()).or(woff2())) } #[cfg(feature = "warp")] fn ttf() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { warp::get().and( warp::path("noto-sans-regular.ttf") .map(|| Font { body: FONT_REGULAR_TTF, }) .or(warp::path("noto-sans-italic.ttf").map(|| Font { body: FONT_ITALIC_TTF, })) .or(warp::path("noto-sans-bold.ttf").map(|| Font { body: FONT_BOLD_TTF, })) .or(warp::path("noto-sans-bold-italic.ttf").map(|| Font { body: FONT_BOLD_ITALIC_TTF, })), ) } #[cfg(feature = "warp")] fn woff() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { warp::get().and( warp::path("noto-sans-regular.woff") .map(|| Font { body: FONT_REGULAR_WOFF, }) .or(warp::path("noto-sans-italic.woff").map(|| Font { body: FONT_ITALIC_WOFF, })) .or(warp::path("noto-sans-bold.woff").map(|| Font { body: FONT_BOLD_WOFF, })) .or(warp::path("noto-sans-bold-italic.woff").map(|| Font { body: FONT_BOLD_ITALIC_WOFF, })), ) } #[cfg(feature = "warp")] fn woff2() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { warp::get().and( warp::path("noto-sans-regular.woff2") .map(|| Font { body: FONT_REGULAR_WOFF2, }) .or(warp::path("noto-sans-italic.woff2").map(|| Font { body: FONT_ITALIC_WOFF2, })) .or(warp::path("noto-sans-bold.woff2").map(|| Font { body: FONT_BOLD_WOFF2, })) .or(warp::path("noto-sans-bold-italic.woff2").map(|| Font { body: FONT_BOLD_ITALIC_WOFF2, })), ) } #[cfg(feature = "warp")] struct Css<T> { body: T, } #[cfg(feature = "warp")] impl<T> Reply for Css<T> where Body: From<T>, T: Send, { #[inline] fn into_response(self) -> Response { let mut res = Response::new(Body::from(self.body)); res.headers_mut().insert( CACHE_CONTROL, HeaderValue::from_static("public, max-age=37260"), ); res.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_static("text/css; charset=utf-8"), ); res } } #[cfg(feature = "warp")] struct Font<T> { body: T, } #[cfg(feature = "warp")] impl<T> Reply for Font<T> where Body: From<T>, T: Send, { #[inline] fn into_response(self) -> Response { let mut res = Response::new(Body::from(self.body)); res.headers_mut().insert( CACHE_CONTROL, HeaderValue::from_static("public, max-age=37260"), ); res.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_static("application/octet-stream"), ); res } } #[cfg(feature = "warp")] struct Map<T> { body: T, } #[cfg(feature = "warp")] impl<T> Reply for Map<T> where Body: From<T>, T: Send, { #[inline] fn into_response(self) -> Response { let mut res = Response::new(Body::from(self.body)); res.headers_mut().insert( CACHE_CONTROL, HeaderValue::from_static("public, max-age=37260"), ); res.headers_mut().insert( CONTENT_TYPE, HeaderValue::from_static("application/json; charset=utf-8"), ); res } }