Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search json index #1998

Merged
merged 4 commits into from
Oct 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add elasticlunr prefix to search engine format configuration
This will be useful if support for more search libraries are added in the future
sgued committed Oct 30, 2022
commit c716bfcdba9ff69e097b7372b59fe192435a7ae7
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: