Add active class to currently viewed chapter in the sidebar. Closes #20
This commit is contained in:
parent
1a8c2259e5
commit
31f638eae3
|
@ -14,7 +14,7 @@
|
|||
<body>
|
||||
|
||||
<div id="sidebar" class="sidebar">
|
||||
<ul class="chapter"><li><a href="README.html"><strong>1.</strong> mdBook</a></li><li><a href="cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
<ul class="chapter"><li><a href="README.html"class="active"><strong>1.</strong> mdBook</a></li><li><a href="cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
</div>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<body>
|
||||
|
||||
<div id="sidebar" class="sidebar">
|
||||
<ul class="chapter"><li><a href="../README.html"><strong>1.</strong> mdBook</a></li><li><a href="../cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="../cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="../cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
<ul class="chapter"><li><a href="../README.html"><strong>1.</strong> mdBook</a></li><li><a href="../cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="../cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="../cli/build.html"class="active"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
</div>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<body>
|
||||
|
||||
<div id="sidebar" class="sidebar">
|
||||
<ul class="chapter"><li><a href="../README.html"><strong>1.</strong> mdBook</a></li><li><a href="../cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="../cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="../cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
<ul class="chapter"><li><a href="../README.html"><strong>1.</strong> mdBook</a></li><li><a href="../cli/cli-tool.html"class="active"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="../cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="../cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
</div>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<body>
|
||||
|
||||
<div id="sidebar" class="sidebar">
|
||||
<ul class="chapter"><li><a href="../README.html"><strong>1.</strong> mdBook</a></li><li><a href="../cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="../cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="../cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
<ul class="chapter"><li><a href="../README.html"><strong>1.</strong> mdBook</a></li><li><a href="../cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="../cli/init.html"class="active"><strong>2.1.</strong> init</a></li><li><a href="../cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
</div>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<body>
|
||||
|
||||
<div id="sidebar" class="sidebar">
|
||||
<ul class="chapter"><li><a href="README.html"><strong>1.</strong> mdBook</a></li><li><a href="cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
<ul class="chapter"><li><a href="README.html"class="active"><strong>1.</strong> mdBook</a></li><li><a href="cli/cli-tool.html"><strong>2.</strong> Command Line Tool</a></li><li><ul class="section"><li><a href="cli/init.html"><strong>2.1.</strong> init</a></li><li><a href="cli/build.html"><strong>2.2.</strong> build</a></li></ul><li><strong>3.</strong> Format</li><li><ul class="section"><li><strong>3.1.</strong> SUMMARY.md</li></ul><li><strong>4.</strong> Rust Library</li></ul>
|
||||
</div>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
|
|
@ -18,6 +18,7 @@ impl HelperDef for RenderToc {
|
|||
// rc.get_path() is current json parent path, you should always use it like this
|
||||
// param is the key of value you want to display
|
||||
let chapters = c.navigate(rc.get_path(), "chapters");
|
||||
let current = c.navigate(rc.get_path(), "path").to_string().replace("\"", "");
|
||||
let path_to_root = c.navigate(rc.get_path(), "path_to_root").to_string().replace("\"", "");
|
||||
try!(rc.writer.write("<ul class=\"chapter\">".as_bytes()));
|
||||
|
||||
|
@ -58,7 +59,14 @@ impl HelperDef for RenderToc {
|
|||
.to_str().unwrap().as_bytes()
|
||||
));
|
||||
|
||||
try!(rc.writer.write("\">".as_bytes()));
|
||||
try!(rc.writer.write("\"".as_bytes()));
|
||||
|
||||
println!("[DEBUG] path: {}\n current: {}", path, ¤t);
|
||||
if path == ¤t {
|
||||
try!(rc.writer.write("class=\"active\"".as_bytes()));
|
||||
}
|
||||
|
||||
try!(rc.writer.write(">".as_bytes()));
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -53,6 +53,10 @@ impl Renderer for HtmlHandlebars {
|
|||
// Render markdown using the pulldown-cmark crate
|
||||
content = render_html(&content);
|
||||
|
||||
// Remove content from previous file and render content for this one
|
||||
data.remove("path");
|
||||
data.insert("path".to_string(), item.path.to_str().unwrap().to_json());
|
||||
|
||||
// Remove content from previous file and render content for this one
|
||||
data.remove("content");
|
||||
data.insert("content".to_string(), content.to_json());
|
||||
|
@ -169,25 +173,6 @@ fn create_file(working_directory: &Path, path: &Path) -> Result<File, Box<Error>
|
|||
|
||||
fn make_data(book: BookItems, config: &BookConfig) -> Result<BTreeMap<String,Json>, Box<Error>> {
|
||||
|
||||
/*
|
||||
Function to make the JSon data for the handlebars template:
|
||||
|
||||
{
|
||||
"language": ...,
|
||||
"title": ...
|
||||
"chapters": [
|
||||
{
|
||||
"section": section,
|
||||
"chapter": BookItem,
|
||||
},
|
||||
{
|
||||
...
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
let mut data = BTreeMap::new();
|
||||
data.insert("language".to_string(), "en".to_json());
|
||||
data.insert("title".to_string(), config.title.to_json());
|
||||
|
|
Loading…
Reference in New Issue