1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2025-02-17 18:49:21 +01:00

Merge branch 'refactor/rxjs-typescript' into feature/landing-page

This commit is contained in:
squidfunk 2020-03-29 15:28:00 +02:00
commit fa9110c2e4
24 changed files with 101 additions and 59 deletions

View File

@ -719,11 +719,13 @@ including more information regarding installation and usage:
* [Search][32] (enabled by default) * [Search][32] (enabled by default)
* [Minification][33] * [Minification][33]
* [Revision date][34] * [Revision date][34]
* [Awesome pages][35]
For further reference, the MkDocs wiki contains a list of all For further reference, the MkDocs wiki contains a list of all
[available plugins][35]. [available plugins][36].
[32]: plugins/search.md [32]: plugins/search.md
[33]: plugins/minification.md [33]: plugins/minification.md
[34]: plugins/revision-date.md [34]: plugins/revision-date.md
[35]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins [35]: plugins/awesome-pages.md
[36]: https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins

View File

@ -9,9 +9,19 @@ and is implemented using [lunr.js][2] which includes stemmers for the English
language by default, while stemmers for other languages are included with language by default, while stemmers for other languages are included with
[lunr-languages][3], both of which are integrated with this theme. [lunr-languages][3], both of which are integrated with this theme.
!!! tip "Add the [localsearch][4] plugin to support search from `file://`"
While search will not work for the `file://` protocol, as web workers and
the use of `XMLHTTPRequest` are both blocked by modern browsers for security
reasons, the [localsearch][4] plugin and @squidfunk's [iframe-worker][5]
polyfill add support for cases where this is a mandatory requirement, e.g.,
for offline use.
[1]: https://www.mkdocs.org/user-guide/configuration/#search [1]: https://www.mkdocs.org/user-guide/configuration/#search
[2]: https://lunrjs.com [2]: https://lunrjs.com
[3]: https://github.com/MihaiValentin/lunr-languages [3]: https://github.com/MihaiValentin/lunr-languages
[4]: https://github.com/wilhelmer/mkdocs-localsearch
[5]: https://github.com/squidfunk/iframe-worker
## Installation ## Installation
@ -102,7 +112,7 @@ plugins:
> Default: `false` > Default: `false`
MkDocs can generate a [prebuilt index][4] of all pages during build time, which MkDocs can generate a [prebuilt index][6] of all pages during build time, which
provides performance improvements at the cost of more bandwidth. This may be provides performance improvements at the cost of more bandwidth. This may be
beneficial for large documentation projects that are served with appropriate beneficial for large documentation projects that are served with appropriate
HTTP headers (e.g. `Content-Encoding: gzip`). HTTP headers (e.g. `Content-Encoding: gzip`).
@ -116,7 +126,7 @@ plugins:
prebuild_index: true prebuild_index: true
``` ```
[4]: https://www.mkdocs.org/user-guide/configuration/#prebuild_index [6]: https://www.mkdocs.org/user-guide/configuration/#prebuild_index
## Usage ## Usage

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

View File

