Update slotmap + handle in memory XML content type in zola serve
Second part of #1308
This commit is contained in:
parent
fecc3cf148
commit
1fab9c664d
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -309,9 +309,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cd5a7748210e7ec1a9696610b1015e6e31fbf58f77a160801f124bd1c36592a"
|
||||
checksum = "dec1028182c380cc45a2e2c5ec841134f2dfd0f8f5f0a5bcd68004f81b5efdf4"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
|
@ -900,9 +903,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "http-body"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737"
|
||||
checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9"
|
||||
dependencies = [
|
||||
"bytes 1.0.1",
|
||||
"http",
|
||||
|
@ -2071,9 +2074,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.3"
|
||||
version = "1.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce5f1ceb7f74abbce32601642fcf8e8508a8a8991e0621c7d750295b9095702b"
|
||||
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
@ -2420,9 +2423,12 @@ checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527"
|
|||
|
||||
[[package]]
|
||||
name = "slotmap"
|
||||
version = "0.4.0"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c46a3482db8f247956e464d783693ece164ca056e6e67563ee5505bdb86452cd"
|
||||
checksum = "585cd5dffe4e9e06f6dfdf66708b70aca3f781bed561f4f667b2d9c0d4559e36"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slug"
|
||||
|
@ -2923,9 +2929,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
|||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.2.1"
|
||||
version = "2.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b"
|
||||
checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
|
|
|
@ -5,7 +5,7 @@ authors = ["Vincent Prouillet <prouillet.vincent@gmail.com>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
slotmap = "0.4"
|
||||
slotmap = "1"
|
||||
rayon = "1"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
tera = "1"
|
||||
|
|
|
@ -15,7 +15,7 @@ serde_derive = "1"
|
|||
sass-rs = "0.2"
|
||||
lazy_static = "1.1"
|
||||
relative-path = "1"
|
||||
slotmap = "0.4"
|
||||
slotmap = "1"
|
||||
url = "2"
|
||||
|
||||
errors = { path = "../errors" }
|
||||
|
|
|
@ -93,7 +93,7 @@ async fn handle_request(req: Request<Body>, mut root: PathBuf) -> Result<Respons
|
|||
}
|
||||
|
||||
if let Some(content) = SITE_CONTENT.read().unwrap().get(&path) {
|
||||
return Ok(in_memory_html(content));
|
||||
return Ok(in_memory_content(&path, content));
|
||||
}
|
||||
|
||||
// Handle only `GET`/`HEAD` requests
|
||||
|
@ -152,9 +152,19 @@ fn livereload_js() -> Response<Body> {
|
|||
.expect("Could not build livereload.js response")
|
||||
}
|
||||
|
||||
fn in_memory_html(content: &str) -> Response<Body> {
|
||||
fn in_memory_content(path: &RelativePathBuf, content: &str) -> Response<Body> {
|
||||
let content_type = match path.extension() {
|
||||
Some(ext) => {
|
||||
match ext {
|
||||
"xml" => "text/xml",
|
||||
"json" => "application/json",
|
||||
_ => "text/html",
|
||||
}
|
||||
},
|
||||
None => "text/html",
|
||||
};
|
||||
Response::builder()
|
||||
.header(header::CONTENT_TYPE, "text/html")
|
||||
.header(header::CONTENT_TYPE, content_type)
|
||||
.status(StatusCode::OK)
|
||||
.body(content.to_owned().into())
|
||||
.expect("Could not build HTML response")
|
||||
|
|
Loading…
Reference in a new issue