mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Replaced operators: ajax -> fetch, pluck -> map
This commit is contained in:
parent
0c4ddfcd70
commit
ab513f036e
@ -3,7 +3,7 @@ mkdocs-material-6.x.x (2020-09-xx)
|
|||||||
* Fixed stemmer support for file:// protocol through `iframe-worker`
|
* Fixed stemmer support for file:// protocol through `iframe-worker`
|
||||||
* Fixed details marker showing for search result in Firefox
|
* Fixed details marker showing for search result in Firefox
|
||||||
* Fixed tabbing behavior when search query is not empty
|
* Fixed tabbing behavior when search query is not empty
|
||||||
* Reduced size of vendor bundle by 25% (67kb → 65kb)
|
* Reduced size of vendor bundle by 10% (67kb → 61kb)
|
||||||
* Removed mkdocs and readthedocs themes from Docker image
|
* Removed mkdocs and readthedocs themes from Docker image
|
||||||
|
|
||||||
mkdocs-material-6.0.0 (2020-09-25)
|
mkdocs-material-6.0.0 (2020-09-25)
|
||||||
|
2
material/assets/javascripts/bundle.6f400298.min.js
vendored
Normal file
2
material/assets/javascripts/bundle.6f400298.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/bundle.6f400298.min.js.map
Normal file
1
material/assets/javascripts/bundle.6f400298.min.js.map
Normal file
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
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/vendor.e3b5b4d0.min.js.map
Normal file
1
material/assets/javascripts/vendor.e3b5b4d0.min.js.map
Normal file
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
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"assets/javascripts/bundle.js": "assets/javascripts/bundle.a50b2d70.min.js",
|
"assets/javascripts/bundle.js": "assets/javascripts/bundle.6f400298.min.js",
|
||||||
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.a50b2d70.min.js.map",
|
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.6f400298.min.js.map",
|
||||||
"assets/javascripts/vendor.js": "assets/javascripts/vendor.bdf98b33.min.js",
|
"assets/javascripts/vendor.js": "assets/javascripts/vendor.e3b5b4d0.min.js",
|
||||||
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.bdf98b33.min.js.map",
|
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.e3b5b4d0.min.js.map",
|
||||||
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.e0a2b82c.min.js",
|
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.2693be28.min.js",
|
||||||
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.e0a2b82c.min.js.map",
|
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.2693be28.min.js.map",
|
||||||
"assets/stylesheets/main.css": "assets/stylesheets/main.40703c20.min.css",
|
"assets/stylesheets/main.css": "assets/stylesheets/main.6a8334c2.min.css",
|
||||||
"assets/stylesheets/main.css.map": "assets/stylesheets/main.40703c20.min.css.map",
|
"assets/stylesheets/main.css.map": "assets/stylesheets/main.6a8334c2.min.css.map",
|
||||||
"assets/stylesheets/overrides.css": "assets/stylesheets/overrides.082f5519.min.css",
|
"assets/stylesheets/overrides.css": "assets/stylesheets/overrides.2ca3414a.min.css",
|
||||||
"assets/stylesheets/overrides.css.map": "assets/stylesheets/overrides.082f5519.min.css.map",
|
"assets/stylesheets/overrides.css.map": "assets/stylesheets/overrides.2ca3414a.min.css.map",
|
||||||
"assets/stylesheets/palette.css": "assets/stylesheets/palette.0eb3995c.min.css",
|
"assets/stylesheets/palette.css": "assets/stylesheets/palette.037a1494.min.css",
|
||||||
"assets/stylesheets/palette.css.map": "assets/stylesheets/palette.0eb3995c.min.css.map"
|
"assets/stylesheets/palette.css.map": "assets/stylesheets/palette.037a1494.min.css.map"
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,3 +1,3 @@
|
|||||||
.md-typeset .tx-insiders{color:#e91e63}.md-typeset .tx-switch button{cursor:pointer;transition:opacity 250ms}.md-typeset .tx-switch button:hover{opacity:.75}.md-typeset .tx-switch button>code{display:block;color:var(--md-primary-bg-color);background-color:var(--md-primary-fg-color)}.md-typeset .tx-columns{-moz-columns:2;columns:2}.md-typeset .tx-columns>*{-moz-column-break-inside:avoid;break-inside:avoid}.md-announce a,.md-announce a:focus,.md-announce a:hover{color:currentColor}.md-announce strong{white-space:nowrap}.md-announce .twitter{margin-left:.2em;color:#00acee}.tx-container{padding-top:1rem;background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(0, 0%, 100%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}[data-md-color-scheme=slate] .tx-container{background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(232, 15%, 21%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}@-webkit-keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}@keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}.tx-content__footer{margin-top:1rem;text-align:center}.tx-content__footer a{display:inline-block;color:#e91e63;transition:transform 250ms cubic-bezier(0.1, 0.7, 0.1, 1),color 125ms}.tx-content__footer a:focus,.tx-content__footer a:hover{transform:scale(1.2)}.tx-content__footer hr{display:inline-block;width:2rem;margin:1em;vertical-align:middle;background-color:currentColor;border:none}.tx-heart{-webkit-animation:tx-heart 1000ms infinite;animation:tx-heart 1000ms infinite}.tx-hero{margin:0 .8rem;color:var(--md-primary-bg-color)}.tx-hero h1{margin-bottom:1rem;color:currentColor;font-weight:700}@media screen and (max-width: 29.9375em){.tx-hero h1{font-size:1.4rem}}.tx-hero__content{padding-bottom:6rem}@media screen and (min-width: 60em){.tx-hero{display:flex;align-items:stretch}.tx-hero__content{max-width:19rem;margin-top:3.5rem;padding-bottom:14vw}.tx-hero__image{order:1;width:38rem;transform:translateX(4rem)}}@media screen and (min-width: 76.25em){.tx-hero__image{transform:translateX(8rem)}}.tx-hero .md-button{margin-top:.5rem;margin-right:.5rem;color:var(--md-primary-bg-color)}.tx-hero .md-button:hover,.tx-hero .md-button:focus{color:var(--md-default-bg-color);background-color:var(--md-accent-fg-color);border-color:var(--md-accent-fg-color)}.tx-hero .md-button--primary{color:#894da8;background-color:var(--md-primary-bg-color);border-color:var(--md-primary-bg-color)}
|
.md-typeset .tx-insiders{color:#e91e63}.md-typeset .tx-switch button{cursor:pointer;transition:opacity 250ms}.md-typeset .tx-switch button:hover{opacity:.75}.md-typeset .tx-switch button>code{display:block;color:var(--md-primary-bg-color);background-color:var(--md-primary-fg-color)}.md-typeset .tx-columns{-moz-columns:2;columns:2}.md-typeset .tx-columns>*{-moz-column-break-inside:avoid;break-inside:avoid}.md-announce a,.md-announce a:focus,.md-announce a:hover{color:currentColor}.md-announce strong{white-space:nowrap}.md-announce .twitter{margin-left:.2em;color:#00acee}.tx-container{padding-top:1rem;background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(0, 0%, 100%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}[data-md-color-scheme=slate] .tx-container{background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1123 258'><path d='M1124,2c0,0 0,256 0,256l-1125,0l0,-48c0,0 16,5 55,5c116,0 197,-92 325,-92c121,0 114,46 254,46c140,0 214,-167 572,-166Z' style='fill: hsla(232, 15%, 21%, 1)' /></svg>") no-repeat bottom,linear-gradient(to bottom, var(--md-primary-fg-color), #a63fd9 99%, var(--md-default-bg-color) 99%)}@-webkit-keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}@keyframes tx-heart{0%,40%,80%,100%{transform:scale(1)}20%,60%{transform:scale(1.15)}}.tx-content__footer{margin-top:1rem;text-align:center}.tx-content__footer a{display:inline-block;color:#e91e63;transition:transform 250ms cubic-bezier(0.1, 0.7, 0.1, 1),color 125ms}.tx-content__footer a:focus,.tx-content__footer a:hover{transform:scale(1.2)}.tx-content__footer hr{display:inline-block;width:2rem;margin:1em;vertical-align:middle;background-color:currentColor;border:none}.tx-heart{-webkit-animation:tx-heart 1000ms infinite;animation:tx-heart 1000ms infinite}.tx-hero{margin:0 .8rem;color:var(--md-primary-bg-color)}.tx-hero h1{margin-bottom:1rem;color:currentColor;font-weight:700}@media screen and (max-width: 29.9375em){.tx-hero h1{font-size:1.4rem}}.tx-hero__content{padding-bottom:6rem}@media screen and (min-width: 60em){.tx-hero{display:flex;align-items:stretch}.tx-hero__content{max-width:19rem;margin-top:3.5rem;padding-bottom:14vw}.tx-hero__image{order:1;width:38rem;transform:translateX(4rem)}}@media screen and (min-width: 76.25em){.tx-hero__image{transform:translateX(8rem)}}.tx-hero .md-button{margin-top:.5rem;margin-right:.5rem;color:var(--md-primary-bg-color)}.tx-hero .md-button:hover,.tx-hero .md-button:focus{color:var(--md-default-bg-color);background-color:var(--md-accent-fg-color);border-color:var(--md-accent-fg-color)}.tx-hero .md-button--primary{color:#894da8;background-color:var(--md-primary-bg-color);border-color:var(--md-primary-bg-color)}
|
||||||
|
|
||||||
/*# sourceMappingURL=overrides.082f5519.min.css.map*/
|
/*# sourceMappingURL=overrides.2ca3414a.min.css.map*/
|
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
@ -34,10 +34,10 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block styles %}
|
{% block styles %}
|
||||||
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.40703c20.min.css' | url }}">
|
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.6a8334c2.min.css' | url }}">
|
||||||
{% if config.theme.palette %}
|
{% if config.theme.palette %}
|
||||||
{% set palette = config.theme.palette %}
|
{% set palette = config.theme.palette %}
|
||||||
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.0eb3995c.min.css' | url }}">
|
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.037a1494.min.css' | url }}">
|
||||||
{% if palette.primary %}
|
{% if palette.primary %}
|
||||||
{% import "partials/palette.html" as map %}
|
{% import "partials/palette.html" as map %}
|
||||||
{% set primary = map.primary(
|
{% set primary = map.primary(
|
||||||
@ -172,8 +172,8 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{ 'assets/javascripts/vendor.bdf98b33.min.js' | url }}"></script>
|
<script src="{{ 'assets/javascripts/vendor.e3b5b4d0.min.js' | url }}"></script>
|
||||||
<script src="{{ 'assets/javascripts/bundle.a50b2d70.min.js' | url }}"></script>
|
<script src="{{ 'assets/javascripts/bundle.6f400298.min.js' | url }}"></script>
|
||||||
{%- set translations = {} -%}
|
{%- set translations = {} -%}
|
||||||
{%- for key in [
|
{%- for key in [
|
||||||
"clipboard.copy",
|
"clipboard.copy",
|
||||||
@ -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.e0a2b82c.min.js' | url }}"
|
worker: "{{ 'assets/javascripts/worker/search.2693be28.min.js' | url }}"
|
||||||
}, typeof search !== "undefined" && search)
|
}, typeof search !== "undefined" && search)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<meta name="twitter:title" content="{{ title }}">
|
<meta name="twitter:title" content="{{ title }}">
|
||||||
<meta name="twitter:description" content="{{ config.site_description }}">
|
<meta name="twitter:description" content="{{ config.site_description }}">
|
||||||
<meta name="twitter:image" content="{{ image }}">
|
<meta name="twitter:image" content="{{ image }}">
|
||||||
<link rel="stylesheet" href="{{ 'assets/stylesheets/overrides.082f5519.min.css' | url }}">
|
<link rel="stylesheet" href="{{ 'assets/stylesheets/overrides.2ca3414a.min.css' | url }}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block announce %}
|
{% block announce %}
|
||||||
<a href="https://twitter.com/squidfunk">
|
<a href="https://twitter.com/squidfunk">
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
import { Observable, Subject, fromEvent } from "rxjs"
|
import { Observable, Subject, fromEvent } from "rxjs"
|
||||||
import {
|
import {
|
||||||
pluck,
|
map,
|
||||||
share,
|
share,
|
||||||
switchMapTo,
|
switchMapTo,
|
||||||
tap,
|
tap,
|
||||||
@ -90,7 +90,7 @@ export function watchWorker<T extends WorkerMessage>(
|
|||||||
/* Intercept messages from worker-like objects */
|
/* Intercept messages from worker-like objects */
|
||||||
const rx$ = fromEvent<MessageEvent>(worker, "message")
|
const rx$ = fromEvent<MessageEvent>(worker, "message")
|
||||||
.pipe<T>(
|
.pipe<T>(
|
||||||
pluck("data")
|
map(({ data }) => data)
|
||||||
)
|
)
|
||||||
|
|
||||||
/* Send and receive messages, return hot observable */
|
/* Send and receive messages, return hot observable */
|
||||||
|
@ -33,7 +33,6 @@ import {
|
|||||||
finalize,
|
finalize,
|
||||||
map,
|
map,
|
||||||
observeOn,
|
observeOn,
|
||||||
pluck,
|
|
||||||
switchMap,
|
switchMap,
|
||||||
tap
|
tap
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
@ -82,7 +81,7 @@ export function watchMain(
|
|||||||
/* Compute necessary adjustment for header */
|
/* Compute necessary adjustment for header */
|
||||||
const adjust$ = header$
|
const adjust$ = header$
|
||||||
.pipe(
|
.pipe(
|
||||||
pluck("height"),
|
map(({ height }) => height),
|
||||||
distinctUntilChanged()
|
distinctUntilChanged()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import {
|
|||||||
filter,
|
filter,
|
||||||
map,
|
map,
|
||||||
mapTo,
|
mapTo,
|
||||||
pluck,
|
|
||||||
startWith,
|
startWith,
|
||||||
switchMap
|
switchMap
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
@ -93,7 +92,7 @@ export function mountSearchResult(
|
|||||||
return rx$
|
return rx$
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(isSearchResultMessage),
|
filter(isSearchResultMessage),
|
||||||
pluck("data"),
|
map(({ data }) => data),
|
||||||
applySearchResult(el, { query$, ready$, fetch$ }),
|
applySearchResult(el, { query$, ready$, fetch$ }),
|
||||||
startWith([])
|
startWith([])
|
||||||
)
|
)
|
||||||
|
@ -36,7 +36,6 @@ import {
|
|||||||
of,
|
of,
|
||||||
NEVER
|
NEVER
|
||||||
} from "rxjs"
|
} from "rxjs"
|
||||||
import { ajax } from "rxjs/ajax"
|
|
||||||
import {
|
import {
|
||||||
delay,
|
delay,
|
||||||
switchMap,
|
switchMap,
|
||||||
@ -46,7 +45,6 @@ import {
|
|||||||
observeOn,
|
observeOn,
|
||||||
take,
|
take,
|
||||||
shareReplay,
|
shareReplay,
|
||||||
pluck,
|
|
||||||
catchError,
|
catchError,
|
||||||
map
|
map
|
||||||
} from "rxjs/operators"
|
} from "rxjs/operators"
|
||||||
@ -94,7 +92,7 @@ import {
|
|||||||
patchSource,
|
patchSource,
|
||||||
patchScripts
|
patchScripts
|
||||||
} from "patches"
|
} from "patches"
|
||||||
import { isConfig, translate } from "utilities"
|
import { isConfig } from "utilities"
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
@ -134,38 +132,6 @@ export function resetScrollLock(
|
|||||||
window.scrollTo(0, value)
|
window.scrollTo(0, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
|
||||||
* Helper functions
|
|
||||||
* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up search index
|
|
||||||
*
|
|
||||||
* @param data - Search index
|
|
||||||
*
|
|
||||||
* @return Search index
|
|
||||||
*/
|
|
||||||
function setupSearchIndex( // Hack: move this outside here, temporarily...
|
|
||||||
{ config, docs, index }: SearchIndex
|
|
||||||
): SearchIndex {
|
|
||||||
|
|
||||||
/* Override default language with value from translation */
|
|
||||||
if (config.lang.length === 1 && config.lang[0] === "en")
|
|
||||||
config.lang = [translate("search.config.lang")]
|
|
||||||
|
|
||||||
/* Override default separator with value from translation */
|
|
||||||
if (config.separator === "[\\s\\-]+")
|
|
||||||
config.separator = translate("search.config.separator")
|
|
||||||
|
|
||||||
/* Set pipeline from translation */
|
|
||||||
const pipeline = translate("search.config.pipeline")
|
|
||||||
.split(/\s*,\s*/)
|
|
||||||
.filter(Boolean) as SearchIndexPipeline
|
|
||||||
|
|
||||||
/* Return search index after defaulting */
|
|
||||||
return { config, docs, index, pipeline }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
@ -277,21 +243,11 @@ export function initialize(config: unknown) {
|
|||||||
? from(index)
|
? from(index)
|
||||||
: base$
|
: base$
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(base => ajax({
|
switchMap(base => fetch(`${base}/search/search_index.json`, {
|
||||||
url: `${base}/search/search_index.json`,
|
credentials: "same-origin"
|
||||||
responseType: "json",
|
}).then(res => res.json())) // SearchIndex
|
||||||
withCredentials: true
|
|
||||||
})
|
|
||||||
.pipe<SearchIndex>(
|
|
||||||
pluck("response")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.pipe(
|
|
||||||
map(setupSearchIndex),
|
|
||||||
shareReplay(1)
|
|
||||||
)
|
|
||||||
|
|
||||||
return of(setupSearchWorker(config.search.worker, {
|
return of(setupSearchWorker(config.search.worker, {
|
||||||
base$, index$
|
base$, index$
|
||||||
@ -396,19 +352,15 @@ export function initialize(config: unknown) {
|
|||||||
config.features.includes("navigation.instant") &&
|
config.features.includes("navigation.instant") &&
|
||||||
location.protocol !== "file:"
|
location.protocol !== "file:"
|
||||||
) {
|
) {
|
||||||
|
const dom = new DOMParser()
|
||||||
|
|
||||||
/* Fetch sitemap and extract URL whitelist */
|
/* Fetch sitemap and extract URL whitelist */
|
||||||
base$
|
base$
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(base => ajax({
|
switchMap(base => from(fetch(`${base}/sitemap.xml`)
|
||||||
url: `${base}/sitemap.xml`,
|
.then(res => res.text())
|
||||||
responseType: "document",
|
.then(text => dom.parseFromString(text, "text/xml"))
|
||||||
withCredentials: true
|
)),
|
||||||
})
|
|
||||||
.pipe<Document>(
|
|
||||||
pluck("response")
|
|
||||||
)
|
|
||||||
),
|
|
||||||
withLatestFrom(base$),
|
withLatestFrom(base$),
|
||||||
map(([document, base]) => {
|
map(([document, base]) => {
|
||||||
const urls = getElements("loc", document)
|
const urls = getElements("loc", document)
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { NEVER, Observable, Subject, fromEvent, merge, of } from "rxjs"
|
import { NEVER, Observable, Subject, from, fromEvent, merge, of } from "rxjs"
|
||||||
import { ajax } from "rxjs//ajax"
|
|
||||||
import {
|
import {
|
||||||
bufferCount,
|
bufferCount,
|
||||||
catchError,
|
catchError,
|
||||||
@ -30,7 +29,6 @@ import {
|
|||||||
distinctUntilKeyChanged,
|
distinctUntilKeyChanged,
|
||||||
filter,
|
filter,
|
||||||
map,
|
map,
|
||||||
pluck,
|
|
||||||
sample,
|
sample,
|
||||||
share,
|
share,
|
||||||
skip,
|
skip,
|
||||||
@ -168,7 +166,7 @@ export function setupInstantLoading(
|
|||||||
merge(push$, pop$)
|
merge(push$, pop$)
|
||||||
.pipe(
|
.pipe(
|
||||||
distinctUntilChanged((prev, next) => prev.url.href === next.url.href),
|
distinctUntilChanged((prev, next) => prev.url.href === next.url.href),
|
||||||
pluck("url")
|
map(({ url }) => url)
|
||||||
)
|
)
|
||||||
.subscribe(location$)
|
.subscribe(location$)
|
||||||
|
|
||||||
@ -177,11 +175,9 @@ export function setupInstantLoading(
|
|||||||
.pipe(
|
.pipe(
|
||||||
distinctUntilKeyChanged("pathname"),
|
distinctUntilKeyChanged("pathname"),
|
||||||
skip(1),
|
skip(1),
|
||||||
switchMap(url => ajax({
|
switchMap(url => from(fetch(url.href, {
|
||||||
url: url.href,
|
credentials: "same-origin"
|
||||||
responseType: "text",
|
}).then(res => res.text()))
|
||||||
withCredentials: true
|
|
||||||
})
|
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(() => {
|
catchError(() => {
|
||||||
setLocation(url)
|
setLocation(url)
|
||||||
@ -205,7 +201,7 @@ export function setupInstantLoading(
|
|||||||
const dom = new DOMParser()
|
const dom = new DOMParser()
|
||||||
ajax$
|
ajax$
|
||||||
.pipe(
|
.pipe(
|
||||||
map(({ response }) => dom.parseFromString(response, "text/html"))
|
map(response => dom.parseFromString(response, "text/html"))
|
||||||
)
|
)
|
||||||
.subscribe(document$)
|
.subscribe(document$)
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ export type SearchIndexPipeline = SearchIndexPipelineFn[]
|
|||||||
export interface SearchIndex {
|
export interface SearchIndex {
|
||||||
config: SearchIndexConfig /* Search index configuration */
|
config: SearchIndexConfig /* Search index configuration */
|
||||||
docs: SearchIndexDocument[] /* Search index documents */
|
docs: SearchIndexDocument[] /* Search index documents */
|
||||||
index?: object | string /* Prebuilt or serialized index */
|
index?: object /* Prebuilt index */
|
||||||
pipeline?: SearchIndexPipeline /* Search index pipeline */
|
pipeline?: SearchIndexPipeline /* Search index pipeline */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,13 +204,9 @@ export class Search {
|
|||||||
this.add(doc)
|
this.add(doc)
|
||||||
})
|
})
|
||||||
|
|
||||||
/* Handle prebuilt or serialized index */
|
/* Handle prebuilt index */
|
||||||
} else {
|
} else {
|
||||||
this.index = lunr.Index.load(
|
this.index = lunr.Index.load(index)
|
||||||
typeof index === "string"
|
|
||||||
? JSON.parse(index)
|
|
||||||
: index
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* IN THE SOFTWARE.
|
* IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
import * as escapeHTML from "escape-html"
|
import * as escapeHTML from "escape-html"
|
||||||
|
|
||||||
import { SearchIndexDocument } from "../_"
|
import { SearchIndexDocument } from "../_"
|
||||||
|
@ -30,13 +30,14 @@ import {
|
|||||||
|
|
||||||
import { WorkerHandler, watchWorker } from "browser"
|
import { WorkerHandler, watchWorker } from "browser"
|
||||||
|
|
||||||
import { SearchIndex } from "../../_"
|
import { SearchIndex, SearchIndexPipeline } from "../../_"
|
||||||
import {
|
import {
|
||||||
SearchMessage,
|
SearchMessage,
|
||||||
SearchMessageType,
|
SearchMessageType,
|
||||||
SearchSetupMessage,
|
SearchSetupMessage,
|
||||||
isSearchResultMessage
|
isSearchResultMessage
|
||||||
} from "../message"
|
} from "../message"
|
||||||
|
import { translate } from "utilities"
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Helper types
|
* Helper types
|
||||||
@ -54,6 +55,38 @@ interface SetupOptions {
|
|||||||
* Functions
|
* Functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up search index
|
||||||
|
*
|
||||||
|
* @param data - Search index
|
||||||
|
*
|
||||||
|
* @return Search index
|
||||||
|
*/
|
||||||
|
function setupSearchIndex(
|
||||||
|
{ config, docs, index }: SearchIndex
|
||||||
|
): SearchIndex {
|
||||||
|
|
||||||
|
/* Override default language with value from translation */
|
||||||
|
if (config.lang.length === 1 && config.lang[0] === "en")
|
||||||
|
config.lang = [translate("search.config.lang")]
|
||||||
|
|
||||||
|
/* Override default separator with value from translation */
|
||||||
|
if (config.separator === "[\\s\\-]+")
|
||||||
|
config.separator = translate("search.config.separator")
|
||||||
|
|
||||||
|
/* Set pipeline from translation */
|
||||||
|
const pipeline = translate("search.config.pipeline")
|
||||||
|
.split(/\s*,\s*/)
|
||||||
|
.filter(Boolean) as SearchIndexPipeline
|
||||||
|
|
||||||
|
/* Return search index after defaulting */
|
||||||
|
return { config, docs, index, pipeline }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
* Helper functions
|
||||||
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up search web worker
|
* Set up search web worker
|
||||||
*
|
*
|
||||||
@ -92,7 +125,7 @@ export function setupSearchWorker(
|
|||||||
.pipe(
|
.pipe(
|
||||||
map<SearchIndex, SearchSetupMessage>(data => ({
|
map<SearchIndex, SearchSetupMessage>(data => ({
|
||||||
type: SearchMessageType.SETUP,
|
type: SearchMessageType.SETUP,
|
||||||
data
|
data: setupSearchIndex(data)
|
||||||
})),
|
})),
|
||||||
observeOn(asyncScheduler)
|
observeOn(asyncScheduler)
|
||||||
)
|
)
|
||||||
|
@ -22,11 +22,7 @@
|
|||||||
|
|
||||||
import "lunr"
|
import "lunr"
|
||||||
|
|
||||||
import {
|
import { Search, SearchIndexConfig } from "../../_"
|
||||||
Search,
|
|
||||||
SearchIndex,
|
|
||||||
SearchIndexConfig
|
|
||||||
} from "../../_"
|
|
||||||
import {
|
import {
|
||||||
SearchMessage,
|
SearchMessage,
|
||||||
SearchMessageType
|
SearchMessageType
|
||||||
@ -63,20 +59,6 @@ let index: Search
|
|||||||
* Helper functions
|
* Helper functions
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch search index from given URL
|
|
||||||
*
|
|
||||||
* @param url - Search index URL
|
|
||||||
*
|
|
||||||
* @return Promise resolving with search index
|
|
||||||
*/
|
|
||||||
async function fetchSearchIndex(url: string): Promise<SearchIndex> {
|
|
||||||
return fetch(url, {
|
|
||||||
credentials: "same-origin"
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch (= import) multi-language support through `lunr-languages`
|
* Fetch (= import) multi-language support through `lunr-languages`
|
||||||
*
|
*
|
||||||
@ -143,13 +125,8 @@ export async function handler(
|
|||||||
|
|
||||||
/* Search setup message */
|
/* Search setup message */
|
||||||
case SearchMessageType.SETUP:
|
case SearchMessageType.SETUP:
|
||||||
const data = typeof message.data === "string"
|
await setupSearchLanguages(message.data.config)
|
||||||
? await fetchSearchIndex(message.data)
|
index = new Search(message.data)
|
||||||
: message.data
|
|
||||||
|
|
||||||
/* Set up search index with multi-language support */
|
|
||||||
await setupSearchLanguages(data.config)
|
|
||||||
index = new Search(data)
|
|
||||||
return {
|
return {
|
||||||
type: SearchMessageType.READY
|
type: SearchMessageType.READY
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ export const enum SearchMessageType {
|
|||||||
*/
|
*/
|
||||||
export interface SearchSetupMessage {
|
export interface SearchSetupMessage {
|
||||||
type: SearchMessageType.SETUP /* Message type */
|
type: SearchMessageType.SETUP /* Message type */
|
||||||
data: SearchIndex | string /* Message data */
|
data: SearchIndex /* Message data */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,9 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Repo, User } from "github-types"
|
import { Repo, User } from "github-types"
|
||||||
import { Observable } from "rxjs"
|
import { Observable, from } from "rxjs"
|
||||||
import { ajax } from "rxjs/ajax"
|
import { filter, map } from "rxjs/operators"
|
||||||
import { filter, map, pluck } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { round } from "utilities"
|
import { round } from "utilities"
|
||||||
|
|
||||||
@ -44,20 +43,17 @@ import { SourceFacts } from ".."
|
|||||||
export function fetchSourceFactsFromGitHub(
|
export function fetchSourceFactsFromGitHub(
|
||||||
user: string, repo?: string
|
user: string, repo?: string
|
||||||
): Observable<SourceFacts> {
|
): Observable<SourceFacts> {
|
||||||
return ajax({
|
const url = typeof repo !== "undefined"
|
||||||
url: typeof repo !== "undefined"
|
? `https://api.github.com/repos/${user}/${repo}`
|
||||||
? `https://api.github.com/repos/${user}/${repo}`
|
: `https://api.github.com/users/${user}`
|
||||||
: `https://api.github.com/users/${user}`,
|
return from(fetch(url).then(res => res.json()))
|
||||||
responseType: "json"
|
|
||||||
})
|
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(({ status }) => status === 200),
|
filter(({ status }) => status === 200),
|
||||||
pluck("response"),
|
map(({ response }) => {
|
||||||
map(data => {
|
|
||||||
|
|
||||||
/* GitHub repository */
|
/* GitHub repository */
|
||||||
if (typeof repo !== "undefined") {
|
if (typeof repo !== "undefined") {
|
||||||
const { stargazers_count, forks_count }: Repo = data
|
const { stargazers_count, forks_count }: Repo = response
|
||||||
return [
|
return [
|
||||||
`${round(stargazers_count || 0)} Stars`,
|
`${round(stargazers_count || 0)} Stars`,
|
||||||
`${round(forks_count || 0)} Forks`
|
`${round(forks_count || 0)} Forks`
|
||||||
@ -65,7 +61,7 @@ export function fetchSourceFactsFromGitHub(
|
|||||||
|
|
||||||
/* GitHub user/organization */
|
/* GitHub user/organization */
|
||||||
} else {
|
} else {
|
||||||
const { public_repos }: User = data
|
const { public_repos }: User = response
|
||||||
return [
|
return [
|
||||||
`${round(public_repos || 0)} Repositories`
|
`${round(public_repos || 0)} Repositories`
|
||||||
]
|
]
|
||||||
|
@ -21,9 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ProjectSchema } from "gitlab"
|
import { ProjectSchema } from "gitlab"
|
||||||
import { Observable } from "rxjs"
|
import { Observable, from } from "rxjs"
|
||||||
import { ajax } from "rxjs/ajax"
|
import { filter, map } from "rxjs/operators"
|
||||||
import { filter, map, pluck } from "rxjs/operators"
|
|
||||||
|
|
||||||
import { round } from "utilities"
|
import { round } from "utilities"
|
||||||
|
|
||||||
@ -44,13 +43,11 @@ import { SourceFacts } from ".."
|
|||||||
export function fetchSourceFactsFromGitLab(
|
export function fetchSourceFactsFromGitLab(
|
||||||
base: string, project: string
|
base: string, project: string
|
||||||
): Observable<SourceFacts> {
|
): Observable<SourceFacts> {
|
||||||
return ajax({
|
const url = `https://${base}/api/v4/projects/${encodeURIComponent(project)}`
|
||||||
url: `https://${base}/api/v4/projects/${encodeURIComponent(project)}`,
|
return from(fetch(url).then(res => res.json()))
|
||||||
responseType: "json"
|
|
||||||
})
|
|
||||||
.pipe(
|
.pipe(
|
||||||
filter(({ status }) => status === 200),
|
filter(({ status }) => status === 200),
|
||||||
pluck("response"),
|
map(({ response }) => response),
|
||||||
map(({ star_count, forks_count }: ProjectSchema) => ([
|
map(({ star_count, forks_count }: ProjectSchema) => ([
|
||||||
`${round(star_count)} Stars`,
|
`${round(star_count)} Stars`,
|
||||||
`${round(forks_count)} Forks`
|
`${round(forks_count)} Forks`
|
||||||
|
Loading…
Reference in New Issue
Block a user