Fixed error when initializing search

This commit is contained in:
squidfunk 2017-10-31 20:48:41 +01:00 committed by Martin Donath
parent c5143e890f
commit 87d8855dfe
8 changed files with 38 additions and 34 deletions

View File

@ -17,7 +17,7 @@ The translations can be changed in `theme/partials/language.html`:
"footer.next": "Nächste Seite", "footer.next": "Nächste Seite",
"meta.comments": "Kommentare", "meta.comments": "Kommentare",
"meta.source": "Quellcode", "meta.source": "Quellcode",
"search.languages": "de", "search.language": "de",
"search.placeholder": "Suche", "search.placeholder": "Suche",
"search.result.placeholder": "Suchbegriff eingeben", "search.result.placeholder": "Suchbegriff eingeben",
"search.result.none": "Keine Suchergebnisse", "search.result.none": "Keine Suchergebnisse",

View File

@ -30,7 +30,7 @@
"footer.next": "Nächste Seite", "footer.next": "Nächste Seite",
"meta.comments": "Kommentare", "meta.comments": "Kommentare",
"meta.source": "Quellcode", "meta.source": "Quellcode",
"search.languages": "de", "search.language": "de",
"search.placeholder": "Suche", "search.placeholder": "Suche",
"search.result.placeholder": "Suchbegriff eingeben", "search.result.placeholder": "Suchbegriff eingeben",
"search.result.none": "Keine Suchergebnisse", "search.result.none": "Keine Suchergebnisse",

View File

@ -25,7 +25,7 @@
{% for key in [ {% for key in [
"clipboard.copy", "clipboard.copy",
"clipboard.copied", "clipboard.copied",
"search.languages", "search.language",
"search.result.none", "search.result.none",
"search.result.one", "search.result.one",
"search.result.other", "search.result.other",
@ -167,8 +167,9 @@
{% endblock %} {% endblock %}
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application-946997f430.js"></script> <script src="{{ base_url }}/assets/javascripts/application-84693e5e49.js"></script>
{% set languages = lang.t("search.languages").split(",") %} {% if lang.t("search.language") != "en" %}
{% set languages = lang.t("search.language").split(",") %}
{% if languages | length and languages[0] != "" %} {% if languages | length and languages[0] != "" %}
{% set path = base_url + "/assets/javascripts/lunr" %} {% set path = base_url + "/assets/javascripts/lunr" %}
<script src="{{ path }}/lunr.stemmer.support.js"></script> <script src="{{ path }}/lunr.stemmer.support.js"></script>
@ -184,6 +185,7 @@
<script src="{{ path }}/lunr.multi.js"></script> <script src="{{ path }}/lunr.multi.js"></script>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %}
<script>app.initialize({version:"{{ mkdocs_version }}",url:{base:"{{ base_url }}"}})</script> <script>app.initialize({version:"{{ mkdocs_version }}",url:{base:"{{ base_url }}"}})</script>
{% for path in extra_javascript %} {% for path in extra_javascript %}
<script src="{{ path }}"></script> <script src="{{ path }}"></script>

View File

@ -1,6 +1,6 @@
{% import "partials/language/" + config.theme.language + ".html" as lang %} {% import "partials/language/" + config.theme.language + ".html" as lang %}
{% macro t(key) %}{{ { {% macro t(key) %}{{ {
"search.languages": ( "search.language": (
config.extra.search | default({}) config.extra.search | default({})
).language | default(config.theme.language, true), ).language | default(config.theme.language, true),
"search.tokenizer": ( "search.tokenizer": (

View File

@ -117,7 +117,7 @@ export default class Result {
lunr.tokenizer.separator = tokenizer lunr.tokenizer.separator = tokenizer
/* Load search languages */ /* Load search languages */
this.lang_ = translate("search.languages").split(",") this.lang_ = translate("search.language").split(",")
.filter(Boolean) .filter(Boolean)
.map(lang => lang.trim()) .map(lang => lang.trim())
} }
@ -180,7 +180,7 @@ export default class Result {
) )
/* Set up alternate search languages */ /* Set up alternate search languages */
if (lang.length === 1) { if (lang.length === 1 && lang[0] !== "en") {
this.use(lunr[lang[0]]) this.use(lunr[lang[0]])
} else if (lang.length > 1) { } else if (lang.length > 1) {
this.use(lunr.multiLanguage(...lang)) this.use(lunr.multiLanguage(...lang))

View File

@ -63,7 +63,7 @@
{% for key in [ {% for key in [
"clipboard.copy", "clipboard.copy",
"clipboard.copied", "clipboard.copied",
"search.languages", "search.language",
"search.result.none", "search.result.none",
"search.result.one", "search.result.one",
"search.result.other", "search.result.other",
@ -303,7 +303,8 @@
<script src="{{ base_url }}/assets/javascripts/application.js"></script> <script src="{{ base_url }}/assets/javascripts/application.js"></script>
<!-- Load additional languages for search --> <!-- Load additional languages for search -->
{% set languages = lang.t("search.languages").split(",") %} {% if lang.t("search.language") != "en" %}
{% set languages = lang.t("search.language").split(",") %}
{% if languages | length and languages[0] != "" %} {% if languages | length and languages[0] != "" %}
{% set path = base_url + "/assets/javascripts/lunr" %} {% set path = base_url + "/assets/javascripts/lunr" %}
<script src="{{ path }}/lunr.stemmer.support.js"></script> <script src="{{ path }}/lunr.stemmer.support.js"></script>
@ -319,6 +320,7 @@
<script src="{{ path }}/lunr.multi.js"></script> <script src="{{ path }}/lunr.multi.js"></script>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endif %}
<!-- Initialize application --> <!-- Initialize application -->
<script> <script>

View File

@ -25,7 +25,7 @@
<!-- Re-export translations --> <!-- Re-export translations -->
{% macro t(key) %}{{ { {% macro t(key) %}{{ {
"search.languages": ( "search.language": (
config.extra.search | default({}) config.extra.search | default({})
).language | default(config.theme.language, true), ).language | default(config.theme.language, true),
"search.tokenizer": ( "search.tokenizer": (