mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Added stemmer support for file:// protocol through iframe-worker
This commit is contained in:
parent
ee808c769e
commit
9fe00ec0af
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
File diff suppressed because one or more lines are too long
@ -3,8 +3,8 @@
|
|||||||
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.d5b17bb4.min.js.map",
|
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.d5b17bb4.min.js.map",
|
||||||
"assets/javascripts/vendor.js": "assets/javascripts/vendor.186f2b9b.min.js",
|
"assets/javascripts/vendor.js": "assets/javascripts/vendor.186f2b9b.min.js",
|
||||||
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.186f2b9b.min.js.map",
|
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.186f2b9b.min.js.map",
|
||||||
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.cbc634e2.min.js",
|
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.c9a3f22b.min.js",
|
||||||
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.cbc634e2.min.js.map",
|
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.c9a3f22b.min.js.map",
|
||||||
"assets/stylesheets/main.css": "assets/stylesheets/main.f6c1319f.min.css",
|
"assets/stylesheets/main.css": "assets/stylesheets/main.f6c1319f.min.css",
|
||||||
"assets/stylesheets/main.css.map": "assets/stylesheets/main.f6c1319f.min.css.map",
|
"assets/stylesheets/main.css.map": "assets/stylesheets/main.f6c1319f.min.css.map",
|
||||||
"assets/stylesheets/overrides.css": "assets/stylesheets/overrides.41a1bb10.min.css",
|
"assets/stylesheets/overrides.css": "assets/stylesheets/overrides.41a1bb10.min.css",
|
||||||
|
@ -200,7 +200,7 @@
|
|||||||
base: "{{ base_url }}",
|
base: "{{ base_url }}",
|
||||||
features: {{ config.theme.features or [] | tojson }},
|
features: {{ config.theme.features or [] | tojson }},
|
||||||
search: Object.assign({
|
search: Object.assign({
|
||||||
worker: "{{ 'assets/javascripts/worker/search.cbc634e2.min.js' | url }}"
|
worker: "{{ 'assets/javascripts/worker/search.c9a3f22b.min.js' | url }}"
|
||||||
}, typeof search !== "undefined" && search)
|
}, typeof search !== "undefined" && search)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -37,8 +37,8 @@
|
|||||||
"focus-visible": "^5.1.0",
|
"focus-visible": "^5.1.0",
|
||||||
"lunr": "^2.3.9",
|
"lunr": "^2.3.9",
|
||||||
"lunr-languages": "^1.4.0",
|
"lunr-languages": "^1.4.0",
|
||||||
"resize-observer-polyfill": "^1.5.1",
|
|
||||||
"ramda": "^0.27.1",
|
"ramda": "^0.27.1",
|
||||||
|
"resize-observer-polyfill": "^1.5.1",
|
||||||
"rxjs": "^7.0.0-beta.7"
|
"rxjs": "^7.0.0-beta.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -39,7 +39,7 @@ import {
|
|||||||
/**
|
/**
|
||||||
* Add support for usage with `iframe-worker` polyfill
|
* Add support for usage with `iframe-worker` polyfill
|
||||||
*
|
*
|
||||||
* While `importScripts` is synchronous when executed inside of a webworker,
|
* While `importScripts` is synchronous when executed inside of a web worker,
|
||||||
* it's not possible to provide a synchronous polyfilled implementation. The
|
* it's not possible to provide a synchronous polyfilled implementation. The
|
||||||
* cool thing is that awaiting a non-Promise is a noop, so extending the type
|
* cool thing is that awaiting a non-Promise is a noop, so extending the type
|
||||||
* definition to return a `Promise` shouldn't break anything.
|
* definition to return a `Promise` shouldn't break anything.
|
||||||
@ -83,6 +83,11 @@ async function fetchSearchIndex(url: string): Promise<SearchIndex> {
|
|||||||
* This function will automatically import the stemmers necessary to process
|
* This function will automatically import the stemmers necessary to process
|
||||||
* the languages which were given through the search index configuration.
|
* the languages which were given through the search index configuration.
|
||||||
*
|
*
|
||||||
|
* If the worker runs inside of an `iframe` (when using `iframe-worker` as a
|
||||||
|
* shim), the base URL must be determined by searching for the first `script`
|
||||||
|
* element with a `src` attribute, which will equal the worker script, and
|
||||||
|
* determine the base URL by examining the worker URL.
|
||||||
|
*
|
||||||
* @param config - Search index configuration
|
* @param config - Search index configuration
|
||||||
*
|
*
|
||||||
* @return Promise resolving with no result
|
* @return Promise resolving with no result
|
||||||
@ -90,7 +95,16 @@ async function fetchSearchIndex(url: string): Promise<SearchIndex> {
|
|||||||
async function setupSearchLanguages(
|
async function setupSearchLanguages(
|
||||||
config: SearchIndexConfig
|
config: SearchIndexConfig
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const base = "../lunr"
|
let base = "../lunr"
|
||||||
|
|
||||||
|
/* Detect `iframe-worker` and fix base URL */
|
||||||
|
if (typeof parent !== "undefined" && "IFrameWorker" in parent) {
|
||||||
|
const worker = document.querySelector<HTMLScriptElement>("script[src]")!
|
||||||
|
const [path] = worker.src.split("/worker")
|
||||||
|
|
||||||
|
/* Prefix base with path */
|
||||||
|
base = base.replace("..", path)
|
||||||
|
}
|
||||||
|
|
||||||
/* Add scripts for languages */
|
/* Add scripts for languages */
|
||||||
const scripts = []
|
const scripts = []
|
||||||
|
Loading…
Reference in New Issue
Block a user