Search: Add handlebars variable and do not load js libraries if search is disabled.

This commit is contained in:
Phaiax 2017-11-26 19:52:59 +01:00
parent 0ad8535084
commit 592fb17c70
2 changed files with 9 additions and 1 deletions

View File

@ -413,6 +413,8 @@ fn make_data(book: &MDBook, config: &Config) -> Result<serde_json::Map<String, s
json!("theme-tomorrow_night.js")); json!("theme-tomorrow_night.js"));
} }
data.insert("search".to_owned(), json!(html.search.enable));
let mut chapters = vec![]; let mut chapters = vec![];
for item in book.iter() { for item in book.iter() {

View File

@ -48,6 +48,7 @@
} }
</script> </script>
{{#if search}}
<!-- Fetch elasticlunr.js from CDN but have a local fallback --> <!-- Fetch elasticlunr.js from CDN but have a local fallback -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.6/elasticlunr.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.6/elasticlunr.min.js"></script>
<script> <script>
@ -63,6 +64,7 @@
document.write(unescape("%3Cscript src='jquery.mark.min.js'%3E%3C/script%3E")); document.write(unescape("%3Cscript src='jquery.mark.min.js'%3E%3C/script%3E"));
} }
</script> </script>
{{/if}}
<!-- Fetch store.js from local - TODO add CDN when 2.x.x is available on cdnjs --> <!-- Fetch store.js from local - TODO add CDN when 2.x.x is available on cdnjs -->
<script src="store.js"></script> <script src="store.js"></script>
@ -94,7 +96,9 @@
<div class="left-buttons"> <div class="left-buttons">
<i id="sidebar-toggle" class="fa fa-bars" title="Toggle sidebar"></i> <i id="sidebar-toggle" class="fa fa-bars" title="Toggle sidebar"></i>
<i id="theme-toggle" class="fa fa-paint-brush" title="Change theme"></i> <i id="theme-toggle" class="fa fa-paint-brush" title="Change theme"></i>
<i id="search-icon" class="fa fa-search" title="Search!"></i> {{#if search}}
<i id="search-icon" class="fa fa-search" title="Search. (Shortkey: s)"></i>
{{/if}}
</div> </div>
<h1 class="menu-title">{{ book_title }}</h1> <h1 class="menu-title">{{ book_title }}</h1>
@ -106,6 +110,7 @@
</div> </div>
</div> </div>
{{#if search}}
<div id="searchbar-outer" class="searchbar-outer"> <div id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..."> <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ...">
@ -115,6 +120,7 @@
</ul> </ul>
</div> </div>
</div> </div>
{{/if}}
<div id="content" class="content"> <div id="content" class="content">