mirror of https://github.com/onweru/compose.git

weru
28.10.2023 bf9588061a3f948f6a0acb3abd953d50e9bfbf6f
allow site owners to enable global-search #104

Signed-off-by: weru <fromweru@gmail.com>
4 files modified
22 ■■■■ changed files
assets/js/search/index.js 4 ●●● patch | view | raw | blame | history
assets/js/search/variables.js 2 ●●●●● patch | view | raw | blame | history
exampleSite/config/_default/params.toml 3 ●●●● patch | view | raw | blame | history
exampleSite/content/docs/compose/search.md 13 ●●●●● patch | view | raw | blame | history
assets/js/search/index.js
@@ -11,6 +11,7 @@
}
function search(index, scope = null, passive = false) {
  scope = search_scope_global ? null : scope;
  if(search_term.length) {
    let raw_results = index;
    if(!algolia_config.on) {
@@ -38,8 +39,9 @@
function liveSearch(index) {
  if (search_field) {
    const search_scope = search_field.dataset.scope;
    let search_scope = search_field.dataset.scope;
    search(index, search_scope);
    search_scope = search_scope_global ? null : search_scope;
    if(!search_page_element) {
      search_field.addEventListener('search', function(){
        search_term = search_field.value.trim().toLowerCase();
assets/js/search/variables.js
@@ -24,6 +24,8 @@
}
const search_page_element = elem('#searchpage');
let search_scope_global = `{{ trim site.Params.search.global " " }}`;
search_scope_global = search_scope_global == 'true' ? true : false;
// Fuse specific
let search_keys = ['body', 'title', 'link', 'section', 'id',];
exampleSite/config/_default/params.toml
@@ -26,13 +26,14 @@
# search
[search]
on = true
# Site logo
global = false # turn to `true` to enable global search
[search.algolia]
enable = false # if false search will default to fusejs
id = "Q40WQQX84U" # Application ID
index = "compose" # Index name
key = "da87401a458102ec6bbd6cc5e5cf8d95" # Search-Only API Key
# Site logo
[logo]
  lightMode = "images/compose.svg"
  darkMode = "images/compose-light.svg"
exampleSite/content/docs/compose/search.md
@@ -17,7 +17,7 @@
# search
[search]
on = true
# Site logo
global = false
[search.algolia]
enable = false # if false search will default to fusejs
id = "Q40WQQX84U" # Application ID
@@ -29,6 +29,17 @@
Algolia will require you to build and host your index. For those using Github, this theme ships with an [algolia github action](/docs/compose/github-actions/#algolia-ci).
By default, search will return results from the current content section. Searches from the top level section e.g the homepage, will return global results. This way, the results are scoped. You can override this behaviour using this setting
```toml
...
[search]
...
global = false # turn to `true` to enable global search
...
```
At the time of this writing, search on these theme takes either of this forms:
### 1. Passive search