-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #26216 - azerupi:doc-experiments, r=steveklabnik
So I have tried to improve the rustbook engine: - The sidebar now looks a lot more like gitbook (I thinks it cleaner) - Added the Open Sans font, in my opinion more readable for prolonged periods of time - Changed the style for code blocks a little I encountered 1 problem. In `build.rs` I added this google font url (I commented out the non-relevant parts for clarity) ```rust let rustdoc_args: &[String] = &[ //"".to_string(), //preprocessed_path.display().to_string(), //format!("-o{}", out_path.display()), //format!("--html-before-content={}", prelude.display()), //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(), ]; ``` As you can see, I had to escape `=` with `=` because the string would get truncated if I didn't. Is that normal behaviour? Is that for security measures? If it is, isn't it a little weak if you can circumvent it by escaped characters? I don't know the reason behind, but I thought it was at least worth mentioning :) Take your time for this PR, I still want to add multiple improvements: - Like gitbook, possibility to change font by user - Put `css` and `js` in their respective files (not hardcoded in rust) - button to hide sidebar - ... So I'm not in a hurry to get this merged ;) But if you think it's good enough to be merged, go ahead. I will make another PR when I have other improvements. In the image below is a screen of the improvements ![rustbook](https://cloud.githubusercontent.com/assets/7647338/8105345/bf545c74-1038-11e5-962e-b04ebfaf8257.png)
- Loading branch information
Showing
5 changed files
with
135 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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; | ||
|
||
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'); | ||
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; | ||
} | ||
} | ||
|
||
}); |