From 0d41764d99bf5507d17105fd2f4f7a30c2c7e7a1 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 11 Jun 2015 12:48:10 +0200 Subject: [PATCH 1/6] Some love for the rustbook, added Open Sans font, made the sidebar more beautiful with more space and colors, added some style to the code blocks --- src/rustbook/build.rs | 1 + src/rustbook/css.rs | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index a7a6ed3bfe7..dc97d1e2434 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -145,6 +145,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { format!("--html-after-content={}", postlude.display()), format!("--markdown-playground-url=http://play.rust-lang.org"), format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()), + format!("--markdown-css=http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700"), "--markdown-no-toc".to_string(), ]; let output_result = rustdoc::main_args(rustdoc_args); diff --git a/src/rustbook/css.rs b/src/rustbook/css.rs index aae5f21a73d..33517e7cf64 100644 --- a/src/rustbook/css.rs +++ b/src/rustbook/css.rs @@ -15,6 +15,15 @@ pub static STYLE: &'static str = r#" body { max-width:none; + font: 16px/1.4 'Open Sans', 'Source Serif Pro', Georgia, Times, 'Times New Roman', serif; + line-height: 1.6; + color: #333; +} + +h1, h2, h3, h4, h5, h6 { + font-family: 'Open Sans', 'Fira Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-weight: bold; + color: #333; } @media only screen { @@ -23,20 +32,21 @@ body { left: 0px; top: 0px; bottom: 0px; - width: 250px; + width: 300px; overflow-y: auto; border-right: 1px solid rgba(0, 0, 0, 0.07); padding: 10px 10px; - font-size: 16px; - background: none repeat scroll 0% 0% #FFF; + font-size: 14px; box-sizing: border-box; -webkit-overflow-scrolling: touch; + background-color: #fafafa; + color: #364149; } #page-wrapper { position: absolute; overflow-y: auto; - left: 260px; + left: 310px; right: 0px; top: 0px; bottom: 0px; @@ -84,7 +94,7 @@ body { .section { list-style: none outside none; padding-left: 20px; - line-height: 30px; + line-height: 40px; } .section li { @@ -94,12 +104,17 @@ body { } .chapter li a { - color: #000000; + color: #333; + padding: 5px 0; } .chapter li a.active { - text-decoration: underline; - font-weight: bold; + color: #008cff; +} + +.chapter li a:hover { + color: #008cff; + text-decoration: none; } #toggle-nav { @@ -138,6 +153,16 @@ body { padding: 0; } +pre { + padding: 16px; + overflow: auto; + font-size: 85%; + line-height: 1.45; + background-color: #f7f7f7; + border: 0; + border-radius: 3px; +} + .left { float: left; } From f862575feb0c54966ce7ea363603519c03faa4f7 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 11 Jun 2015 13:31:25 +0200 Subject: [PATCH 2/6] Fixed line longer than 100 chars --- src/rustbook/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index dc97d1e2434..69ef20884f4 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -145,7 +145,8 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { format!("--html-after-content={}", postlude.display()), format!("--markdown-playground-url=http://play.rust-lang.org"), format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()), - format!("--markdown-css=http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700"), + format!("--markdown-css={}", + "http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700"), "--markdown-no-toc".to_string(), ]; let output_result = rustdoc::main_args(rustdoc_args); From 98633de498f9dc7132eed2dddf1c9acf997f18f3 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 11 Jun 2015 21:50:34 +0200 Subject: [PATCH 3/6] Add class to last paragraph that contains next and previous navigation links to add bigger margin --- src/rustbook/css.rs | 4 ++++ src/rustbook/javascript.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/rustbook/css.rs b/src/rustbook/css.rs index 33517e7cf64..11d8a034c60 100644 --- a/src/rustbook/css.rs +++ b/src/rustbook/css.rs @@ -163,6 +163,10 @@ pre { border-radius: 3px; } +.nav-previous-next { + margin-top: 60px; +} + .left { float: left; } diff --git a/src/rustbook/javascript.rs b/src/rustbook/javascript.rs index f33b79cc188..69124372260 100644 --- a/src/rustbook/javascript.rs +++ b/src/rustbook/javascript.rs @@ -54,6 +54,7 @@ document.addEventListener("DOMContentLoaded", function(event) { 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'; From 6709685377487475c2911af3d996650553339685 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Fri, 12 Jun 2015 11:32:25 +0200 Subject: [PATCH 4/6] separate css and js from rust --- src/rustbook/build.rs | 18 ++++-- src/rustbook/javascript.rs | 62 +------------------- src/rustbook/main.rs | 1 - src/rustbook/{css.rs => static/rustbook.css} | 16 +---- src/rustbook/static/rustbook.js | 60 +++++++++++++++++++ 5 files changed, 75 insertions(+), 82 deletions(-) rename src/rustbook/{css.rs => static/rustbook.css} (83%) create mode 100644 src/rustbook/static/rustbook.js diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index 69ef20884f4..afae4276507 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -22,7 +22,7 @@ use term::Term; use error::{err, CliResult, CommandResult}; use book; use book::{Book, BookItem}; -use css; + use javascript; use rustdoc; @@ -146,7 +146,8 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { format!("--markdown-playground-url=http://play.rust-lang.org"), format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()), format!("--markdown-css={}", - "http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700"), + "http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700" + ), "--markdown-no-toc".to_string(), ]; let output_result = rustdoc::main_args(rustdoc_args); @@ -197,9 +198,16 @@ impl Subcommand for Build { } try!(fs::create_dir(&tgt)); - try!(File::create(&tgt.join("rust-book.css")).and_then(|mut f| { - f.write_all(css::STYLE.as_bytes()) - })); + // 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 mut summary = try!(File::open(&src.join("SUMMARY.md"))); match book::parse_summary(&mut summary, &src) { diff --git a/src/rustbook/javascript.rs b/src/rustbook/javascript.rs index 69124372260..beddc23fe2b 100644 --- a/src/rustbook/javascript.rs +++ b/src/rustbook/javascript.rs @@ -11,66 +11,6 @@ // The rust-book JavaScript in string form. pub static JAVASCRIPT: &'static str = r#" - + "#; diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs index acb1c5cbd90..81f8c8c40fd 100644 --- a/src/rustbook/main.rs +++ b/src/rustbook/main.rs @@ -35,7 +35,6 @@ mod build; mod serve; mod test; -mod css; mod javascript; static EXIT_STATUS: AtomicIsize = ATOMIC_ISIZE_INIT; diff --git a/src/rustbook/css.rs b/src/rustbook/static/rustbook.css similarity index 83% rename from src/rustbook/css.rs rename to src/rustbook/static/rustbook.css index 11d8a034c60..955f4ab3817 100644 --- a/src/rustbook/css.rs +++ b/src/rustbook/static/rustbook.css @@ -1,16 +1,3 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// The rust-book CSS in string form. - -pub static STYLE: &'static str = r#" @import url("../rust.css"); body { @@ -57,7 +44,7 @@ h1, h2, h3, h4, h5, h6 { } @media only print { - #toc, #nav { + #toc, #nav, #menu-bar { display: none; } } @@ -174,4 +161,3 @@ pre { .right { float: right; } -"#; diff --git a/src/rustbook/static/rustbook.js b/src/rustbook/static/rustbook.js new file mode 100644 index 00000000000..af4e2a80a38 --- /dev/null +++ b/src/rustbook/static/rustbook.js @@ -0,0 +1,60 @@ +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"); + } + + 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); + + if (existingIndex >= 0) { + classes.splice(existingIndex, 1); + } else { + classes.push(className); + } + + 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; + } + } + +}); From 8da9f0643f92f88b09d06497db7e92cde2a9c9e7 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Fri, 12 Jun 2015 11:43:58 +0200 Subject: [PATCH 5/6] Fix license --- src/rustbook/static/rustbook.css | 12 ++++++++++++ src/rustbook/static/rustbook.js | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/rustbook/static/rustbook.css b/src/rustbook/static/rustbook.css index 955f4ab3817..0071fb25eeb 100644 --- a/src/rustbook/static/rustbook.css +++ b/src/rustbook/static/rustbook.css @@ -1,3 +1,15 @@ +/** + * Copyright 2013 The Rust Project Developers. See the COPYRIGHT + * file at the top-level directory of this distribution and at + * http://rust-lang.org/COPYRIGHT. + * + * Licensed under the Apache License, Version 2.0 or the MIT license + * , at your + * option. This file may not be copied, modified, or distributed + * except according to those terms. + */ + @import url("../rust.css"); body { diff --git a/src/rustbook/static/rustbook.js b/src/rustbook/static/rustbook.js index af4e2a80a38..ef96448a5d3 100644 --- a/src/rustbook/static/rustbook.js +++ b/src/rustbook/static/rustbook.js @@ -1,3 +1,13 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// 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; From 003c3eaa62981b791f9eb7bcad015baa1e00d98c Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 25 Jun 2015 11:11:06 +0200 Subject: [PATCH 6/6] removed open sans font --- src/rustbook/build.rs | 3 --- src/rustbook/static/rustbook.css | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index afae4276507..8152ea530d5 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -145,9 +145,6 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { format!("--html-after-content={}", postlude.display()), format!("--markdown-playground-url=http://play.rust-lang.org"), format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()), - format!("--markdown-css={}", - "http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700" - ), "--markdown-no-toc".to_string(), ]; let output_result = rustdoc::main_args(rustdoc_args); diff --git a/src/rustbook/static/rustbook.css b/src/rustbook/static/rustbook.css index 0071fb25eeb..3e0537c5551 100644 --- a/src/rustbook/static/rustbook.css +++ b/src/rustbook/static/rustbook.css @@ -14,7 +14,7 @@ body { max-width:none; - font: 16px/1.4 'Open Sans', 'Source Serif Pro', Georgia, Times, 'Times New Roman', serif; + font: 16px/1.4 'Source Serif Pro', Georgia, Times, 'Times New Roman', serif; line-height: 1.6; color: #333; }