-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '2417d5888fb2627cb193fe37b11e8d510e765927'
- Loading branch information
Showing
16 changed files
with
294 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
external_dependencies <- function() { | ||
list( | ||
fontawesome::fa_html_dependency(), | ||
cached_dependency( | ||
name = "headroom", | ||
version = "0.11.0", | ||
files = list( | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js", | ||
integrity = "sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" | ||
), | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js", | ||
integrity = "sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" | ||
) | ||
) | ||
), | ||
cached_dependency( | ||
name = "bootstrap-toc", | ||
version = "1.0.1", | ||
files = list( | ||
list( | ||
url = "https://cdn.jsdelivr.net/gh/afeld/[email protected]/dist/bootstrap-toc.min.js", | ||
integrity = "sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" | ||
) | ||
) | ||
), | ||
cached_dependency( | ||
name = "clipboard.js", | ||
version = "2.0.11", | ||
files = list( | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js", | ||
integrity = "sha512-7O5pXpc0oCRrxk8RUfDYFgn0nO1t+jLuIOQdOMRp4APB7uZ4vSjspzp5y6YDtDs4VzUSTbWzBFZ/LKJhnyFOKw==" | ||
) | ||
) | ||
), | ||
cached_dependency( | ||
name = "search", | ||
version = "1.0.0", | ||
files = list( | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.min.js", | ||
integrity = "sha512-KnvCNMwWBGCfxdOtUpEtYgoM59HHgjHnsVGSxxgz7QH1DYeURk+am9p3J+gsOevfE29DV0V+/Dd52ykTKxN5fA==" | ||
), | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js", | ||
integrity = "sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" | ||
), | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js", | ||
integrity = "sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" | ||
) | ||
) | ||
), | ||
cached_dependency( | ||
name = "MathJax", | ||
version = "2.7.5", | ||
files = list( | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js", | ||
integrity = "sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" | ||
), | ||
list( | ||
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js", | ||
integrity = "sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" | ||
) | ||
) | ||
) | ||
) | ||
} | ||
|
||
cached_dependency <- function(name, version, files) { | ||
cache_dir <- path(tools::R_user_dir("pkgdown", "cache"), name, version) | ||
dir_create(cache_dir) | ||
|
||
for (file in files) { | ||
cache_path <- path(cache_dir, path_file(file$url)) | ||
if (!file_exists(cache_path)) { | ||
utils::download.file(file$url, cache_path, quiet = TRUE, mode = "wb") | ||
check_integrity(cache_path, file$integrity) | ||
} | ||
} | ||
dep_files <- path_rel(dir_ls(cache_dir), cache_dir) | ||
|
||
htmltools::htmlDependency( | ||
name = name, | ||
version = version, | ||
src = cache_dir, | ||
script = dep_files[path_ext(dep_files) == "js"], | ||
stylesheet = dep_files[path_ext(dep_files) == "css"] | ||
) | ||
} | ||
|
||
check_integrity <- function(path, integrity) { | ||
parsed <- parse_integrity(integrity) | ||
if (!parsed$size %in% c(256L, 384L, 512L)) { | ||
cli::cli_abort( | ||
"{.field integrity} must use SHA-256, SHA-384, or SHA-512", | ||
.internal = TRUE | ||
) | ||
} | ||
|
||
hash <- compute_hash(path, parsed$size) | ||
if (hash != parsed$hash) { | ||
cli::cli_abort( | ||
"Downloaded asset does not match known integrity", | ||
.internal = TRUE | ||
) | ||
} | ||
|
||
invisible() | ||
} | ||
|
||
compute_hash <- function(path, size) { | ||
con <- file(path, encoding = "UTF-8") | ||
openssl::base64_encode(openssl::sha2(con, size)) | ||
} | ||
|
||
parse_integrity <- function(x) { | ||
size <- as.integer(regmatches(x, regexpr("(?<=^sha)\\d{3}", x, perl = TRUE))) | ||
hash <- regmatches(x, regexpr("(?<=^sha\\d{3}-).+", x, perl = TRUE)) | ||
|
||
list(size = size, hash = hash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
/*! | ||
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) | ||
* Copyright 2011-2023 The Bootstrap Authors | ||
* Licensed under the Creative Commons Attribution 3.0 Unported License. | ||
* Updates for {pkgdown} by the {bslib} authors, also licensed under CC-BY-3.0. | ||
*/ | ||
|
||
const getStoredTheme = () => localStorage.getItem('theme') | ||
const setStoredTheme = theme => localStorage.setItem('theme', theme) | ||
|
||
const getPreferredTheme = () => { | ||
const storedTheme = getStoredTheme() | ||
if (storedTheme) { | ||
return storedTheme | ||
} | ||
|
||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' | ||
} | ||
|
||
const setTheme = theme => { | ||
if (theme === 'auto') { | ||
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) | ||
} else { | ||
document.documentElement.setAttribute('data-bs-theme', theme) | ||
} | ||
} | ||
|
||
function bsSetupThemeToggle () { | ||
'use strict' | ||
|
||
const showActiveTheme = (theme, focus = false) => { | ||
var activeLabel, activeIcon; | ||
|
||
document.querySelectorAll('[data-bs-theme-value]').forEach(element => { | ||
const buttonTheme = element.getAttribute('data-bs-theme-value') | ||
const isActive = buttonTheme == theme | ||
|
||
element.classList.toggle('active', isActive) | ||
element.setAttribute('aria-pressed', isActive) | ||
|
||
if (isActive) { | ||
activeLabel = element.textContent; | ||
activeIcon = element.querySelector('span').classList.value; | ||
} | ||
}) | ||
|
||
const themeSwitcher = document.querySelector('#dropdown-lightswitch') | ||
if (!themeSwitcher) { | ||
return | ||
} | ||
|
||
themeSwitcher.setAttribute('aria-label', activeLabel) | ||
themeSwitcher.querySelector('span').classList.value = activeIcon; | ||
|
||
if (focus) { | ||
themeSwitcher.focus() | ||
} | ||
} | ||
|
||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { | ||
const storedTheme = getStoredTheme() | ||
if (storedTheme !== 'light' && storedTheme !== 'dark') { | ||
setTheme(getPreferredTheme()) | ||
} | ||
}) | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
showActiveTheme(getPreferredTheme()) | ||
|
||
document | ||
.querySelectorAll('[data-bs-theme-value]') | ||
.forEach(toggle => { | ||
toggle.addEventListener('click', () => { | ||
const theme = toggle.getAttribute('data-bs-theme-value') | ||
setTheme(theme) | ||
setStoredTheme(theme) | ||
showActiveTheme(theme, true) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
setTheme(getPreferredTheme()); | ||
bsSetupThemeToggle(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.