eBPF-based security platform
Documentation: add a light and dark theme toggle
Daniel Borkmann519870c2ba4d
diff --git a/Documentation/_themes/shirudo/layout.html b/Documentation/_themes/shirudo/layout.htmlindex 461ad460..8d5edebc 100644--- a/Documentation/_themes/shirudo/layout.html+++ b/Documentation/_themes/shirudo/layout.html@@ -8,6 +8,7 @@{%- block extrahead %}<meta name="viewport" content="width=device-width, initial-scale=1">+<script>try { var t = localStorage.getItem("shirudo-theme"); if (t === "light" || t === "dark") document.documentElement.setAttribute("data-theme", t); } catch (e) {}</script><script src="{{ pathto('_static/shirudo.js', 1) }}" defer></script>{%- endblock %}@@ -27,6 +28,7 @@<input type="search" name="q" placeholder="Search docs" aria-label="Search the documentation"><kbd>/</kbd></form>+ <button class="theme-toggle" type="button" hidden></button><a class="gh" href="{{ repository }}">GitHub</a></div></div>diff --git a/Documentation/_themes/shirudo/static/shirudo.css b/Documentation/_themes/shirudo/static/shirudo.cssindex 278b53b0..d0474b27 100644--- a/Documentation/_themes/shirudo/static/shirudo.css+++ b/Documentation/_themes/shirudo/static/shirudo.css@@ -39,7 +39,7 @@}@media (prefers-color-scheme: dark) {- :root {+ :root:not([data-theme="light"]) {--bar: #fff;--bar-fg: #5d6675;--bar-hi: #171b22;@@ -64,6 +64,30 @@}}+:root[data-theme="dark"] {+ --bar: #fff;+ --bar-fg: #5d6675;+ --bar-hi: #171b22;+ --bar-dim: #8a93a0;+ --bar-field: #f4f6f8;+ --bar-line: #e2e6eb;+ --logo-light-back: block;+ --logo-dark-back: none;+ --bg: #0e1116;+ --soft: #161b22;+ --fg: #e4e8ee;+ --muted: #9ba5b3;+ --line: #262d37;+ --accent: #e8899f;+ --accent-soft: #3a1b25;+ --code-bg: #080a0d;+ --warn-bg: #261f10;+ --warn-line: #6e5520;+ --stop-bg: #2a1614;+ --stop-line: #6f2e28;+ color-scheme: dark;+}+* { box-sizing: border-box; }html { scroll-padding-top: 72px; }body { margin: 0; background: var(--bg); color: var(--fg); font: 400 15px/1.65 var(--sans); }@@ -90,6 +114,8 @@ code.literal { font-size: 0.9em; background: none; padding: 0; }.search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--bar-dim); }.gh { color: var(--bar-fg); font-size: 13.5px; }.gh:hover { color: var(--bar-hi); text-decoration: none; }+.theme-toggle { background: none; border: 0; padding: 0; cursor: pointer; color: var(--bar-fg); font: 400 13.5px var(--sans); }+.theme-toggle:hover { color: var(--bar-hi); }/* columns */.shell { display: grid; grid-template-columns: 280px minmax(0, 1fr) 220px; gap: 48px; max-width: 1480px; margin: 0 auto; padding: 0 20px; }diff --git a/Documentation/_themes/shirudo/static/shirudo.js b/Documentation/_themes/shirudo/static/shirudo.jsindex 8e921fa4..ada8f431 100644--- a/Documentation/_themes/shirudo/static/shirudo.js+++ b/Documentation/_themes/shirudo/static/shirudo.js@@ -166,11 +166,50 @@});}+ /*+ * An explicit choice overrides the system preference and is kept per+ * browser; storage can be unavailable, in which case it lasts the page.+ */+ function theme() {+ var button = document.querySelector(".theme-toggle");+ var root = document.documentElement;+ var media = window.matchMedia("(prefers-color-scheme: dark)");++ if (!button)+ return;+ var current = function () {+ return root.getAttribute("data-theme") ||+ (media.matches ? "dark" : "light");+ };+ var label = function () {+ var next = current() === "dark" ? "light" : "dark";++ button.textContent = next === "dark" ? "Dark" : "Light";+ button.setAttribute("aria-label", "Switch to the " + next ++ " theme");+ };+ button.addEventListener("click", function () {+ var next = current() === "dark" ? "light" : "dark";++ root.setAttribute("data-theme", next);+ try {+ localStorage.setItem("shirudo-theme", next);+ } catch (e) {+ /* the choice then lasts until the page is left */+ }+ label();+ });+ media.addEventListener("change", label);+ label();+ button.hidden = false;+ }+document.addEventListener("DOMContentLoaded", function () {tree();menu();code();spy();search();+ theme();});})();