From 8cd7061ff28e6fd8d8588a63b8d7a64f060fdfca Mon Sep 17 00:00:00 2001 From: Matt Ickstadt Date: Wed, 13 Jun 2018 13:11:25 -0500 Subject: [PATCH] Add search.enable config field --- book-example/src/format/config.md | 2 ++ src/config.rs | 5 ++++- src/renderer/html_handlebars/hbs_renderer.rs | 13 +++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/book-example/src/format/config.md b/book-example/src/format/config.md index 96da0e74..4c65f553 100644 --- a/book-example/src/format/config.md +++ b/book-example/src/format/config.md @@ -113,6 +113,7 @@ Available configuration options for the `[output.html.playpen]` table: Available configuration options for the `[output.html.search]` table: +- **enable:** Enables the search feature. Defaults to `true`. - **limit-results:** The maximum number of search results. Defaults to `30`. - **teaser-word-count:** The number of words used for a search result teaser. Defaults to `30`. @@ -168,6 +169,7 @@ boost-hierarchy = 1 boost-paragraph = 1 expand = true heading-split-level = 3 +copy-js = true ``` diff --git a/src/config.rs b/src/config.rs index 898ec6b7..2e0ec51a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -463,9 +463,11 @@ impl Default for Playpen { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(default, rename_all = "kebab-case")] pub struct Search { + /// Enable the search feature. Default: `true`. + pub enable: bool, /// Maximum number of visible results. Default: `30`. pub limit_results: u32, - /// The number of words used for a search result teaser. Default: `30`, + /// The number of words used for a search result teaser. Default: `30`. pub teaser_word_count: u32, /// Define the logical link between multiple search words. /// If true, all search words must appear in each result. Default: `true`. @@ -494,6 +496,7 @@ impl Default for Search { fn default() -> Search { // Please update the documentation of `Search` when changing values! Search { + enable: true, limit_results: 30, teaser_word_count: 30, use_boolean_and: false, diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 4fad1eef..52e58f81 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -367,8 +367,10 @@ impl Renderer for HtmlHandlebars { .chain_err(|| "Unable to copy across additional CSS and JS")?; // Render search index - #[cfg(feature = "search")] - super::search::create_files(&html_config.search.unwrap_or_default(), &destination, &book)?; + let search = html_config.search.unwrap_or_default(); + if cfg!(feature = "search") && search.enable { + super::search::create_files(&search, &destination, &book)?; + } // Copy all remaining files utils::fs::copy_files_except_ext(&src_dir, &destination, true, &["md"])?; @@ -446,10 +448,9 @@ fn make_data( let search = html_config.search.clone(); if cfg!(feature = "search") { - data.insert("search_enabled".to_owned(), json!(true)); - if search.unwrap_or_default().copy_js { - data.insert("search_js".to_owned(), json!(true)); - } + let search = search.unwrap_or_default(); + data.insert("search_enabled".to_owned(), json!(search.enable)); + data.insert("search_js".to_owned(), json!(search.copy_js)); } else if search.is_some() { warn!("mdBook compiled without search support, ignoring `output.html.search` table"); warn!(