mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-29 17:22:37 -04:00
Squashed commit of the following:
commit 9b5b80380fc81f5a68828e22754f0e7d53b0dea0
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Feb 7 16:25:06 2021 +0100
Refactored more stuff
commit 5a2108254f1222db7de08690e13c24e972ea19c0
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Feb 7 13:48:16 2021 +0100
Refactored more stuff
commit b3a112f4bddefebcf9dbd1d0ffe240d86fc9aa08
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Feb 7 12:02:42 2021 +0100
Refactored more stuff
commit bff323b6b81571021c0ac9be6f637de7728447a5
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sat Feb 6 18:14:52 2021 +0100
Refactored search result list
commit 27b7e7e2da3b725797ad769e4411260ffd35b9f8
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sat Feb 6 17:12:36 2021 +0100
Refactored more components
commit 3747e5ba6d084ed513a2659f48f161449b760076
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Jan 24 18:56:26 2021 +0100
Implemented new architecture for several components
commit ea2851ab0f27113b080c2539a94a88dc0332be84
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Jan 24 14:53:42 2021 +0100
Removed unnecessary height declaration for sidebars
commit 3c3f83ab4ef392dbabf1a11afba2556e529b1674
Merge: 91d239d8 13024179
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sun Jan 24 13:04:49 2021 +0100
Merge branch 'master' into refactor/observable-architecture
commit 91d239d86649b9571b376011669bc73a7865b186
Author: squidfunk <martin.donath@squidfunk.com>
Date: Sat Jan 9 13:11:04 2021 +0100
Started refactoring observable architecture
This commit is contained in:
@@ -20,66 +20,10 @@
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { getElementOrThrow } from "browser"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Helper types
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Translation keys
|
||||
*/
|
||||
type TranslateKey =
|
||||
| "clipboard.copy" /* Copy to clipboard */
|
||||
| "clipboard.copied" /* Copied to clipboard */
|
||||
| "search.config.lang" /* Search language */
|
||||
| "search.config.pipeline" /* Search pipeline */
|
||||
| "search.config.separator" /* Search separator */
|
||||
| "search.placeholder" /* Search */
|
||||
| "search.result.placeholder" /* Type to start searching */
|
||||
| "search.result.none" /* No matching documents */
|
||||
| "search.result.one" /* 1 matching document */
|
||||
| "search.result.other" /* # matching documents */
|
||||
| "search.result.more.one" /* 1 more on this page */
|
||||
| "search.result.more.other" /* # more on this page */
|
||||
| "search.result.term.missing" /* Missing */
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Data
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Translations
|
||||
*/
|
||||
let lang: Record<string, string>
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Functions
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Translate the given key
|
||||
*
|
||||
* @param key - Key to be translated
|
||||
* @param value - Value to be replaced
|
||||
*
|
||||
* @return Translation
|
||||
*/
|
||||
export function translate(
|
||||
key: TranslateKey, value?: string | number
|
||||
): string {
|
||||
if (typeof lang === "undefined") {
|
||||
const el = getElementOrThrow("#__lang")
|
||||
lang = JSON.parse(el.textContent!)
|
||||
}
|
||||
if (typeof lang[key] === "undefined") {
|
||||
throw new ReferenceError(`Invalid translation: ${key}`)
|
||||
}
|
||||
return typeof value !== "undefined"
|
||||
? lang[key].replace("#", value.toString())
|
||||
: lang[key]
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate a string after the given number of characters
|
||||
*
|
||||
@@ -96,16 +40,16 @@ export function translate(
|
||||
export function truncate(value: string, n: number): string {
|
||||
let i = n
|
||||
if (value.length > i) {
|
||||
while (value[i] !== " " && --i > 0); // tslint:disable-line
|
||||
while (value[i] !== " " && --i > 0) { /* keep eating */ }
|
||||
return `${value.substring(0, i)}...`
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Round a number for display with source facts
|
||||
* Round a number for display with repository facts
|
||||
*
|
||||
* This is a reverse engineered version of GitHub's weird rounding algorithm
|
||||
* This is a reverse-engineered version of GitHub's weird rounding algorithm
|
||||
* for stars, forks and all other numbers. While all numbers below `1,000` are
|
||||
* returned as-is, bigger numbers are converted to fixed numbers:
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user