about summary refs log tree commit diff
path: root/src/rustbook
diff options
context:
space:
mode:
authorMathieu David <mathieudavid@mathieudavid.org>2015-07-27 20:46:01 +0200
committerMathieu David <mathieudavid@mathieudavid.org>2015-07-27 20:46:01 +0200
commitf6e9240a99e86d2c799dc29f179dd2870e51f71d (patch)
treea7e5ba20745b16949a45a4612b2708e262693a7b /src/rustbook
parent003c3eaa62981b791f9eb7bcad015baa1e00d98c (diff)
parent3351afeecffcc9ebaeb1188a5cde976da8e4a5aa (diff)
Fix the relative path issue by including the files using include_bytes!
Diffstat (limited to 'src/rustbook')
-rw-r--r--src/rustbook/build.rs18
-rw-r--r--src/rustbook/static/rustbook.js103
2 files changed, 62 insertions, 59 deletions
diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs
index 8152ea530d5..3ac71c167cd 100644
--- a/src/rustbook/build.rs
+++ b/src/rustbook/build.rs
@@ -196,15 +196,15 @@ impl Subcommand for Build {
         try!(fs::create_dir(&tgt));
 
         // Copy static files
-        try!(fs::copy(
-            &cwd.join("src/rustbook/static/rustbook.css"),
-            &tgt.join("rust-book.css")
-        ));
-
-        try!(fs::copy(
-            &cwd.join("src/rustbook/static/rustbook.js"),
-            &tgt.join("rust-book.js")
-        ));
+        let css = include_bytes!("static/rustbook.css");
+        let js = include_bytes!("static/rustbook.js");
+
+        let mut css_file = try!(File::create(tgt.join("rust-book.css")));
+        try!(css_file.write_all(css));
+
+        let mut js_file = try!(File::create(tgt.join("rust-book.js")));
+        try!(js_file.write_all(js));
+
 
         let mut summary = try!(File::open(&src.join("SUMMARY.md")));
         match book::parse_summary(&mut summary, &src) {
diff --git a/src/rustbook/static/rustbook.js b/src/rustbook/static/rustbook.js
index ef96448a5d3..fdefab28759 100644
--- a/src/rustbook/static/rustbook.js
+++ b/src/rustbook/static/rustbook.js
@@ -8,63 +8,66 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+
 document.addEventListener("DOMContentLoaded", function(event) {
 
-    document.getElementById("toggle-nav").onclick = toggleNav;
-    function toggleNav() {
-        var toc = document.getElementById("toc");
-        var pagewrapper = document.getElementById("page-wrapper");
-        toggleClass(toc, "mobile-hidden");
-        toggleClass(pagewrapper, "mobile-hidden");
-    }
+  document.getElementById("toggle-nav").onclick = toggleNav;
 
-    function toggleClass(el, className) {
-        // from http://youmightnotneedjquery.com/
-        if (el.classList) {
-            el.classList.toggle(className);
-        } else {
-            var classes = el.className.split(' ');
-            var existingIndex = classes.indexOf(className);
+  function toggleNav() {
+    var toc = document.getElementById("toc");
+    var pagewrapper = document.getElementById("page-wrapper");
+    toggleClass(toc, "mobile-hidden");
+    toggleClass(pagewrapper, "mobile-hidden");
+  }
 
-            if (existingIndex >= 0) {
-                classes.splice(existingIndex, 1);
-            } else {
-                classes.push(className);
-            }
+  function toggleClass(el, className) {
+     // from http://youmightnotneedjquery.com/
+     if (el.classList) {
+       el.classList.toggle(className);
+     } else {
+       var classes = el.className.split(' ');
+       var existingIndex = classes.indexOf(className);
 
-            el.className = classes.join(' ');
-        }
-    }
+       if (existingIndex >= 0) {
+         classes.splice(existingIndex, 1);
+       } else {
+         classes.push(className);
+       }
 
-    // The below code is used to add prev and next navigation links to the bottom
-    // of each of the sections.
-    // It works by extracting the current page based on the url and iterates over
-    // the menu links until it finds the menu item for the current page. We then
-    // create a copy of the preceding and following menu links and add the
-    // correct css class and insert them into the bottom of the page.
-    var toc = document.getElementById('toc').getElementsByTagName('a');
-    var href = document.location.pathname.split('/').pop();
-    if (href === 'index.html' || href === '') {
-        href = 'README.html';
-    }
+       el.className = classes.join(' ');
+     }
+  }
+
+  // The below code is used to add prev and next navigation links to the bottom
+  // of each of the sections.
+  // It works by extracting the current page based on the url and iterates over
+  // the menu links until it finds the menu item for the current page. We then
+  // create a copy of the preceding and following menu links and add the
+  // correct css class and insert them into the bottom of the page.
+  var toc = document.getElementById('toc').getElementsByTagName('a');
+  var href = document.location.pathname.split('/').pop();
+  if (href === 'index.html' || href === '') {
+    href = 'README.html';
+  }
 
-    for (var i = 0; i < toc.length; i++) {
-        if (toc[i].attributes['href'].value.split('/').pop() === href) {
-            var nav = document.createElement('p');
-            nav.className = 'nav-previous-next';
-            if (i > 0) {
-                var prevNode = toc[i-1].cloneNode(true);
-                prevNode.className = 'left';
-                nav.appendChild(prevNode);
-            }
-            if (i < toc.length - 1) {
-                var nextNode = toc[i+1].cloneNode(true);
-                nextNode.className = 'right';
-                nav.appendChild(nextNode);
-            }
-            document.getElementById('page').appendChild(nav);
-            break;
-        }
+  for (var i = 0; i < toc.length; i++) {
+    if (toc[i].attributes.href.value.split('/').pop() === href) {
+      var nav = document.createElement('p');
+      if (i > 0) {
+        var prevNode = toc[i-1].cloneNode(true);
+        prevNode.className = 'left';
+        prevNode.setAttribute('rel', 'prev');
+        nav.appendChild(prevNode);
+      }
+      if (i < toc.length - 1) {
+        var nextNode = toc[i+1].cloneNode(true);
+        nextNode.className = 'right';
+        nextNode.setAttribute('rel', 'next');
+        nav.appendChild(nextNode);
+      }
+      document.getElementById('page').appendChild(nav);
+      break;
     }
+  }
 
 });