Skip to content

Commit b03ed84

Browse files
committed
Add external-links.js
1 parent 2d361d6 commit b03ed84

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

docs/javascripts/external-links.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
document.addEventListener('DOMContentLoaded', domContentLoaded)
2+
3+
const observer = new MutationObserver(mutationObserver)
4+
5+
function domContentLoaded() {
6+
for (const el of document.querySelectorAll('a')) {
7+
processLink(el)
8+
}
9+
observer.observe(document, {
10+
childList: true,
11+
subtree: true,
12+
})
13+
}
14+
15+
function mutationObserver(mutationList) {
16+
// console.debug('mutationList:', mutationList)
17+
for (const mutation of mutationList) {
18+
// console.debug('mutation:', mutation)
19+
mutation.addedNodes.forEach((el) => {
20+
// console.debug('el:', el)
21+
if (el.classList?.contains('md-container')) {
22+
for (const el of document.querySelectorAll('a')) {
23+
processLink(el)
24+
}
25+
}
26+
})
27+
}
28+
}
29+
30+
function processLink(el) {
31+
// console.debug('checking el:', el)
32+
if (el.host !== window.location.host) {
33+
// console.debug('updating el:', el)
34+
el.target = '_blank'
35+
el.rel = 'noopener'
36+
}
37+
}

zensical.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ site_url = "https://zensical-action.cssnr.com/"
1212

1313
# https://zensical.org/docs/setup/basics/#copyright
1414
copyright = """
15-
<a href="https://github.com/cssnr/zensical-action-docs" target="_blank">Zensical Action Docs</a>
15+
<a href="https://github.com/cssnr/zensical-action-docs">Zensical Action Docs</a>
1616
<br>
17-
Built with <a href="https://github.com/zensical/zensical" target="_blank">Zensical</a>
17+
Built with <a href="https://github.com/zensical/zensical">Zensical</a>
1818
"""
1919

2020
# https://zensical.org/docs/setup/navigation/
@@ -29,7 +29,7 @@ nav = [
2929
#extra_css = ["assets/stylesheets/extra.css"]
3030

3131
# https://zensical.org/docs/customization/#additional-javascript
32-
#extra_javascript = ["assets/javascript/extra.js"]
32+
extra_javascript = ["javascripts/external-links.js"]
3333

3434
# ----------------------------------------------------------------------------
3535
# Section for configuring theme options

0 commit comments

Comments
 (0)