Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add elasticlunr prefix to search engine format configuration
Browse files Browse the repository at this point in the history
This will be useful if support for more search libraries are added in the future
sgued committed Oct 30, 2022

Verified

This commit was signed with the committer’s verified signature.
Eliulm Elias Wahl
1 parent 0de053b commit c716bfc
Showing 5 changed files with 10 additions and 11 deletions.
9 changes: 4 additions & 5 deletions components/config/src/config/search.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum IndexFormat {
#[serde(rename = "json")]
Json,
#[serde(rename = "javascript")]
Javascript,
ElasticlunrJson,
ElasticlunrJavascript,
}

impl Default for IndexFormat {
fn default() -> IndexFormat {
IndexFormat::Javascript
IndexFormat::ElasticlunrJavascript
}
}

4 changes: 2 additions & 2 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
@@ -771,11 +771,11 @@ impl Site {
&self.config,
)?;
let (path, content) = match &self.config.search.index_format {
IndexFormat::Json => {
IndexFormat::ElasticlunrJson => {
let path = self.output_path.join(&format!("search_index.{}.json", lang));
(path, index_json)
}
IndexFormat::Javascript => {
IndexFormat::ElasticlunrJavascript => {
let path = self.output_path.join(&format!("search_index.{}.js", lang));
let content = format!("window.searchIndex = {};", index_json);
(path, content)
2 changes: 1 addition & 1 deletion docs/config.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ compile_sass = true
build_search_index = true

[search]
index_format = "json"
index_format = "elasticlunr_json"

[markdown]
highlight_code = true
2 changes: 1 addition & 1 deletion docs/content/documentation/content/search.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ After `zola build` or `zola serve`, you should see two files in your public dire
- `search_index.${default_language}.js`: so `search_index.en.js` for a default setup
- `elasticlunr.min.js`

If you set `index_format = "json"` in your `config.toml`, a `search_index.${default_language}.json` is generated
If you set `index_format = "elasticlunr_json"` in your `config.toml`, a `search_index.${default_language}.json` is generated
instead of the default `search_index.${default_language}.js`.

As each site will be different, Zola makes no assumptions about your search function and doesn't provide
4 changes: 2 additions & 2 deletions docs/content/documentation/getting-started/configuration.md
Original file line number Diff line number Diff line change
@@ -161,8 +161,8 @@ include_content = true
# truncate_content_length = 100

# Wether to produce the search index as a javascript file or as a JSON file
# Accepted value "javascript" or "json"
index_format = "javascript"
# Accepted value "elasticlunr_javascript" or "elasticlunr_json"
index_format = "elasticlunr_javascript"

# Optional translation object for the default language
# Example:

0 comments on commit c716bfc

Please sign in to comment.