mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Replace old docs with new docs repo (#24201)
This commit is contained in:
44
docs/normalize-internal-links.js
Normal file
44
docs/normalize-internal-links.js
Normal file
@@ -0,0 +1,44 @@
|
||||
(function () {
|
||||
function normalizeInternalLinks() {
|
||||
const selectors = [
|
||||
'a[href*="bun.com/docs/installation"]',
|
||||
'a[href="https://bun.com/reference"]',
|
||||
'a[href="https://bun.com/blog"]',
|
||||
];
|
||||
|
||||
selectors.forEach(selector => {
|
||||
const elements = document.querySelectorAll(selector);
|
||||
elements.forEach(element => {
|
||||
if (element.hasAttribute("target")) {
|
||||
element.removeAttribute("target");
|
||||
// Also remove rel="noreferrer" if present, typically paired with target="_blank"
|
||||
if (element.getAttribute("rel") === "noreferrer") {
|
||||
element.removeAttribute("rel");
|
||||
}
|
||||
console.log(`Removed target="_blank" from: ${element.textContent || element.innerHTML.substring(0, 50)}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", normalizeInternalLinks);
|
||||
} else {
|
||||
normalizeInternalLinks();
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(function (mutations) {
|
||||
mutations.forEach(function (mutation) {
|
||||
if (mutation.type === "childList" || mutation.type === "attributes") {
|
||||
normalizeInternalLinks();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ["target", "href"],
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user