@ -1,6 +1,6 @@
{ {
"assets/javascripts/bundle.js": "assets/javascripts/bundle.0ddca959.min.js", "assets/javascripts/bundle.js": "assets/javascripts/bundle.ed8df680.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.0ddca959.min.js.map", "assets/javascripts/bundle.js.map": "assets/javascripts/bundle.ed8df680.min.js.map",
"assets/javascripts/vendor.js": "assets/javascripts/vendor.c1fcc1cc.min.js", "assets/javascripts/vendor.js": "assets/javascripts/vendor.c1fcc1cc.min.js",
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.c1fcc1cc.min.js.map", "assets/javascripts/vendor.js.map": "assets/javascripts/vendor.c1fcc1cc.min.js.map",
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.3bc815f0.min.js", "assets/javascripts/worker/search.js": "assets/javascripts/worker/search.3bc815f0.min.js",

View File

@ -29,7 +29,7 @@
<meta name="author" content="{{ config.site_author }}"> <meta name="author" content="{{ config.site_author }}">
{% endif %} {% endif %}
<link rel="shortcut icon" href="{{ config.theme.favicon | url }}"> <link rel="shortcut icon" href="{{ config.theme.favicon | url }}">
<meta name="generator" content="mkdocs-{{ mkdocs_version }}, mkdocs-material-5.0.0rc3"> <meta name="generator" content="mkdocs-{{ mkdocs_version }}, mkdocs-material-5.0.0rc4">
{% endblock %} {% endblock %}
{% block htmltitle %} {% block htmltitle %}
{% if page and page.meta and page.meta.title %} {% if page and page.meta and page.meta.title %}
@ -179,7 +179,7 @@
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/vendor.c1fcc1cc.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/vendor.c1fcc1cc.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.0ddca959.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.ed8df680.min.js' | url }}"></script>
{%- set translations = {} -%} {%- set translations = {} -%}
{%- for key in [ {%- for key in [
"clipboard.copy", "clipboard.copy",

View File

@ -7,7 +7,7 @@
{% if page and page.title and not page.is_homepage %} {% if page and page.title and not page.is_homepage %}
{% set title = config.site_name ~ " - " ~ page.title | striptags %} {% set title = config.site_name ~ " - " ~ page.title | striptags %}
{% endif %} {% endif %}
{% set image = 'assets/images/illustration.png' | url %} {% set image = config.site_url ~ 'assets/images/illustration.png' %}
<meta property="og:title" content="{{ title }}"> <meta property="og:title" content="{{ title }}">
<meta property="og:description" content="{{ config.site_description }}"> <meta property="og:description" content="{{ config.site_description }}">
<meta property="og:url" content="{{ page.canonical_url }}"> <meta property="og:url" content="{{ page.canonical_url }}">
@ -20,5 +20,5 @@
<meta name="twitter:image" content="{{ image }}"> <meta name="twitter:image" content="{{ image }}">
{% endblock %} {% endblock %}
{% block announce %} {% block announce %}
Material for MkDocs 5.0.0rc3 Material for MkDocs 5.0.0rc4
{% endblock %} {% endblock %}

View File

@ -20,12 +20,12 @@
# Project information # Project information
site_name: Material for MkDocs site_name: Material for MkDocs
site_url: https://squidfunk.github.io/mkdocs-material/
site_author: Martin Donath
site_description: >- site_description: >-
Create a branded static site from a set of Markdown files to host the Create a branded static site from a set of Markdown files to host the
documentation of your Open Source or commercial project customizable, documentation of your Open Source or commercial project customizable,
searchable, mobile-friendly, 40+ languages searchable, mobile-friendly, 40+ languages
site_author: Martin Donath
site_url: https://squidfunk.github.io/mkdocs-material/
# Repository # Repository
repo_name: squidfunk/mkdocs-material repo_name: squidfunk/mkdocs-material
@ -52,7 +52,7 @@ theme:
language: en language: en
features: features:
- tabs - tabs
- instant #- instant
palette: palette:
primary: indigo primary: indigo
accent: indigo accent: indigo

14
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "mkdocs-material", "name": "mkdocs-material",
"version": "5.0.0rc3", "version": "5.0.0rc4",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1828,8 +1828,7 @@
}, },
"kind-of": { "kind-of": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", "resolved": "",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"dev": true "dev": true
} }
} }
@ -2810,8 +2809,7 @@
}, },
"minimist": { "minimist": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "resolved": "",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true "dev": true
}, },
"normalize-path": { "normalize-path": {
@ -3415,8 +3413,7 @@
}, },
"kind-of": { "kind-of": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", "resolved": "",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"dev": true "dev": true
} }
} }
@ -7773,8 +7770,7 @@
}, },
"kind-of": { "kind-of": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", "resolved": "",
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
"dev": true "dev": true
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "mkdocs-material", "name": "mkdocs-material",
"version": "5.0.0rc3", "version": "5.0.0rc4",
"description": "A Material Design theme for MkDocs", "description": "A Material Design theme for MkDocs",
"keywords": [ "keywords": [
"mkdocs", "mkdocs",

View File

@ -90,6 +90,21 @@ export function getElements<T extends HTMLElement>(
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/**
* Create an element
*
* @template T - Tag name type
*
* @param tagName - Tag name
*
* @return Element
*/
export function createElement<
T extends keyof HTMLElementTagNameMap
>(tagName: T): HTMLElementTagNameMap[T] {
return document.createElement(tagName)
}
/** /**
* Replace an element with another element * Replace an element with another element
* *

View File

@ -23,6 +23,8 @@
import { Observable, fromEvent } from "rxjs" import { Observable, fromEvent } from "rxjs"
import { filter, map, share, startWith } from "rxjs/operators" import { filter, map, share, startWith } from "rxjs/operators"
import { createElement } from "browser"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
@ -47,7 +49,7 @@ export function getLocationHash(): string {
* @param hash - Location hash * @param hash - Location hash
*/ */
export function setLocationHash(hash: string): void { export function setLocationHash(hash: string): void {
const el = document.createElement("a") const el = createElement("a")
el.href = hash el.href = hash
el.addEventListener("click", ev => ev.stopPropagation()) el.addEventListener("click", ev => ev.stopPropagation())
el.click() el.click()

View File

@ -21,7 +21,11 @@
*/ */
import { Observable, OperatorFunction, pipe } from "rxjs" import { Observable, OperatorFunction, pipe } from "rxjs"
import { distinctUntilChanged, map, switchMap } from "rxjs/operators" import {
distinctUntilKeyChanged,
map,
switchMap
} from "rxjs/operators"
import { Viewport, watchViewportAt } from "browser" import { Viewport, watchViewportAt } from "browser"
@ -69,7 +73,7 @@ export function mountHero(
switchMap(el => watchViewportAt(el, { header$, viewport$ }) switchMap(el => watchViewportAt(el, { header$, viewport$ })
.pipe( .pipe(
map(({ offset: { y } }) => ({ hidden: y >= 20 })), map(({ offset: { y } }) => ({ hidden: y >= 20 })),
distinctUntilChanged(), distinctUntilKeyChanged("hidden"),
applyHero(el) applyHero(el)
) )
) )

View File

@ -88,8 +88,8 @@ export function watchMain(
shareReplay(1) shareReplay(1)
) )
/* Compute the main area's top and bottom markers */ /* Compute the main area's top and bottom borders */
const marker$ = adjust$ const border$ = adjust$
.pipe( .pipe(
switchMap(() => watchElementSize(el) switchMap(() => watchElementSize(el)
.pipe( .pipe(
@ -104,7 +104,7 @@ export function watchMain(
) )
/* Compute the main area's offset, visible height and if we scrolled past */ /* Compute the main area's offset, visible height and if we scrolled past */
return combineLatest([adjust$, marker$, viewport$]) return combineLatest([adjust$, border$, viewport$])
.pipe( .pipe(
map(([header, { top, bottom }, { offset: { y }, size: { height } }]) => { map(([header, { top, bottom }, { offset: { y }, size: { height } }]) => {
height = Math.max(0, height height = Math.max(0, height
@ -114,7 +114,7 @@ export function watchMain(
return { return {
offset: top - header, offset: top - header,
height, height,
active: y >= top - header active: top - header <= y
} }
}), }),
distinctUntilChanged<Main>((a, b) => { distinctUntilChanged<Main>((a, b) => {

View File

@ -21,7 +21,11 @@
*/ */
import { Observable, OperatorFunction, of, pipe } from "rxjs" import { Observable, OperatorFunction, of, pipe } from "rxjs"
import { distinctUntilChanged, map, switchMap } from "rxjs/operators" import {
distinctUntilKeyChanged,
map,
switchMap
} from "rxjs/operators"
import { Viewport, watchViewportAt } from "browser" import { Viewport, watchViewportAt } from "browser"
@ -76,7 +80,7 @@ export function mountTabs(
return watchViewportAt(el, { header$, viewport$ }) return watchViewportAt(el, { header$, viewport$ })
.pipe( .pipe(
map(({ offset: { y } }) => ({ hidden: y >= 10 })), map(({ offset: { y } }) => ({ hidden: y >= 10 })),
distinctUntilChanged(), distinctUntilKeyChanged("hidden"),
applyTabs(el) applyTabs(el)
) )

View File

@ -96,7 +96,7 @@ interface MountOptions {
* @return Operator function * @return Operator function
*/ */
export function mountTableOfContents( export function mountTableOfContents(
{ header$, main$, viewport$, tablet$}: MountOptions { header$, main$, viewport$, tablet$ }: MountOptions
): OperatorFunction<HTMLElement, TableOfContents> { ): OperatorFunction<HTMLElement, TableOfContents> {
return pipe( return pipe(
switchMap(el => tablet$ switchMap(el => tablet$

View File

@ -41,7 +41,7 @@ import {
tap tap
} from "rxjs/operators" } from "rxjs/operators"
import { Viewport, getElement } from "browser" import { Viewport, getElement, watchElementSize } from "browser"
import { Header } from "../../../header" import { Header } from "../../../header"
import { AnchorList } from "../_" import { AnchorList } from "../_"
@ -106,9 +106,9 @@ export function watchAnchorList(
) )
/* Compute partition of previous and next anchors */ /* Compute partition of previous and next anchors */
const partition$ = viewport$ const partition$ = watchElementSize(document.body)
.pipe( .pipe(
distinctUntilKeyChanged("size"), distinctUntilKeyChanged("height"),
/* Build index to map anchor paths to vertical offsets */ /* Build index to map anchor paths to vertical offsets */
map(() => { map(() => {

View File

@ -29,6 +29,8 @@ import {
tap tap
} from "rxjs/operators" } from "rxjs/operators"
import { createElement } from "browser"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Types * Types
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
@ -57,7 +59,7 @@ export function setupDialog(
const dialog$ = new Subject<string>() const dialog$ = new Subject<string>()
/* Create dialog */ /* Create dialog */
const dialog = document.createElement("div") // TODO: improve scoping const dialog = createElement("div") // TODO: improve scoping
dialog.classList.add("md-dialog", "md-typeset") dialog.classList.add("md-dialog", "md-typeset")
/* Display dialog */ /* Display dialog */

View File

@ -23,7 +23,11 @@
import { Observable } from "rxjs" import { Observable } from "rxjs"
import { map, skip, withLatestFrom } from "rxjs/operators" import { map, skip, withLatestFrom } from "rxjs/operators"
import { getElements } from "browser" import {
createElement,
getElements,
replaceElement
} from "browser"
import { useComponent } from "components" import { useComponent } from "components"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
@ -63,10 +67,10 @@ export function patchScripts(
els$.subscribe(els => { els$.subscribe(els => {
for (const el of els) { for (const el of els) {
if (el.src || /(^|\/javascript)$/i.test(el.type)) { if (el.src || /(^|\/javascript)$/i.test(el.type)) {
const script = document.createElement("script") const script = createElement("script")
const key = el.src ? "src" : "textContent" const key = el.src ? "src" : "textContent"
script[key] = el[key]! script[key] = el[key]!
el.replaceWith(script) replaceElement(el, script)
} }
} }
}) })

View File

@ -23,7 +23,11 @@
import { Observable } from "rxjs" import { Observable } from "rxjs"
import { map } from "rxjs/operators" import { map } from "rxjs/operators"
import { getElements } from "browser" import {
createElement,
getElements,
replaceElement
} from "browser"
import { renderTable } from "templates" import { renderTable } from "templates"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
@ -52,15 +56,15 @@ interface MountOptions {
export function patchTables( export function patchTables(
{ document$ }: MountOptions { document$ }: MountOptions
): void { ): void {
const sentinel = document.createElement("table") const sentinel = createElement("table")
document$ document$
.pipe( .pipe(
map(() => getElements<HTMLTableElement>("table:not([class])")) map(() => getElements<HTMLTableElement>("table:not([class])"))
) )
.subscribe(els => { .subscribe(els => {
for (const el of els) { for (const el of els) {
el.replaceWith(sentinel) replaceElement(el, sentinel)
sentinel.replaceWith(renderTable(el)) replaceElement(sentinel, renderTable(el))
} }
}) })
} }

View File

@ -54,21 +54,21 @@ type Child =
/** /**
* Create an element * Create an element
* *
* @param tag - HTML or SVG tag * @param tagName - HTML or SVG tag
* *
* @return Element * @return Element
*/ */
function createElement(tag: string): HTMLElement | SVGElement { function createElement(tagName: string): HTMLElement | SVGElement {
switch (tag) { switch (tagName) {
/* SVG elements */ /* SVG elements */
case "svg": case "svg":
case "path": case "path":
return document.createElementNS("http://www.w3.org/2000/svg", tag) return document.createElementNS("http://www.w3.org/2000/svg", tagName)
/* HTML elements */ /* HTML elements */
default: default:
return document.createElement(tag) return document.createElement(tagName)
} }
} }
@ -137,16 +137,16 @@ function appendChild(
/** /**
* JSX factory * JSX factory
* *
* @param tag - HTML or SVG tag * @param tagName - HTML or SVG tag
* @param attributes - HTML attributes * @param attributes - HTML attributes
* @param children - Child elements * @param children - Child elements
* *
* @return Element * @return Element
*/ */
export function h( export function h(
tag: string, attributes: Attributes | null, ...children: Child[] tagName: string, attributes: Attributes | null, ...children: Child[]
): HTMLElement | SVGElement { ): HTMLElement | SVGElement {
const el = createElement(tag) const el = createElement(tagName)
/* Set attributes, if any */ /* Set attributes, if any */
if (attributes) if (attributes)

View File

@ -22,7 +22,6 @@
{% extends "base.html" %} {% extends "base.html" %}
<!-- Custom front matter --> <!-- Custom front matter -->
{% block extrahead %} {% block extrahead %}
@ -32,8 +31,8 @@
{% set title = config.site_name ~ " - " ~ page.title | striptags %} {% set title = config.site_name ~ " - " ~ page.title | striptags %}
{% endif %} {% endif %}
<!-- Determine image --> <!-- The image needs to have an absolute URL -->
{% set image = 'assets/images/illustration.png' | url %} {% set image = config.site_url ~ 'assets/images/illustration.png' %}
<!-- Open graph meta tags --> <!-- Open graph meta tags -->
<meta property="og:title" content="{{ title }}" /> <meta property="og:title" content="{{ title }}" />
@ -52,5 +51,5 @@
<!-- Announcement bar --> <!-- Announcement bar -->
{% block announce %} {% block announce %}
Material for MkDocs 5.0.0rc3 Material for MkDocs 5.0.0rc4
{% endblock %} {% endblock %}