Skip to content

Commit

Permalink
Merge branch 'main' into code-inspection-2
Browse files Browse the repository at this point in the history
  • Loading branch information
auronen committed Aug 2, 2022
2 parents a7007a2 + 597d67c commit 261ccd7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/css/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@
}
}


/* 16:9 aspect ratio and centering */
/* Works on top of mkdocs-video */
.video-container {
width: 32rem;
height: 18rem;
margin: auto;
}

/* Special character added to external links*/
.md-content a.external-link::after {
content: "[➽]";

}
37 changes: 32 additions & 5 deletions docs/js/extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
let gGMC_DEBUG = false;

window.addEventListener("DOMContentLoaded", _ => {
gmcExpandNavigation();
gmcExternalLinks();
});

function gmcExternalLinks() {
const hostname = window.location.hostname;
const domainParts = hostname.split('.');
const githubId = domainParts[1] === "github" ? domainParts[0] : "auronen";
const repoUrl = `github.com/${githubId}`;

// Regex to match urls starting with
// https://127.0.0.1
// https://auronen ...
// https://github.com/auronen ...
const regex = /^(?:https?:\/\/)?(?:www)?(127\.0\.0\.1|auronen|github\.com\/auronen)/;
// https://$hostname
// https://$repoUrl
const regex = new RegExp(`^(?:https?:\/\/)?(${hostname}|${repoUrl})`);
const anchors = document.querySelectorAll(".md-content a");
let className = "external-link";
const className = "external-link";

anchors.forEach( a => {
if (regex.test(a.href)) {
Expand All @@ -33,6 +38,28 @@ function gmcExternalLinks() {
});
}

function gmcExpandNavigation() {
const activeNav = document.querySelector(".md-nav__link--active").parentElement;
const children = activeNav.querySelector("nav > ul").children;

for (let i = 0; i < children.length; i++) {
const toggle = children[i].querySelector('input[type="checkbox"]');

if (!toggle) {
gmcDebug(`⏩ toggle not present`);
continue;
}

if (toggle.checked) {
gmcDebug(`⏩ '${toggle.id}' already checked`);
continue;
}

toggle.checked = true;
gmcDebug(`✅ Expanded '${toggle.id}'`);
}
}

function gmcDebug(message) {
if (gGMC_DEBUG)
console.debug(message);
Expand Down

0 comments on commit 261ccd7

Please sign in to comment.