zed/server/src/assets.rs
Antonio Scandurra 00f6bdcb24 Bundle and use Inconsolata v2.012
There's a newer version of the font available but ligatures seem
broken googlefonts/Inconsolata#58 and googlefonts/Inconsolata#52.

As part of this commit I also upgraded rust-embed to use the new
exclusion feature, which allows us to skip embedding OS files like
`.DS_Store`.
2021-09-04 17:02:20 +02:00

31 lines
806 B
Rust

use crate::{AppState, Request};
use anyhow::anyhow;
use rust_embed::RustEmbed;
use std::sync::Arc;
use tide::{http::mime, Server};
#[derive(RustEmbed)]
#[folder = "static"]
struct Static;
pub fn add_routes(app: &mut Server<Arc<AppState>>) {
app.at("/static/*path").get(get_static_asset);
}
async fn get_static_asset(request: Request) -> tide::Result {
let path = request.param("path").unwrap();
let content = Static::get(path).ok_or_else(|| anyhow!("asset not found at {}", path))?;
let content_type = if path.starts_with("svg") {
mime::SVG
} else if path.starts_with("styles") {
mime::CSS
} else {
mime::BYTE_STREAM
};
Ok(tide::Response::builder(200)
.content_type(content_type)
.body(content.data.as_ref())
.build())
}