Files
json/docs/mkdocs/docs/js/external-links.js
T
Niels Lohmann f4a91f800d docs: byline and licenses for the 3.13.0 post
- author and date below the title, styled as .nj-byline; its link gets
  no external-link icon
- the license of every library in the thanks section, checked against
  each project's license files; credit sonic-rs for QUOTE_TAB, which
  orjson adapted from it

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-30 15:29:47 +01:00

34 lines
1.3 KiB
JavaScript

/*
* Marks links that leave the site with the class "nj-external", which brand.css turns into a small icon in front of
* the link. A link is external when its host is neither the current one nor the production site. Links in the page
* actions (edit, raw), buttons, header anchors, a blog post's byline, and links that only wrap an image (badges) are
* left alone.
* Runs through Material's document$ (navigation.instant), so it also applies after an instant page switch.
*/
(function () {
"use strict";
function mark() {
var links = document.querySelectorAll(".md-typeset a[href]");
for (var i = 0; i < links.length; i++) {
var a = links[i];
if (a.hostname === "" || a.hostname === location.hostname || a.hostname === "json.nlohmann.me") {
continue;
}
if (a.protocol !== "http:" && a.protocol !== "https:") {
continue;
}
if (a.matches(".md-button, .md-content__button, .headerlink, .nj-byline a") || a.querySelector("img, svg")) {
continue;
}
a.classList.add("nj-external");
}
}
if (window.document$ && window.document$.subscribe) {
window.document$.subscribe(mark);
} else {
document.addEventListener("DOMContentLoaded", mark);
}
})();