From db5c8758f748562cf2c51db63f957181b2766bbc Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 04:13:12 +0000 Subject: [PATCH 01/13] Make pure menu dropdowns keyboard accessible Fixes #67 --- templates/footer.hbs | 171 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/templates/footer.hbs b/templates/footer.hbs index aca7519a0..80e55dc7d 100644 --- a/templates/footer.hbs +++ b/templates/footer.hbs @@ -1,3 +1,174 @@ {{#if varsb.javascript_highlightjs}}{{/if}} + From 4161d40b66672b69d6fa2638a5d75215e7011657 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 19:19:16 +0000 Subject: [PATCH 02/13] Move (minified) menu.js to separate file --- Cargo.lock | 7 ++ Cargo.toml | 1 + build.rs | 19 +++++ src/web/mod.rs | 9 +++ src/web/routes.rs | 1 + templates/footer.hbs | 172 +------------------------------------------ templates/menu.js | 171 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 209 insertions(+), 171 deletions(-) create mode 100644 templates/menu.js diff --git a/Cargo.lock b/Cargo.lock index 0f23b5ecc..fba6b514f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,6 +327,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "magic 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "minifier 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "params 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1062,6 +1063,11 @@ dependencies = [ "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "minifier" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "miniz-sys" version = "0.1.10" @@ -3014,6 +3020,7 @@ dependencies = [ "checksum mime 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "4b082692d3f6cf41b453af73839ce3dfc212c4411cbb2441dff80a716e38bd79" "checksum mime_guess 1.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2d4c0961143b8efdcfa29c3ae63281601b446a4a668165454b6c90f8024954c5" "checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed" +"checksum minifier 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16b1492b655977a6de47e262383c02de37873e8c7978986a52b0f9ee6c4ca39e" "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" "checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432" "checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" diff --git a/Cargo.toml b/Cargo.toml index 62f9c00a2..dbb508098 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ once_cell = "1.2.0" time = "0.1" git2 = "0.9" sass-rs = "0.2" +minifier = "^0.0.1" [[bin]] name = "cratesfyi" diff --git a/build.rs b/build.rs index 292f85b2f..9c131423b 100644 --- a/build.rs +++ b/build.rs @@ -2,6 +2,7 @@ extern crate time; extern crate sass_rs; extern crate git2; +extern crate minifier; use std::env; use std::path::Path; @@ -13,6 +14,7 @@ use git2::Repository; fn main() { write_git_version(); compile_sass(); + minify_js(); } @@ -49,3 +51,20 @@ fn compile_sass() { let mut file = File::create(&dest_path).unwrap(); file.write_all(css.as_bytes()).unwrap(); } + +fn minify_js() { + use minifier::js::minify; + use std::io::Read; + let mut javascript = String::new(); + let source_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/menu.js")); + let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("menu.js"); + File::open(&source_path) + .expect("open templates/menu.js") + .read_to_string(&mut javascript) + .expect("read templates/menu.js"); + let javascript = minify(&javascript); + File::create(&dest_path) + .expect("create target/.../menu.js") + .write_all(javascript.as_bytes()) + .expect("write target/.../menu.js"); +} diff --git a/src/web/mod.rs b/src/web/mod.rs index 067acd30b..f73100163 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -72,6 +72,7 @@ use std::sync::{Arc, Mutex}; /// Duration of static files for staticfile and DatabaseFileHandler (in seconds) const STATIC_FILE_CACHE_DURATION: u64 = 60 * 60 * 24 * 30 * 12; // 12 months const STYLE_CSS: &'static str = include_str!(concat!(env!("OUT_DIR"), "/style.css")); +const MENU_JS: &'static str = include_str!(concat!(env!("OUT_DIR"), "/menu.js")); const OPENSEARCH_XML: &'static [u8] = include_bytes!("opensearch.xml"); const DEFAULT_BIND: &str = "0.0.0.0:3000"; @@ -426,6 +427,14 @@ fn style_css_handler(_: &mut Request) -> IronResult { Ok(response) } +fn menu_js_handler(_: &mut Request) -> IronResult { + let mut response = Response::with((status::Ok, MENU_JS)); + let cache = vec![CacheDirective::Public, + CacheDirective::MaxAge(STATIC_FILE_CACHE_DURATION as u32)]; + response.headers.set(ContentType("application/javascript".parse().unwrap())); + response.headers.set(CacheControl(cache)); + Ok(response) +} fn opensearch_xml_handler(_: &mut Request) -> IronResult { let mut response = Response::with((status::Ok, OPENSEARCH_XML)); diff --git a/src/web/routes.rs b/src/web/routes.rs index bef765fe2..8dcd90496 100644 --- a/src/web/routes.rs +++ b/src/web/routes.rs @@ -8,6 +8,7 @@ pub(super) fn build_routes() -> Routes { let mut routes = Routes::new(); routes.static_resource("/style.css", super::style_css_handler); + routes.static_resource("/menu.js", super::menu_js_handler); routes.static_resource("/robots.txt", super::sitemap::robots_txt_handler); routes.static_resource("/sitemap.xml", super::sitemap::sitemap_handler); routes.static_resource("/opensearch.xml", super::opensearch_xml_handler); diff --git a/templates/footer.hbs b/templates/footer.hbs index 80e55dc7d..7b38a379f 100644 --- a/templates/footer.hbs +++ b/templates/footer.hbs @@ -1,174 +1,4 @@ {{#if varsb.javascript_highlightjs}}{{/if}} - + diff --git a/templates/menu.js b/templates/menu.js new file mode 100644 index 000000000..51d4c6a67 --- /dev/null +++ b/templates/menu.js @@ -0,0 +1,171 @@ +// Allow menus to be open and used by keyboard. +(function() { + var currentMenu; + var backdrop = document.createElement("div"); + backdrop.style = "display:none;position:fixed;width:100%;height:100%;z-index:1;background:rgba(50, 50, 50, 0.5)"; + document.documentElement.insertBefore(backdrop, document.querySelector("body")); + function previous(allItems, item) { + var i = 1; + var l = allItems.length; + while (i < l) { + if (allItems[i] == item) { + return allItems[i - 1]; + } + i += 1; + } + } + function next(allItems, item) { + var i = 0; + var l = allItems.length - 1; + while (i < l) { + if (allItems[i] == item) { + return allItems[i + 1]; + } + i += 1; + } + } + function last(allItems) { + return allItems[allItems.length - 1]; + } + function closeMenu() { + currentMenu.className = currentMenu.className.replace("pure-menu-active", ""); + currentMenu = null; + backdrop.style.display = "none"; + } + backdrop.onclick = closeMenu; + function openMenu(newMenu) { + currentMenu = newMenu; + newMenu.className += " pure-menu-active"; + backdrop.style.display = "block"; + } + function menuOnClick(e) { + if (this.parentNode === currentMenu) { + closeMenu(); + } else { + if (currentMenu) closeMenu(); + openMenu(this.parentNode); + } + e.preventDefault(); + e.stopPropagation(); + }; + function menuMouseOver(e) { + if (currentMenu) { + if (e.target.className.indexOf("pure-menu-link") !== -1) { + e.target.focus(); + } + } + } + function menuKeyDown(e) { + if (currentMenu) { + var children = currentMenu.querySelector(".pure-menu-children"); + var currentLink = children.querySelector(".pure-menu-link:focus"); + var currentItem; + if (currentLink && currentLink.parentNode.className.indexOf("pure-menu-item") !== -1) { + currentItem = currentLink.parentNode; + } + var allItems = []; + if (children) { + allItems = children.querySelectorAll(".pure-menu-item .pure-menu-link"); + } + var switchTo = null; + switch (e.key.toLowerCase()) { + case "escape": + case "esc": + closeMenu(); + e.preventDefault(); + e.stopPropagation(); + return; + case "arrowdown": + case "down": + if (currentLink) { + // Arrow down when an item other than the last is focused: focus next item. + // Arrow down when the last item is focused: jump to top. + switchTo = (next(allItems, currentLink) || allItems[0]); + } else { + // Arrow down when a menu is open and nothing is focused: focus first item. + switchTo = allItems[0]; + } + break; + case "arrowup": + case "up": + if (currentLink) { + // Arrow up when an item other than the first is focused: focus previous item. + // Arrow up when the first item is focused: jump to bottom. + switchTo = (previous(allItems, currentLink) || last(allItems)); + } else { + // Arrow up when a menu is open and nothing is focused: focus last item. + switchTo = last(allItems); + } + break; + case "tab": + if (!currentLink) { + // if the menu is open, we should focus trap into it + // this is the behavior of the WAI example + // it is not the same as GitHub, but GitHub allows you to tab yourself out + // of the menu without closing it (which is horrible behavior) + switchTo = e.shiftKey ? last(allItems) : allItems[0]; + } else if (e.shiftKey && currentItem === allItems[0]) { + // if you tab your way out of the menu, close it + // this is neither what GitHub nor the WAI example do, + // but is a rationalization of GitHub's behavior: we don't want users who know how to + // use tab and enter, but don't know that they can close menus with Escape, + // to find themselves completely trapped in the menu + currentMenu.firstElementChild.focus(); + closeMenu(); + e.preventDefault(); + e.stopPropagation(); + } else if (!e.shiftKey && currentLink === last(allItems)) { + // same as above. + // if you tab your way out of the menu, close it + closeMenu(); + } + break; + case "enter": + case "return": + case "space": + // enter, return, and space have the default browser behavior, + // but they also close the menu + // this behavior is identical between both the WAI example, and GitHub's + setTimeout(function() { + closeMenu(); + }, 100); + break; + case "home": + // home: focus first menu item. + // This is the behavior of WAI, while GitHub scrolls, + // but it's unlikely that a user will try to scroll the page while the menu is open, + // so they won't do it on accident. + switchTo = allItems[0]; + break; + case "end": + // end: focus last menu item. + // This is the behavior of WAI, while GitHub scrolls, + // but it's unlikely that a user will try to scroll the page while the menu is open, + // so they won't do it on accident. + switchTo = last(allItems); + break; + } + if (switchTo) { + var switchToLink = switchTo.querySelector("a"); + if (switchToLink) { + switchToLink.focus(); + } else { + switchTo.focus(); + } + e.preventDefault(); + e.stopPropagation(); + } + } + }; + var menus = Array.prototype.slice.call(document.querySelectorAll(".pure-menu-has-children")); + var menusLength = menus.length; + var menu; + for (var i = 0; i < menusLength; ++i) { + menu = menus[i]; + menu.firstElementChild.setAttribute("aria-haspopup", "menu"); + menu.firstElementChild.nextElementSibling.setAttribute("role", "menu"); + menu.firstElementChild.addEventListener("click", menuOnClick); + menu.addEventListener("mouseover", menuMouseOver); + } + document.documentElement.addEventListener("keydown", menuKeyDown); +})(); From 1b76c49ee682ff3c24981c35fa19ded6aa87d114 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 13:04:26 -0700 Subject: [PATCH 03/13] Add script.js to the dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 427820604..87b88700b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,6 +47,7 @@ RUN touch build.rs COPY src src/ RUN find src -name "*.rs" -exec touch {} \; COPY templates/style.scss templates/ +COPY templates/menu.js templates/ RUN cargo build --release From 0f22eab66d70a29844af34325e2001a5eb65e394 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 13:17:42 -0700 Subject: [PATCH 04/13] Add menu.js to rustdoc template Apprently, the regular footer is not used by the rustdoc pages. --- templates/rustdoc.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/rustdoc.hbs b/templates/rustdoc.hbs index 600825d46..5cf0448d8 100644 --- a/templates/rustdoc.hbs +++ b/templates/rustdoc.hbs @@ -13,5 +13,6 @@
{{{content.rustdoc_body}}}
+ From 4dbf2f0ca7ec077a370b7fc49f3d84e11e508a0c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 14:29:13 -0700 Subject: [PATCH 05/13] Remove the gray background when the menu is open Based on feedback from multiple people. --- templates/menu.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/menu.js b/templates/menu.js index 51d4c6a67..e65147ac2 100644 --- a/templates/menu.js +++ b/templates/menu.js @@ -2,7 +2,7 @@ (function() { var currentMenu; var backdrop = document.createElement("div"); - backdrop.style = "display:none;position:fixed;width:100%;height:100%;z-index:1;background:rgba(50, 50, 50, 0.5)"; + backdrop.style = "display:none;position:fixed;width:100%;height:100%;z-index:1"; document.documentElement.insertBefore(backdrop, document.querySelector("body")); function previous(allItems, item) { var i = 1; @@ -104,7 +104,7 @@ // it is not the same as GitHub, but GitHub allows you to tab yourself out // of the menu without closing it (which is horrible behavior) switchTo = e.shiftKey ? last(allItems) : allItems[0]; - } else if (e.shiftKey && currentItem === allItems[0]) { + } else if (e.shiftKey && currentLink === allItems[0]) { // if you tab your way out of the menu, close it // this is neither what GitHub nor the WAI example do, // but is a rationalization of GitHub's behavior: we don't want users who know how to From 390c8e8080307edec981d62d583e06402a185b2d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 14:40:24 -0700 Subject: [PATCH 06/13] Add cache buster to JS includes --- templates/footer.hbs | 2 +- templates/rustdoc.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/footer.hbs b/templates/footer.hbs index 7b38a379f..fdde8e753 100644 --- a/templates/footer.hbs +++ b/templates/footer.hbs @@ -1,4 +1,4 @@ {{#if varsb.javascript_highlightjs}}{{/if}} - + diff --git a/templates/rustdoc.hbs b/templates/rustdoc.hbs index 5cf0448d8..373ef81dc 100644 --- a/templates/rustdoc.hbs +++ b/templates/rustdoc.hbs @@ -13,6 +13,6 @@
{{{content.rustdoc_body}}}
- + From fb236ac3c507d5e71d11899aab8b74d36452e729 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 15:15:54 -0700 Subject: [PATCH 07/13] Remove minifier It's not worth adding a dependency for it. --- Cargo.toml | 1 - build.rs | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dbb508098..62f9c00a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,6 @@ once_cell = "1.2.0" time = "0.1" git2 = "0.9" sass-rs = "0.2" -minifier = "^0.0.1" [[bin]] name = "cratesfyi" diff --git a/build.rs b/build.rs index 9c131423b..2e406aa78 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,6 @@ extern crate time; extern crate sass_rs; extern crate git2; -extern crate minifier; use std::env; use std::path::Path; @@ -14,7 +13,7 @@ use git2::Repository; fn main() { write_git_version(); compile_sass(); - minify_js(); + copy_js(); } @@ -52,8 +51,7 @@ fn compile_sass() { file.write_all(css.as_bytes()).unwrap(); } -fn minify_js() { - use minifier::js::minify; +fn copy_js() { use std::io::Read; let mut javascript = String::new(); let source_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/menu.js")); @@ -62,7 +60,6 @@ fn minify_js() { .expect("open templates/menu.js") .read_to_string(&mut javascript) .expect("read templates/menu.js"); - let javascript = minify(&javascript); File::create(&dest_path) .expect("create target/.../menu.js") .write_all(javascript.as_bytes()) From f71d708dbbbefe85b087c3b06f98f6f9ca78d571 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 16:14:13 -0700 Subject: [PATCH 08/13] Allow the user to open the Crate Page from the crate dropdown This fixes a regression added by the keyboard-accessible JavaScript menus, where clicking the link opened the menu instead of the linked page. It checks if the link points somewhere, and lets it behave normally if it does. Also adds keyboard handling for the space key, so you can still get to the menu. --- templates/menu.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/templates/menu.js b/templates/menu.js index e65147ac2..828db196c 100644 --- a/templates/menu.js +++ b/templates/menu.js @@ -39,6 +39,9 @@ backdrop.style.display = "block"; } function menuOnClick(e) { + if (this.getAttribute("href") != "#") { + return; + } if (this.parentNode === currentMenu) { closeMenu(); } else { @@ -123,6 +126,7 @@ case "enter": case "return": case "space": + case " ": // enter, return, and space have the default browser behavior, // but they also close the menu // this behavior is identical between both the WAI example, and GitHub's @@ -155,6 +159,17 @@ e.preventDefault(); e.stopPropagation(); } + } else if (e.target.parentNode.className && e.target.parentNode.className.indexOf("pure-menu-has-children") !== -1) { + switch (e.key.toLowerCase()) { + case "arrowdown": + case "down": + case "space": + case " ": + openMenu(e.target.parentNode); + e.preventDefault(); + e.stopPropagation(); + break; + } } }; var menus = Array.prototype.slice.call(document.querySelectorAll(".pure-menu-has-children")); From d195ea611d9739fc9509abc8b5c9595d980ec977 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 22 Jan 2020 16:42:00 -0700 Subject: [PATCH 09/13] Better focus behaviour on menu close If they click the backdrop, give focus to the rustdoc container, and otherwise give the focus to the menu button itself. --- templates/menu.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/templates/menu.js b/templates/menu.js index 828db196c..9f6e89e1e 100644 --- a/templates/menu.js +++ b/templates/menu.js @@ -28,6 +28,16 @@ return allItems[allItems.length - 1]; } function closeMenu() { + if (this === backdrop) { + var rustdoc = document.querySelector(".rustdoc"); + if (rustdoc) { + rustdoc.focus(); + } else { + document.documentElement.focus(); + } + } else if (currentMenu.querySelector(".pure-menu-link:focus")) { + currentMenu.firstElementChild.focus(); + } currentMenu.className = currentMenu.className.replace("pure-menu-active", ""); currentMenu = null; backdrop.style.display = "none"; @@ -113,7 +123,6 @@ // but is a rationalization of GitHub's behavior: we don't want users who know how to // use tab and enter, but don't know that they can close menus with Escape, // to find themselves completely trapped in the menu - currentMenu.firstElementChild.focus(); closeMenu(); e.preventDefault(); e.stopPropagation(); From 7bdcf29e1a00abd9241c71ddeb85a6b88522f4e8 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 24 Jan 2020 19:58:25 -0700 Subject: [PATCH 10/13] Allow pageup and pagedown to move the cursor --- templates/menu.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/templates/menu.js b/templates/menu.js index 9f6e89e1e..275e2921f 100644 --- a/templates/menu.js +++ b/templates/menu.js @@ -65,6 +65,10 @@ if (currentMenu) { if (e.target.className.indexOf("pure-menu-link") !== -1) { e.target.focus(); + if (e.target.parentNode.className.indexOf("pure-menu-has-children") !== -1 && e.target.parentNode !== currentMenu) { + closeMenu(); + openMenu(e.target.parentNode); + } } } } @@ -144,6 +148,7 @@ }, 100); break; case "home": + case "pageup": // home: focus first menu item. // This is the behavior of WAI, while GitHub scrolls, // but it's unlikely that a user will try to scroll the page while the menu is open, @@ -151,6 +156,7 @@ switchTo = allItems[0]; break; case "end": + case "pagedown": // end: focus last menu item. // This is the behavior of WAI, while GitHub scrolls, // but it's unlikely that a user will try to scroll the page while the menu is open, From deacc48f0b72c7b3a11db046605831603eec0fd6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 26 Jan 2020 20:41:59 -0700 Subject: [PATCH 11/13] Undo Cargo.lock changes --- Cargo.lock | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fba6b514f..0f23b5ecc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -327,7 +327,6 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "magic 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "minifier 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "params 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1063,11 +1062,6 @@ dependencies = [ "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "minifier" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "miniz-sys" version = "0.1.10" @@ -3020,7 +3014,6 @@ dependencies = [ "checksum mime 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "4b082692d3f6cf41b453af73839ce3dfc212c4411cbb2441dff80a716e38bd79" "checksum mime_guess 1.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2d4c0961143b8efdcfa29c3ae63281601b446a4a668165454b6c90f8024954c5" "checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed" -"checksum minifier 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16b1492b655977a6de47e262383c02de37873e8c7978986a52b0f9ee6c4ca39e" "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" "checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432" "checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" From bdf62ec2a7d2e622546e16ca27ce4ab0ac0875a8 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 28 Jan 2020 21:14:52 -0700 Subject: [PATCH 12/13] Use fs::copy instead of copying by hand --- build.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/build.rs b/build.rs index 2e406aa78..9b6a1a68d 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,7 @@ extern crate git2; use std::env; use std::path::Path; -use std::fs::File; +use std::fs::{self, File}; use std::io::Write; use git2::Repository; @@ -60,8 +60,5 @@ fn copy_js() { .expect("open templates/menu.js") .read_to_string(&mut javascript) .expect("read templates/menu.js"); - File::create(&dest_path) - .expect("create target/.../menu.js") - .write_all(javascript.as_bytes()) - .expect("write target/.../menu.js"); + fs::copy(&source_path, &dest_path).expect("copy template/menu.js to target"); } From 96747c0b1983f502f60ccbc61a1563b40dd3b807 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 28 Jan 2020 22:32:40 -0700 Subject: [PATCH 13/13] Remove pointless file read --- build.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build.rs b/build.rs index 9b6a1a68d..cc39efb5d 100644 --- a/build.rs +++ b/build.rs @@ -52,13 +52,7 @@ fn compile_sass() { } fn copy_js() { - use std::io::Read; - let mut javascript = String::new(); let source_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/menu.js")); let dest_path = Path::new(&env::var("OUT_DIR").unwrap()).join("menu.js"); - File::open(&source_path) - .expect("open templates/menu.js") - .read_to_string(&mut javascript) - .expect("read templates/menu.js"); fs::copy(&source_path, &dest_path).expect("copy template/menu.js to target"); }