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

Merge of Insiders features tied to 'Black Pearl' funding goal

This commit is contained in:
squidfunk 2021-03-29 18:46:57 +02:00
parent 8677190f3f
commit ca3da9e3ca
51 changed files with 867 additions and 194 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

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

View File

@ -39,10 +39,10 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.c772ddf0.min.css' | url }}"> <link rel="stylesheet" href="{{ 'assets/stylesheets/main.33e2939f.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.7fa14f5b.min.css' | url }}"> <link rel="stylesheet" href="{{ 'assets/stylesheets/palette.ef6f36e2.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(
@ -87,13 +87,14 @@
{% set primary = palette.primary | replace(" ", "-") | lower %} {% set primary = palette.primary | replace(" ", "-") | lower %}
{% set accent = palette.accent | replace(" ", "-") | lower %} {% set accent = palette.accent | replace(" ", "-") | lower %}
<body dir="{{ direction }}" data-md-color-scheme="{{ scheme }}" data-md-color-primary="{{ primary }}" data-md-color-accent="{{ accent }}"> <body dir="{{ direction }}" data-md-color-scheme="{{ scheme }}" data-md-color-primary="{{ primary }}" data-md-color-accent="{{ accent }}">
{% if "preference" == scheme %}
<script>matchMedia("(prefers-color-scheme: dark)").matches&&document.body.setAttribute("data-md-color-scheme","slate")</script>
{% endif %}
{% else %} {% else %}
<body dir="{{ direction }}"> <body dir="{{ direction }}">
{% endif %} {% endif %}
{% set features = config.theme.features or [] %} {% set features = config.theme.features or [] %}
{% include "partials/javascripts/base.html" %}
{% if not config.theme.palette is mapping %}
{% include "partials/javascripts/palette.html" %}
{% endif %}
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off"> <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off"> <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label> <label class="md-overlay" for="__drawer"></label>
@ -178,6 +179,11 @@
</article> </article>
</div> </div>
</div> </div>
{% if "navigation.top" in features %}
<a href="#" class="md-top md-icon" data-md-component="top" data-md-state="hidden">
{% include ".icons/material/arrow-up.svg" %}
</a>
{% endif %}
</main> </main>
{% block footer %} {% block footer %}
{% include "partials/footer.html" %} {% include "partials/footer.html" %}
@ -217,7 +223,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.65ce87ac.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.d892486b.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %} {% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script> <script src="{{ path | url }}"></script>
{% endfor %} {% endfor %}

View File

@ -35,5 +35,5 @@
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script src="{{ 'overrides/assets/javascripts/bundle.afdf7228.min.js' | url }}"></script> <script src="{{ 'overrides/assets/javascripts/bundle.3b3ca511.min.js' | url }}"></script>
{% endblock %} {% endblock %}

View File

@ -27,8 +27,20 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-header__options"> {% if not config.theme.palette is mapping %}
<form class="md-header__option" data-md-component="palette">
{% for option in config.theme.palette %}
{% set primary = option.primary | replace(" ", "-") | lower %}
{% set accent = option.accent | replace(" ", "-") | lower %}
<input class="md-option" data-md-color-media="{{ option.media }}" data-md-color-scheme="{{ option.scheme }}" data-md-color-primary="{{ primary }}" data-md-color-accent="{{ accent }}" type="radio" name="__palette" id="__palette_{{ loop.index }}">
<label class="md-header__button md-icon" title="{{ option.toggle.name }}" for="__palette_{{ loop.index0 or loop.length }}" hidden>
{% include ".icons/" ~ option.toggle.icon ~ ".svg" %}
</label>
{% endfor %}
</form>
{% endif %}
{% if config.extra.alternate %} {% if config.extra.alternate %}
<div class="md-header__option">
<div class="md-select"> <div class="md-select">
{% set icon = config.theme.icon.alternate or "material/translate" %} {% set icon = config.theme.icon.alternate or "material/translate" %}
<span class="md-header__button md-icon"> <span class="md-header__button md-icon">
@ -46,8 +58,8 @@
</ul> </ul>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
{% endif %}
{% if "search" in config["plugins"] %} {% if "search" in config["plugins"] %}
<label class="md-header__button md-icon" for="__search"> <label class="md-header__button md-icon" for="__search">
{% include ".icons/material/magnify.svg" %} {% include ".icons/material/magnify.svg" %}

View File

@ -0,0 +1,4 @@
{#-
This file was automatically generated - do not edit
-#}
<script>function __prefix(e){return new URL("{{ base_url }}",location).pathname+"."+e}function __get(e,t=localStorage){return JSON.parse(t.getItem(__prefix(e)))}</script>

View File

@ -0,0 +1,4 @@
{#-
This file was automatically generated - do not edit
-#}
<script>var palette=__get("__palette");if(null!==palette&&"object"==typeof palette.color)for(var key in palette.color)document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>

View File

@ -55,9 +55,20 @@ theme:
- navigation.sections - navigation.sections
- navigation.tabs - navigation.tabs
palette: palette:
- media: "(prefers-color-scheme: light)"
scheme: default scheme: default
primary: indigo primary: indigo
accent: indigo accent: indigo
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
primary: red
accent: red
toggle:
icon: material/toggle-switch
name: Switch to light mode
font: font:
text: Roboto text: Roboto
code: Roboto Mono code: Roboto Mono

View File

@ -35,6 +35,7 @@ export type Flag =
| "navigation.instant" /* Instant loading */ | "navigation.instant" /* Instant loading */
| "navigation.sections" /* Sections navigation */ | "navigation.sections" /* Sections navigation */
| "navigation.tabs" /* Tabs navigation */ | "navigation.tabs" /* Tabs navigation */
| "navigation.top" /* Back-to-top button */
| "toc.integrate" /* Integrated table of contents */ | "toc.integrate" /* Integrated table of contents */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */

View File

@ -28,3 +28,4 @@ export * from "./search"
export * from "./sidebar" export * from "./sidebar"
export * from "./source" export * from "./source"
export * from "./tabs" export * from "./tabs"
export * from "./top"

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Set back-to-top state
*
* @param el - Back-to-top element
* @param state - Back-to-top state
*/
export function setBackToTopState(
el: HTMLElement, state: "hidden"
): void {
el.setAttribute("data-md-state", state)
}
/**
* Reset back-to-top state
*
* @param el - Back-to-top element
*/
export function resetBackToTopState(
el: HTMLElement
): void {
el.removeAttribute("data-md-state")
}

View File

@ -43,7 +43,7 @@ import {
export function request( export function request(
url: URL | string, options: RequestInit = { credentials: "same-origin" } url: URL | string, options: RequestInit = { credentials: "same-origin" }
): Observable<Response> { ): Observable<Response> {
return from(fetch(url.toString(), options)) return from(fetch(`${url}`, options))
.pipe( .pipe(
filter(res => res.status === 200), filter(res => res.status === 200),
) )

View File

@ -48,10 +48,12 @@ import {
import { import {
getComponentElement, getComponentElement,
getComponentElements, getComponentElements,
mountBackToTop,
mountContent, mountContent,
mountDialog, mountDialog,
mountHeader, mountHeader,
mountHeaderTitle, mountHeaderTitle,
mountPalette,
mountSearch, mountSearch,
mountSidebar, mountSidebar,
mountSource, mountSource,
@ -173,17 +175,17 @@ const control$ = merge(
...getComponentElements("header") ...getComponentElements("header")
.map(el => mountHeader(el, { viewport$, header$, main$ })), .map(el => mountHeader(el, { viewport$, header$, main$ })),
/* Color palette */
...getComponentElements("palette")
.map(el => mountPalette(el)),
/* Search */ /* Search */
...getComponentElements("search") ...getComponentElements("search")
.map(el => mountSearch(el, { index$, keyboard$ })), .map(el => mountSearch(el, { index$, keyboard$ })),
/* Repository information */ /* Repository information */
...getComponentElements("source") ...getComponentElements("source")
.map(el => mountSource(el)), .map(el => mountSource(el))
/* Navigation tabs */
...getComponentElements("tabs")
.map(el => mountTabs(el, { viewport$, header$ })),
) )
/* Set up content component observables */ /* Set up content component observables */
@ -204,9 +206,17 @@ const content$ = defer(() => merge(
: at(tablet$, () => mountSidebar(el, { viewport$, header$, main$ })) : at(tablet$, () => mountSidebar(el, { viewport$, header$, main$ }))
), ),
/* Navigation tabs */
...getComponentElements("tabs")
.map(el => mountTabs(el, { viewport$, header$ })),
/* Table of contents */ /* Table of contents */
...getComponentElements("toc") ...getComponentElements("toc")
.map(el => mountTableOfContents(el, { viewport$, header$ })), .map(el => mountTableOfContents(el, { viewport$, header$ })),
/* Back-to-top button */
...getComponentElements("top")
.map(el => mountBackToTop(el, { viewport$, main$ }))
)) ))
/* Set up component observables */ /* Set up component observables */

View File

@ -38,6 +38,7 @@ export type ComponentType =
| "header-title" /* Header title */ | "header-title" /* Header title */
| "header-topic" /* Header topic */ | "header-topic" /* Header topic */
| "main" /* Main area */ | "main" /* Main area */
| "palette" /* Color palette */
| "search" /* Search */ | "search" /* Search */
| "search-query" /* Search input */ | "search-query" /* Search input */
| "search-result" /* Search results */ | "search-result" /* Search results */
@ -46,6 +47,7 @@ export type ComponentType =
| "source" /* Repository information */ | "source" /* Repository information */
| "tabs" /* Navigation tabs */ | "tabs" /* Navigation tabs */
| "toc" /* Table of contents */ | "toc" /* Table of contents */
| "top" /* Back-to-top button */
/** /**
* A component * A component
@ -77,6 +79,7 @@ interface ComponentTypeMap {
"header-title": HTMLElement /* Header title */ "header-title": HTMLElement /* Header title */
"header-topic": HTMLElement /* Header topic */ "header-topic": HTMLElement /* Header topic */
"main": HTMLElement /* Main area */ "main": HTMLElement /* Main area */
"palette": HTMLElement /* Color palette */
"search": HTMLElement /* Search */ "search": HTMLElement /* Search */
"search-query": HTMLInputElement /* Search input */ "search-query": HTMLInputElement /* Search input */
"search-result": HTMLElement /* Search results */ "search-result": HTMLElement /* Search results */
@ -85,6 +88,7 @@ interface ComponentTypeMap {
"source": HTMLAnchorElement /* Repository information */ "source": HTMLAnchorElement /* Repository information */
"tabs": HTMLElement /* Navigation tabs */ "tabs": HTMLElement /* Navigation tabs */
"toc": HTMLElement /* Table of contents */ "toc": HTMLElement /* Table of contents */
"top": HTMLAnchorElement /* Back-to-top button */
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------

View File

@ -22,4 +22,5 @@
export * from "./_" export * from "./_"
export * from "./code" export * from "./code"
export * from "./details"
export * from "./table" export * from "./table"

View File

@ -120,7 +120,7 @@ function isHidden({ viewport$ }: WatchOptions): Observable<boolean> {
distinctUntilChanged() distinctUntilChanged()
) )
/* Compute threshold for autohiding */ /* Compute threshold for hiding */
const search$ = watchToggle("search") const search$ = watchToggle("search")
return combineLatest([viewport$, search$]) return combineLatest([viewport$, search$])
.pipe( .pipe(

View File

@ -25,8 +25,10 @@ export * from "./content"
export * from "./dialog" export * from "./dialog"
export * from "./header" export * from "./header"
export * from "./main" export * from "./main"
export * from "./palette"
export * from "./search" export * from "./search"
export * from "./sidebar" export * from "./sidebar"
export * from "./source" export * from "./source"
export * from "./tabs" export * from "./tabs"
export * from "./toc" export * from "./toc"
export * from "./top"

View File

@ -0,0 +1,147 @@
/*
* Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
import {
Observable,
Subject,
fromEvent,
of
} from "rxjs"
import {
finalize,
map,
mapTo,
mergeMap,
shareReplay,
startWith,
tap
} from "rxjs/operators"
import { getElements } from "~/browser"
import { Component } from "../_"
/* ----------------------------------------------------------------------------
* Types
* ------------------------------------------------------------------------- */
/**
* Palette colors
*/
export interface PaletteColor {
scheme?: string /* Color scheme */
primary?: string /* Primary color */
accent?: string /* Accent color */
}
/**
* Palette
*/
export interface Palette {
index: number /* Palette index */
color: PaletteColor /* Palette colors */
}
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Watch color palette
*
* @param inputs - Color palette element
*
* @returns Color palette observable
*/
export function watchPalette(
inputs: HTMLInputElement[]
): Observable<Palette> {
const data = localStorage.getItem(__prefix("__palette"))!
const current = JSON.parse(data) || {
index: inputs.findIndex(input => (
matchMedia(input.getAttribute("data-md-color-media")!).matches
))
}
/* Emit changes in color palette */
const palette$ = of(...inputs)
.pipe(
mergeMap(input => fromEvent(input, "change")
.pipe(
mapTo(input)
)
),
startWith(inputs[Math.max(0, current.index)]),
map(input => ({
index: inputs.indexOf(input),
color: {
scheme: input.getAttribute("data-md-color-scheme"),
primary: input.getAttribute("data-md-color-primary"),
accent: input.getAttribute("data-md-color-accent")
}
} as Palette)),
shareReplay(1)
)
/* Persist preference in local storage */
palette$.subscribe(palette => {
localStorage.setItem(__prefix("__palette"), JSON.stringify(palette))
})
/* Return palette */
return palette$
}
/**
* Mount color palette
*
* @param el - Color palette element
*
* @returns Color palette component observable
*/
export function mountPalette(
el: HTMLElement
): Observable<Component<Palette>> {
const internal$ = new Subject<Palette>()
/* Set color palette */
internal$.subscribe(palette => {
for (const [key, value] of Object.entries(palette.color))
if (typeof value === "string")
document.body.setAttribute(`data-md-color-${key}`, value)
/* Toggle visibility */
for (let index = 0; index < inputs.length; index++) {
const label = inputs[index].nextElementSibling as HTMLElement
label.hidden = palette.index !== index
}
})
/* Create and return component */
const inputs = getElements<HTMLInputElement>("input", el)
return watchPalette(inputs)
.pipe(
tap(internal$),
finalize(() => internal$.complete()),
map(state => ({ ref: el, ...state }))
)
}

View File

@ -32,7 +32,6 @@ import {
import { setSourceFacts, setSourceState } from "~/actions" import { setSourceFacts, setSourceState } from "~/actions"
import { renderSourceFacts } from "~/templates" import { renderSourceFacts } from "~/templates"
import { digest } from "~/utilities"
import { Component } from "../../_" import { Component } from "../../_"
import { SourceFacts, fetchSourceFacts } from "../facts" import { SourceFacts, fetchSourceFacts } from "../facts"
@ -75,14 +74,14 @@ export function watchSource(
el: HTMLAnchorElement el: HTMLAnchorElement
): Observable<Source> { ): Observable<Source> {
return fetch$ ||= defer(() => { return fetch$ ||= defer(() => {
const data = sessionStorage.getItem(digest("__repo")) const data = sessionStorage.getItem(__prefix("__source"))
if (data) { if (data) {
return of<SourceFacts>(JSON.parse(data)) return of<SourceFacts>(JSON.parse(data))
} else { } else {
const value$ = fetchSourceFacts(el.href) const value$ = fetchSourceFacts(el.href)
value$.subscribe(value => { value$.subscribe(value => {
try { try {
sessionStorage.setItem(digest("__repo"), JSON.stringify(value)) sessionStorage.setItem(__prefix("__source"), JSON.stringify(value))
} catch (err) { } catch (err) {
/* Uncritical, just swallow */ /* Uncritical, just swallow */
} }
@ -94,7 +93,7 @@ export function watchSource(
}) })
.pipe( .pipe(
catchError(() => NEVER), catchError(() => NEVER),
filter(facts => facts.length > 0), filter(facts => Object.keys(facts).length > 0),
map(facts => ({ facts })), map(facts => ({ facts })),
shareReplay(1) shareReplay(1)
) )

View File

@ -29,10 +29,30 @@ import { fetchSourceFactsFromGitLab } from "../gitlab"
* Types * Types
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/**
* Repository facts for repositories
*/
export interface RepositoryFacts {
stars?: number /* Number of stars */
forks?: number /* Number of forks */
version?: string /* Latest version */
}
/**
* Repository facts for organizations
*/
export interface OrganizationFacts {
repositories?: number /* Number of repositories */
}
/* ------------------------------------------------------------------------- */
/** /**
* Repository facts * Repository facts
*/ */
export type SourceFacts = string[] export type SourceFacts =
| RepositoryFacts
| OrganizationFacts
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions

View File

@ -21,14 +21,24 @@
*/ */
import { Repo, User } from "github-types" import { Repo, User } from "github-types"
import { Observable } from "rxjs" import { Observable, zip } from "rxjs"
import { defaultIfEmpty, map } from "rxjs/operators" import { defaultIfEmpty, map } from "rxjs/operators"
import { requestJSON } from "~/browser" import { requestJSON } from "~/browser"
import { round } from "~/utilities"
import { SourceFacts } from "../_" import { SourceFacts } from "../_"
/* ----------------------------------------------------------------------------
* Helper types
* ------------------------------------------------------------------------- */
/**
* GitHub release (partial)
*/
interface Release {
tag_name: string /* Tag name */
}
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
@ -44,29 +54,42 @@ import { SourceFacts } from "../_"
export function fetchSourceFactsFromGitHub( export function fetchSourceFactsFromGitHub(
user: string, repo?: string user: string, repo?: string
): Observable<SourceFacts> { ): Observable<SourceFacts> {
const url = typeof repo !== "undefined"
? `https://api.github.com/repos/${user}/${repo}`
: `https://api.github.com/users/${user}`
return requestJSON<Repo & User>(url)
.pipe(
map(data => {
/* GitHub repository */
if (typeof repo !== "undefined") { if (typeof repo !== "undefined") {
const { stargazers_count, forks_count }: Repo = data const url = `https://api.github.com/repos/${user}/${repo}`
return [ return zip(
`${round(stargazers_count!)} Stars`,
`${round(forks_count!)} Forks`
]
/* GitHub user/organization */ /* Fetch version */
} else { requestJSON<Release>(`${url}/releases/latest`)
const { public_repos }: User = data .pipe(
return [ map(release => ({
`${round(public_repos!)} Repositories` version: release.tag_name
] })),
} defaultIfEmpty({})
}), ),
defaultIfEmpty([])
/* Fetch stars and forks */
requestJSON<Repo>(url)
.pipe(
map(info => ({
stars: info.stargazers_count,
forks: info.forks_count
})),
defaultIfEmpty({})
) )
)
.pipe(
map(([release, info]) => ({ ...release, ...info }))
)
/* User or organization */
} else {
const url = `https://api.github.com/repos/${user}`
return requestJSON<User>(url)
.pipe(
map(info => ({
repositories: info.public_repos
})),
defaultIfEmpty({})
)
}
} }

View File

@ -25,7 +25,6 @@ import { Observable } from "rxjs"
import { defaultIfEmpty, map } from "rxjs/operators" import { defaultIfEmpty, map } from "rxjs/operators"
import { requestJSON } from "~/browser" import { requestJSON } from "~/browser"
import { round } from "~/utilities"
import { SourceFacts } from "../_" import { SourceFacts } from "../_"
@ -47,10 +46,10 @@ export function fetchSourceFactsFromGitLab(
const url = `https://${base}/api/v4/projects/${encodeURIComponent(project)}` const url = `https://${base}/api/v4/projects/${encodeURIComponent(project)}`
return requestJSON<ProjectSchema>(url) return requestJSON<ProjectSchema>(url)
.pipe( .pipe(
map(({ star_count, forks_count }) => ([ map(({ star_count, forks_count }) => ({
`${round(star_count)} Stars`, stars: star_count,
`${round(forks_count)} Forks` forks: forks_count
])), })),
defaultIfEmpty([]) defaultIfEmpty({})
) )
} }

View File

@ -26,11 +26,16 @@ import {
finalize, finalize,
map, map,
observeOn, observeOn,
switchMap,
tap tap
} from "rxjs/operators" } from "rxjs/operators"
import { resetTabsState, setTabsState } from "~/actions" import { resetTabsState, setTabsState } from "~/actions"
import { Viewport, watchViewportAt } from "~/browser" import {
Viewport,
watchElementSize,
watchViewportAt
} from "~/browser"
import { Component } from "../_" import { Component } from "../_"
import { Header } from "../header" import { Header } from "../header"
@ -81,8 +86,9 @@ interface MountOptions {
export function watchTabs( export function watchTabs(
el: HTMLElement, { viewport$, header$ }: WatchOptions el: HTMLElement, { viewport$, header$ }: WatchOptions
): Observable<Tabs> { ): Observable<Tabs> {
return watchViewportAt(el, { header$, viewport$ }) return watchElementSize(document.body)
.pipe( .pipe(
switchMap(() => watchViewportAt(el, { header$, viewport$ })),
map(({ offset: { y } }) => { map(({ offset: { y } }) => {
return { return {
hidden: y >= 10 hidden: y >= 10

View File

@ -0,0 +1,160 @@
/*
* Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
import {
Observable,
Subject,
animationFrameScheduler,
combineLatest
} from "rxjs"
import {
bufferCount,
distinctUntilChanged,
distinctUntilKeyChanged,
finalize,
map,
observeOn,
tap
} from "rxjs/operators"
import { resetBackToTopState, setBackToTopState } from "~/actions"
import { Viewport } from "~/browser"
import { Component } from "../_"
import { Main } from "../main"
/* ----------------------------------------------------------------------------
* Types
* ------------------------------------------------------------------------- */
/**
* Back-to-top button
*/
export interface BackToTop {
hidden: boolean /* User scrolled up */
}
/* ----------------------------------------------------------------------------
* Helper types
* ------------------------------------------------------------------------- */
/**
* Watch options
*/
interface WatchOptions {
viewport$: Observable<Viewport> /* Viewport observable */
main$: Observable<Main> /* Main area observable */
}
/**
* Mount options
*/
interface MountOptions {
viewport$: Observable<Viewport> /* Viewport observable */
main$: Observable<Main> /* Main area observable */
}
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Watch back-to-top
*
* @param _el - Back-to-top element
* @param options - Options
*
* @returns Back-to-top observable
*/
export function watchBackToTop(
_el: HTMLElement, { viewport$, main$ }: WatchOptions
): Observable<BackToTop> {
/* Compute direction */
const direction$ = viewport$
.pipe(
map(({ offset: { y } }) => y),
bufferCount(2, 1),
map(([a, b]) => a > b),
distinctUntilChanged()
)
/* Compute whether button should be hidden */
const hidden$ = main$
.pipe(
distinctUntilKeyChanged("active")
)
/* Compute threshold for hiding */
return combineLatest([hidden$, direction$])
.pipe(
map(([{ active }, direction]) => ({
hidden: !(active && direction)
})),
distinctUntilChanged((a, b) => (
a.hidden === b.hidden
))
)
}
/* ------------------------------------------------------------------------- */
/**
* Mount back-to-top
*
* @param el - Back-to-top element
* @param options - Options
*
* @returns Back-to-top component observable
*/
export function mountBackToTop(
el: HTMLElement, options: MountOptions
): Observable<Component<BackToTop>> {
const internal$ = new Subject<BackToTop>()
internal$
.pipe(
observeOn(animationFrameScheduler)
)
.subscribe({
/* Update state */
next({ hidden }) {
if (hidden)
setBackToTopState(el, "hidden")
else
resetBackToTopState(el)
},
/* Reset on complete */
complete() {
resetBackToTopState(el)
}
})
/* Create and return component */
return watchBackToTop(el, options)
.pipe(
tap(internal$),
finalize(() => internal$.complete()),
map(state => ({ ref: el, ...state }))
)
}

View File

@ -240,7 +240,7 @@ export function setupInstantLoading(
sample(response$) sample(response$)
) )
.subscribe(({ url }) => { .subscribe(({ url }) => {
history.pushState({}, "", url.toString()) history.pushState({}, "", `${url}`)
}) })
/* Parse and emit fetched document */ /* Parse and emit fetched document */
@ -274,14 +274,14 @@ export function setupInstantLoading(
/* Meta tags */ /* Meta tags */
"title", "title",
"link[rel='canonical']", "link[rel=canonical]",
"meta[name='author']", "meta[name=author]",
"meta[name='description']", "meta[name=description]",
/* Components */ /* Components */
"[data-md-component=announce]", "[data-md-component=announce]",
"[data-md-component=header-topic]",
"[data-md-component=container]", "[data-md-component=container]",
"[data-md-component=header-topic]",
"[data-md-component=logo], .md-logo", // compat "[data-md-component=logo], .md-logo", // compat
"[data-md-component=skip]" "[data-md-component=skip]"
]) { ]) {

View File

@ -21,7 +21,7 @@
*/ */
import { SourceFacts } from "~/components" import { SourceFacts } from "~/components"
import { h } from "~/utilities" import { h, round } from "~/utilities"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions
@ -37,8 +37,10 @@ import { h } from "~/utilities"
export function renderSourceFacts(facts: SourceFacts): HTMLElement { export function renderSourceFacts(facts: SourceFacts): HTMLElement {
return ( return (
<ul class="md-source__facts"> <ul class="md-source__facts">
{facts.map(fact => ( {Object.entries(facts).map(([key, value]) => (
<li class="md-source__fact">{fact}</li> <li class={`md-source__fact md-source__fact--${key}`}>
{typeof value === "number" ? round(value) : value}
</li>
))} ))}
</ul> </ul>
) )

View File

@ -20,8 +20,6 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
import { configuration } from "~/_"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
@ -90,18 +88,3 @@ export function hash(value: string): number {
} }
return h return h
} }
/**
* Add a digest to a value to ensure uniqueness
*
* When a single account hosts multiple sites on the same GitHub Pages domain,
* entries would collide, because session and local storage are not unique.
*
* @param value - Value
*
* @returns Value with digest
*/
export function digest(value: string): string {
const config = configuration()
return `${value}[${hash(config.base)}]`
}

View File

@ -55,6 +55,7 @@
@import "main/layout/sidebar"; @import "main/layout/sidebar";
@import "main/layout/source"; @import "main/layout/source";
@import "main/layout/tabs"; @import "main/layout/tabs";
@import "main/layout/top";
@import "main/layout/version"; @import "main/layout/version";
@import "main/extensions/markdown/admonition"; @import "main/extensions/markdown/admonition";

View File

@ -121,12 +121,31 @@ body {
// Rules: navigational elements // Rules: navigational elements
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Toggle - this class is applied to the checkbox elements, which are used to // Toggle - this class is applied to checkbox elements, which are used to
// implement the CSS-only drawer and navigation, as well as the search // implement the CSS-only drawer and navigation, as well as the search
.md-toggle { .md-toggle {
display: none; display: none;
} }
// Option - this class is applied to radio elements, which are used to
// implement the color palette toggle
.md-option {
position: absolute;
width: 0;
height: 0;
opacity: 0;
// Option label for checked radio button
&:checked + label:not([hidden]) {
display: block;
}
// Option label on focus
&.focus-visible + label {
outline-style: auto;
}
}
// Skip link // Skip link
.md-skip { .md-skip {
position: fixed; position: fixed;

View File

@ -39,9 +39,6 @@
box-shadow: box-shadow:
0 0 px2rem(4px) rgba(0, 0, 0, 0), 0 0 px2rem(4px) rgba(0, 0, 0, 0),
0 px2rem(4px) px2rem(8px) rgba(0, 0, 0, 0); 0 px2rem(4px) px2rem(8px) rgba(0, 0, 0, 0);
transition:
color 250ms,
background-color 250ms;
// [print]: Hide header // [print]: Hide header
@media print { @media print {
@ -55,8 +52,6 @@
0 px2rem(4px) px2rem(8px) rgba(0, 0, 0, 0.2); 0 px2rem(4px) px2rem(8px) rgba(0, 0, 0, 0.2);
transition: transition:
transform 250ms cubic-bezier(0.1, 0.7, 0.1, 1), transform 250ms cubic-bezier(0.1, 0.7, 0.1, 1),
color 250ms,
background-color 250ms,
box-shadow 250ms; box-shadow 250ms;
} }
@ -65,11 +60,14 @@
transform: translateY(-100%); transform: translateY(-100%);
transition: transition:
transform 250ms cubic-bezier(0.8, 0, 0.6, 1), transform 250ms cubic-bezier(0.8, 0, 0.6, 1),
color 250ms,
background-color 250ms,
box-shadow 250ms; box-shadow 250ms;
} }
// Link or button on focus
.focus-visible {
outline-color: currentColor;
}
// Header wrapper // Header wrapper
&__inner { &__inner {
display: flex; display: flex;
@ -81,7 +79,6 @@
&__button { &__button {
position: relative; position: relative;
z-index: 1; z-index: 1;
display: inline-block;
margin: px2rem(4px); margin: px2rem(4px);
padding: px2rem(8px); padding: px2rem(8px);
color: currentColor; color: currentColor;
@ -89,15 +86,20 @@
cursor: pointer; cursor: pointer;
transition: opacity 250ms; transition: opacity 250ms;
// Button on focus/hover // Button on hover
&:focus,
&:hover { &:hover {
opacity: 0.7; opacity: 0.7;
} }
// Header button is visible
&:not([hidden]) {
display: inline-block;
}
// Hide outline for pointer devices // Hide outline for pointer devices
&:not(.focus-visible) { &:not(.focus-visible) {
outline: none; outline: none;
-webkit-tap-highlight-color: transparent;
} }
// Button with logo, pointing to `config.site_url` // Button with logo, pointing to `config.site_url`
@ -223,8 +225,8 @@
} }
} }
// Header options // Header option
&__options { &__option {
display: flex; display: flex;
flex-shrink: 0; flex-shrink: 0;
max-width: 100%; max-width: 100%;
@ -233,11 +235,6 @@
max-width 0ms 250ms, max-width 0ms 250ms,
opacity 250ms 250ms; opacity 250ms 250ms;
// Hide inactive buttons
> [data-md-state="hidden"] {
display: none;
}
// Hide toggle when search is active // Hide toggle when search is active
[data-md-toggle="search"]:checked ~ .md-header & { [data-md-toggle="search"]:checked ~ .md-header & {
max-width: 0; max-width: 0;

View File

@ -56,6 +56,16 @@
// Rules // Rules
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Icon definitions
:root {
--md-source-forks-icon: svg-load("octicons/repo-forked-16.svg");
--md-source-repositories-icon: svg-load("octicons/repo-16.svg");
--md-source-stars-icon: svg-load("octicons/star-16.svg");
--md-source-version-icon: svg-load("octicons/tag-16.svg");
}
// ----------------------------------------------------------------------------
// Repository information // Repository information
.md-source { .md-source {
display: block; display: block;
@ -66,8 +76,7 @@
backface-visibility: hidden; backface-visibility: hidden;
transition: opacity 250ms; transition: opacity 250ms;
// Repository information on focus/hover // Repository information on hover
&:focus,
&:hover { &:hover {
opacity: 0.7; opacity: 0.7;
} }
@ -75,7 +84,7 @@
// Repository icon // Repository icon
&__icon { &__icon {
display: inline-block; display: inline-block;
width: px2rem(48px); width: px2rem(40px);
height: px2rem(48px); height: px2rem(48px);
vertical-align: middle; vertical-align: middle;
@ -112,17 +121,15 @@
max-width: calc(100% - #{px2rem(24px)}); max-width: calc(100% - #{px2rem(24px)});
margin-left: px2rem(12px); margin-left: px2rem(12px);
overflow: hidden; overflow: hidden;
font-weight: 700;
text-overflow: ellipsis; text-overflow: ellipsis;
vertical-align: middle; vertical-align: middle;
} }
// Repository facts // Repository facts
&__facts { &__facts {
margin: 0; margin: px2rem(2px) 0 0;
padding: 0; padding: 0;
overflow: hidden; overflow: hidden;
font-weight: 700;
font-size: px2rem(11px); font-size: px2rem(11px);
list-style-type: none; list-style-type: none;
opacity: 0.75; opacity: 0.75;
@ -135,27 +142,61 @@
// Repository fact // Repository fact
&__fact { &__fact {
float: left; display: inline-block;
// Adjust for right-to-left languages
[dir="rtl"] & {
float: right;
}
// Show after the data was loaded // Show after the data was loaded
[data-md-state="done"] & { [data-md-state="done"] & {
animation: md-source__fact--done 400ms ease-out; animation: md-source__fact--done 400ms ease-out;
} }
// Middle dot before fact // Repository fact icon
&::before { &::before {
margin: 0 px2rem(2px); display: inline-block;
content: "\00B7"; width: px2rem(12px);
height: px2rem(12px);
margin-right: px2rem(2px);
vertical-align: text-top;
background-color: currentColor;
mask-repeat: no-repeat;
mask-size: contain;
content: "";
} }
// Remove middle dot on first fact // Adjust spacing for repository fact icon
&:first-child::before { &:nth-child(1n+2)::before {
display: none; margin-left: px2rem(8px);
}
// Adjust for right-to-left languages
[dir="rtl"] & {
margin-right: initial;
margin-left: px2rem(2px);
// Adjust spacing for repository fact icon
&:nth-child(1n+2)::before {
margin-right: px2rem(8px);
margin-left: initial;
}
}
// Repository fact: version
&--version::before {
mask-image: var(--md-source-version-icon);
}
// Repository fact: stars
&--stars::before {
mask-image: var(--md-source-stars-icon);
}
// Repository fact: forks
&--forks::before {
mask-image: var(--md-source-forks-icon);
}
// Repository fact: repositories
&--repositories::before {
mask-image: var(--md-source-repositories-icon);
} }
} }
} }

View File

@ -30,7 +30,6 @@
overflow: auto; overflow: auto;
color: var(--md-primary-bg-color); color: var(--md-primary-bg-color);
background-color: var(--md-primary-fg-color); background-color: var(--md-primary-fg-color);
transition: background-color 250ms;
// [print]: Hide tabs // [print]: Hide tabs
@media print { @media print {

View File

@ -0,0 +1,65 @@
////
/// Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS
////
// ----------------------------------------------------------------------------
// Rules
// ----------------------------------------------------------------------------
// Back-to-top button
.md-top {
position: sticky;
bottom: px2rem(8px);
z-index: 1;
float: right;
margin: px2rem(-56px) px2rem(8px) px2rem(8px);
padding: px2rem(8px);
color: var(--md-primary-bg-color);
background: var(--md-primary-fg-color);
border-radius: 100%;
outline: none;
box-shadow:
0 px2rem(4px) px2rem(10px) hsla(0, 0%, 0%, 0.1),
0 px2rem(0.5px) px2rem(1px) hsla(0, 0%, 0%, 0.1);
transform: translateY(0);
transition:
opacity 125ms,
transform 125ms cubic-bezier(0.4, 0, 0.2, 1),
background-color 125ms;
// Adjust for right-to-left languages
[dir="rtl"] & {
float: left;
}
// Back-to-top button in hidden state
&[data-md-state="hidden"] {
transform: translateY(px2rem(-4px));
opacity: 0;
}
// Back-to-top button on focus/hover
&:focus,
&:hover {
background: var(--md-accent-fg-color);
transform: scale(1.1);
}
}

View File

@ -57,9 +57,16 @@
--md-code-hl-constant-color: hsla(250, 62%, 70%, 1); --md-code-hl-constant-color: hsla(250, 62%, 70%, 1);
--md-code-hl-keyword-color: hsla(219, 66%, 64%, 1); --md-code-hl-keyword-color: hsla(219, 66%, 64%, 1);
--md-code-hl-string-color: hsla(150, 58%, 44%, 1); --md-code-hl-string-color: hsla(150, 58%, 44%, 1);
--md-code-hl-name-color: var(--md-code-fg-color);
--md-code-hl-operator-color: var(--md-default-fg-color--light);
--md-code-hl-punctuation-color: var(--md-default-fg-color--light);
--md-code-hl-comment-color: var(--md-default-fg-color--light);
--md-code-hl-generic-color: var(--md-default-fg-color--light);
--md-code-hl-variable-color: var(--md-default-fg-color--light);
// Typeset color shades // Typeset color shades
--md-typeset-a-color: var(--md-primary-fg-color--light); --md-typeset-color: var(--md-default-fg-color);
--md-typeset-a-color: var(--md-primary-fg-color);
// Typeset `mark` color shades // Typeset `mark` color shades
--md-typeset-mark-color: hsla(#{hex2hsl($clr-blue-a200)}, 0.3); --md-typeset-mark-color: hsla(#{hex2hsl($clr-blue-a200)}, 0.3);

View File

@ -168,21 +168,18 @@
data-md-color-primary="{{ primary }}" data-md-color-primary="{{ primary }}"
data-md-color-accent="{{ accent }}" data-md-color-accent="{{ accent }}"
> >
<!-- Experimental: set color scheme based on preference -->
{% if "preference" == scheme %}
<script>
if (matchMedia("(prefers-color-scheme: dark)").matches)
document.body.setAttribute("data-md-color-scheme", "slate")
</script>
{% endif %}
{% else %} {% else %}
<body dir="{{ direction }}"> <body dir="{{ direction }}">
{% endif %} {% endif %}
<!-- Retrieve features from configuration --> <!-- Retrieve features from configuration -->
{% set features = config.theme.features or [] %} {% set features = config.theme.features or [] %}
{% include "partials/javascripts/base.html" %}
<!-- User preference: color palette -->
{% if not config.theme.palette is mapping %}
{% include "partials/javascripts/palette.html" %}
{% endif %}
<!-- <!--
State toggles - we need to set autocomplete="off" in order to reset the State toggles - we need to set autocomplete="off" in order to reset the
@ -338,6 +335,18 @@
</article> </article>
</div> </div>
</div> </div>
<!-- Back-to-top button -->
{% if "navigation.top" in features %}
<a
href="#"
class="md-top md-icon"
data-md-component="top"
data-md-state="hidden"
>
{% include ".icons/material/arrow-up.svg" %}
</a>
{% endif %}
</main> </main>
<!-- Footer --> <!-- Footer -->

View File

@ -83,14 +83,12 @@ export function mountIconSearch(
`${config.base}/overrides/assets/javascripts/iconsearch_index.json` `${config.base}/overrides/assets/javascripts/iconsearch_index.json`
) )
/* Retrieve nested components */ /* Retrieve query and result components */
const query = getComponentElement("iconsearch-query", el) const query = getComponentElement("iconsearch-query", el)
const result = getComponentElement("iconsearch-result", el) const result = getComponentElement("iconsearch-result", el)
/* Create and return component */ /* Create and return component */
const query$ = mountIconSearchQuery(query) const query$ = mountIconSearchQuery(query)
return merge( const result$ = mountIconSearchResult(result, { index$, query$ })
query$, return merge(query$, result$)
mountIconSearchResult(result, { index$, query$ })
)
} }

View File

@ -63,11 +63,37 @@
</div> </div>
</div> </div>
<!-- Header options --> <!-- Color palette -->
<div class="md-header__options"> {% if not config.theme.palette is mapping %}
<form class="md-header__option" data-md-component="palette">
{% for option in config.theme.palette %}
{% set primary = option.primary | replace(" ", "-") | lower %}
{% set accent = option.accent | replace(" ", "-") | lower %}
<input
class="md-option"
data-md-color-media="{{ option.media }}"
data-md-color-scheme="{{ option.scheme }}"
data-md-color-primary="{{ primary }}"
data-md-color-accent="{{ accent }}"
type="radio"
name="__palette"
id="__palette_{{ loop.index }}"
/>
<label
class="md-header__button md-icon"
title="{{ option.toggle.name }}"
for="__palette_{{ loop.index0 or loop.length }}"
hidden
>
{% include ".icons/" ~ option.toggle.icon ~ ".svg" %}
</label>
{% endfor %}
</form>
{% endif %}
<!-- Switch to toggle language --> <!-- Site language selector -->
{% if config.extra.alternate %} {% if config.extra.alternate %}
<div class="md-header__option"></form>
<div class="md-select"> <div class="md-select">
{% set icon = config.theme.icon.alternate or "material/translate" %} {% set icon = config.theme.icon.alternate or "material/translate" %}
<span class="md-header__button md-icon"> <span class="md-header__button md-icon">
@ -85,8 +111,8 @@
</ul> </ul>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
{% endif %}
<!-- Button to open search modal --> <!-- Button to open search modal -->
{% if "search" in config["plugins"] %} {% if "search" in config["plugins"] %}

View File

@ -22,7 +22,7 @@
<!-- Google Analytics integration --> <!-- Google Analytics integration -->
{% set analytics = config.google_analytics %} {% set analytics = config.google_analytics %}
<script type="application/javascript"> <script>
window.ga = window.ga || function() { window.ga = window.ga || function() {
(ga.q = ga.q || []).push(arguments) (ga.q = ga.q || []).push(arguments)
} }

View File

@ -30,7 +30,7 @@
{% if not page.is_homepage and disqus %} {% if not page.is_homepage and disqus %}
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2> <h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
<div id="disqus_thread"></div> <div id="disqus_thread"></div>
<script type="application/javascript"> <script>
var disqus_config = function () { var disqus_config = function () {
this.page.url = "{{ page.canonical_url }}"; this.page.url = "{{ page.canonical_url }}";
this.page.identifier = this.page.identifier =

View File

@ -0,0 +1,39 @@
<!--
Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
-->
<!--
A collection of functions used from within some partials to allow the usage
of state saved in local or session storage, e.g. to model preferences.
-->
<script>
/* Prepend the base path to the given key to ensure uniqueness */
function __prefix(key) {
var prefix = new URL("{{ base_url }}", location)
return prefix.pathname + "." + key
}
/* Fetch the given key from the given storage */
function __get(key, storage = localStorage) {
return JSON.parse(storage.getItem(__prefix(key)))
}
</script>

View File

@ -0,0 +1,29 @@
<!--
Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
-->
<!-- User preference: color palette -->
<script>
var palette = __get("__palette")
if (palette !== null && typeof palette.color === "object")
for (var key in palette.color)
document.body.setAttribute("data-md-color-" + key, palette.color[key])
</script>