Add search.enable config field
This commit is contained in:
parent
96b99472fd
commit
8cd7061ff2
|
@ -113,6 +113,7 @@ Available configuration options for the `[output.html.playpen]` table:
|
||||||
|
|
||||||
Available configuration options for the `[output.html.search]` 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`.
|
- **limit-results:** The maximum number of search results. Defaults to `30`.
|
||||||
- **teaser-word-count:** The number of words used for a search result teaser.
|
- **teaser-word-count:** The number of words used for a search result teaser.
|
||||||
Defaults to `30`.
|
Defaults to `30`.
|
||||||
|
@ -168,6 +169,7 @@ boost-hierarchy = 1
|
||||||
boost-paragraph = 1
|
boost-paragraph = 1
|
||||||
expand = true
|
expand = true
|
||||||
heading-split-level = 3
|
heading-split-level = 3
|
||||||
|
copy-js = true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -463,9 +463,11 @@ impl Default for Playpen {
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(default, rename_all = "kebab-case")]
|
#[serde(default, rename_all = "kebab-case")]
|
||||||
pub struct Search {
|
pub struct Search {
|
||||||
|
/// Enable the search feature. Default: `true`.
|
||||||
|
pub enable: bool,
|
||||||
/// Maximum number of visible results. Default: `30`.
|
/// Maximum number of visible results. Default: `30`.
|
||||||
pub limit_results: u32,
|
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,
|
pub teaser_word_count: u32,
|
||||||
/// Define the logical link between multiple search words.
|
/// Define the logical link between multiple search words.
|
||||||
/// If true, all search words must appear in each result. Default: `true`.
|
/// If true, all search words must appear in each result. Default: `true`.
|
||||||
|
@ -494,6 +496,7 @@ impl Default for Search {
|
||||||
fn default() -> Search {
|
fn default() -> Search {
|
||||||
// Please update the documentation of `Search` when changing values!
|
// Please update the documentation of `Search` when changing values!
|
||||||
Search {
|
Search {
|
||||||
|
enable: true,
|
||||||
limit_results: 30,
|
limit_results: 30,
|
||||||
teaser_word_count: 30,
|
teaser_word_count: 30,
|
||||||
use_boolean_and: false,
|
use_boolean_and: false,
|
||||||
|
|
|
@ -367,8 +367,10 @@ impl Renderer for HtmlHandlebars {
|
||||||
.chain_err(|| "Unable to copy across additional CSS and JS")?;
|
.chain_err(|| "Unable to copy across additional CSS and JS")?;
|
||||||
|
|
||||||
// Render search index
|
// Render search index
|
||||||
#[cfg(feature = "search")]
|
let search = html_config.search.unwrap_or_default();
|
||||||
super::search::create_files(&html_config.search.unwrap_or_default(), &destination, &book)?;
|
if cfg!(feature = "search") && search.enable {
|
||||||
|
super::search::create_files(&search, &destination, &book)?;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy all remaining files
|
// Copy all remaining files
|
||||||
utils::fs::copy_files_except_ext(&src_dir, &destination, true, &["md"])?;
|
utils::fs::copy_files_except_ext(&src_dir, &destination, true, &["md"])?;
|
||||||
|
@ -446,10 +448,9 @@ fn make_data(
|
||||||
|
|
||||||
let search = html_config.search.clone();
|
let search = html_config.search.clone();
|
||||||
if cfg!(feature = "search") {
|
if cfg!(feature = "search") {
|
||||||
data.insert("search_enabled".to_owned(), json!(true));
|
let search = search.unwrap_or_default();
|
||||||
if search.unwrap_or_default().copy_js {
|
data.insert("search_enabled".to_owned(), json!(search.enable));
|
||||||
data.insert("search_js".to_owned(), json!(true));
|
data.insert("search_js".to_owned(), json!(search.copy_js));
|
||||||
}
|
|
||||||
} else if search.is_some() {
|
} else if search.is_some() {
|
||||||
warn!("mdBook compiled without search support, ignoring `output.html.search` table");
|
warn!("mdBook compiled without search support, ignoring `output.html.search` table");
|
||||||
warn!(
|
warn!(
|
||||||
|
|
Loading…
Reference in New Issue