1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-12 10:00:52 +01:00

Added support for lunr-languages

This commit is contained in:
squidfunk 2020-01-26 16:03:49 +01:00
parent 1fdb65b88f
commit 018e38e9ac
7 changed files with 17 additions and 21 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,11 +4,5 @@
{% import "partials/language/" + config.theme.language + ".html" as lang %}
{% import "partials/language/en.html" as fallback %}
{% macro t(key) %}{{ {
"direction": config.theme.direction,
"search.language": (
config.extra.search | default({})
).language,
"search.tokenizer": (
config.extra.search | default({})
).tokenizer | default("", true),
"direction": config.theme.direction
}[key] or lang.t(key) or fallback.t(key) }}{% endmacro %}

View File

@ -70,7 +70,8 @@ import {
watchWorker,
setToggle,
getElements,
watchMedia
watchMedia,
translate
} from "./utilities"
import {
PackerMessage,

View File

@ -137,6 +137,13 @@ export class SearchIndex {
if (pipeline.stopwords)
this.pipeline.add(lunr.stopWordFilter)
/* Set up alternate search languages */
if (config.lang.length === 1 && config.lang[0] !== "en") {
this.use((lunr as any)[config.lang[0]])
} else if (config.lang.length > 1) {
this.use((lunr as any).multiLanguage(...config.lang))
}
/* Setup fields and reference */
this.field("title", { boost: 10 })
this.field("text")

View File

@ -28,11 +28,5 @@
<!-- Re-export translations -->
{% macro t(key) %}{{ {
"direction": config.theme.direction,
"search.language": (
config.extra.search | default({})
).language,
"search.tokenizer": (
config.extra.search | default({})
).tokenizer | default("", true),
"direction": config.theme.direction
}[key] or lang.t(key) or fallback.t(key) }}{% endmacro %}