Skip to content

Commit

Permalink
searching changed to search and added default_enable parameter
Browse files Browse the repository at this point in the history
* `searching` changed to `search` and added `default_enable` parameter

* Delete alias.html
  • Loading branch information
harrymkt authored Dec 24, 2024
1 parent dce120e commit a09202a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ default_language = "en"
# Title separator, such as dash (-)
title_sep = ""

[extra.searching]
[extra.search]
enable = true
default_enable = true
format = "pagefind"

[[extra.menus.main]]
Expand Down
3 changes: 2 additions & 1 deletion content/docs/extra/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Example navigation:
class = "blog"
```

## searching
## search
- `enable`(bool): Toggles search. Defaults to `true`
- `default_enable`(bool): Default search status. This is useful to turn this off and manually turn on in the frontmadder of the pages you want. Defaults to `true`
- `format`(string): One of the [search formats](@/docs/search.md#sformats). Defaults to `pagefind`
2 changes: 1 addition & 1 deletion content/docs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight = 2000
Zluinav has search built-in. This is a quick overview on how to create your search.

## Configuration
See [search configuration](@/docs/extra/config.md#searching)
See [search configuration](@/docs/extra/config.md#search)

## Search Formats{#sformats}
You have a variety of formats to choose for your search.
Expand Down
1 change: 1 addition & 0 deletions content/lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# Do not translate this file
title = "Change language"
template = "language_changer.html"
extra.search = false
+++
26 changes: 15 additions & 11 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
{%- if not tr -%}{%- set tr = load_data(path = "themes/zluinav/" ~ config.extra.tr_path ~ "/" ~ lang ~ ".toml", required = false) -%}{%- endif -%}
{%- set ctx = "" -%}
{%- if section -%}
{%- set ctx = section -%}
{%- set ctx = section -%}
{%- elif page -%}
{%- set ctx = page -%}
{%- set ctx = page -%}
{%- endif -%}
{%- set searchfm = config.extra.searching.format %}
{%- set searchfm = config.extra.search.format %}
{%- set searchfms = ["pagefind", "main"] %}
{%- if searchfm not in searchfms %}
{{- throw(message = "Search format is invalid") }}
{%- endif %}
{%- set search = false %}
{%- if config.extra.search.enable and (ctx.extra.search | default(value = config.extra.search.default_enable)) %}
{%- set search = true %}
{%- endif -%}
<!doctype html>
<html lang="{{ lang }}">
Expand Down Expand Up @@ -46,13 +50,13 @@
<p><a href="#navigation" class="skip-link">{{tran::get(tr=tr, key="acc_skip_nav", def="Skip to navigation")}}</a></p>
{%- endif %}
<p><a href="#zlfooter" class="skip-link">{{tran::get(tr=tr, key="acc_skip_footer", def="Skip to footer")}}</a></p>
{%- if config.extra.searching.enable and searchfm == "pagefind" %}
{%- if search and searchfm == "pagefind" %}
<link href="{{ get_url(path = "pagefind/pagefind-ui.css") }}" rel="stylesheet">
<script src="{{ get_url(path = "pagefind/pagefind-ui.js") }}"></script>
<div id="search"></div>
{%- elif config.extra.searching.enable and searchfm == "main" and config.build_search_index %}
<div id="sitesearch"></div>
{%- elif search and searchfm == "main" and config.build_search_index %}
<div class="search-container">
<input id="search" type="search" placeholder="{{ tran::get(tr=tr, key="search_title", def="Search the site") }}">
<input id="sitesearch" type="search" placeholder="{{ tran::get(tr=tr, key="search_title", def="Search the site") }}">
<div class="search-results">
<div class="search-results__items"></div>
</div>
Expand All @@ -70,7 +74,7 @@ <h2>{{tran::get(tr = tr, key = "main_menu", def = "Main menu")}}</h2>
</nav>
{%- endif %}
{%- endblock nav %}
<main id="mainc"{% if (ctx.extra.search | default(value = config.extra.searching.enable)) %} data-pagefind-body{% endif %}>
<main id="mainc"{% if search %} data-pagefind-body{% endif %}>
{%- block main %}
{%- endblock main -%}
</main>
Expand All @@ -83,13 +87,13 @@ <h2>{{tran::get(tr = tr, key = "main_menu", def = "Main menu")}}</h2>
</div>
{%- block extrafoot %}
<script src="{{ get_url(path = "scripts/copy.js") }}"></script>
{%- if config.extra.searching.enable and searchfm == "main" and config.build_search_index %}
{%- if search and searchfm == "main" and config.build_search_index %}
<script type="text/javascript" src="{{ get_url(path = "elasticlunr.min.js") }}"></script>
<script type="text/javascript" src="{{ get_url(path = "scripts/search.js") }}"></script>
{%- elif config.extra.searching.enable and searchfm == "pagefind" %}
{%- elif search and searchfm == "pagefind" %}
<script>
window.addEventListener('DOMContentLoaded', (event) => {
new PagefindUI({ element: "#search", showSubResults: true });
new PagefindUI({ element: "#sitesearch", showSubResults: true });
});
</script>
{%- endif %}
Expand Down
3 changes: 2 additions & 1 deletion theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ demo = "https://harrymkt.github.io/zluinav"
# Title separator, such as dash (-)
title_sep = ""

[extra.searching]
[extra.search]
enable = true
default_enable = true
format = "pagefind"

0 comments on commit a09202a

Please sign in to comment.