From 1fab9c664d984d3be04237713c9179809d8fe6ad Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sun, 9 May 2021 15:57:44 +0200 Subject: [PATCH] Update slotmap + handle in memory XML content type in zola serve Second part of #1308 --- Cargo.lock | 26 ++++++++++++++++---------- components/library/Cargo.toml | 2 +- components/site/Cargo.toml | 2 +- src/cmd/serve.rs | 16 +++++++++++++--- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c317d575..c2d913cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/components/library/Cargo.toml b/components/library/Cargo.toml index 81799616..bfaac903 100644 --- a/components/library/Cargo.toml +++ b/components/library/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Vincent Prouillet "] edition = "2018" [dependencies] -slotmap = "0.4" +slotmap = "1" rayon = "1" chrono = { version = "0.4", features = ["serde"] } tera = "1" diff --git a/components/site/Cargo.toml b/components/site/Cargo.toml index 0a69fd43..7ab0bb42 100644 --- a/components/site/Cargo.toml +++ b/components/site/Cargo.toml @@ -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" } diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 79681f10..724aff56 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -93,7 +93,7 @@ async fn handle_request(req: Request, mut root: PathBuf) -> Result Response { .expect("Could not build livereload.js response") } -fn in_memory_html(content: &str) -> Response { +fn in_memory_content(path: &RelativePathBuf, content: &str) -> Response { + 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")