~ajhalili2006's personal website, built with Zensical (successor of Material for Mkdocs) [old repo name got bugged while attempting to do manual knot migration via repo deletion]
andreijiroh.dev
zensical
mkdocs-material
website
1
2/* RTD Search integration */
3document.addEventListener("DOMContentLoaded", function(event) {
4// Trigger Read the Docs' search addon instead of Material MkDocs default
5document.querySelector(".md-search__input").addEventListener("focus", (e) => {
6 const event = new CustomEvent("readthedocs-search-show");
7 document.dispatchEvent(event);
8 });
9});
10
11/* RTD version selector */
12// Use CustomEvent to generate the version selector
13document.addEventListener(
14 "readthedocs-addons-data-ready",
15 function (event) {
16 const config = event.detail.data();
17 const versioning = `
18<div class="md-version">
19<button class="md-version__current" aria-label="Select version">
20 ${config.versions.current.slug}
21</button>
22
23<ul class="md-version__list">
24${ config.versions.active.map(
25 (version) => `
26 <li class="md-version__item">
27 <a href="${ version.urls.documentation }" class="md-version__link">
28 ${ version.slug }
29 </a>
30 </li>`).join("\n")}
31</ul>
32</div>`;
33
34 // Check if we already added versions and remove them if so.
35 // This happens when using the "Instant loading" feature.
36 // See https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/#instant-loading
37 const currentVersions = document.querySelector(".md-version");
38 if (currentVersions !== null) {
39 currentVersions.remove();
40 }
41 document.querySelector(".md-header__topic").insertAdjacentHTML("beforeend", versioning);
42});