Skip to content

Commit

Permalink
feat: add smart-anchor.js
Browse files Browse the repository at this point in the history
Open new tab for links to other site.
  • Loading branch information
libook committed Aug 5, 2021
1 parent 3423341 commit 208346c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ theme = "mytheme"
default-theme = "rust"
google-analytics = "UA-188947685-1"
git-repository-url = "https://github.com/RustMagazine/rust_magazine_2021"
additional-js = ["mermaid.min.js", "mermaid-init.js"]
additional-js = ["mermaid.min.js", "mermaid-init.js", "smart-anchor.js"]
mathjax-support = true

[output.html.playground]
Expand Down
12 changes: 12 additions & 0 deletions smart-anchor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

/*
For anchor elements, as known as <a> tags.
*/

document.querySelectorAll('a').forEach(aElement => {
// Open new tab for links to other site.
if (aElement.origin !== window.origin) {
aElement.target = '_blank';
}
});

0 comments on commit 208346c

Please sign in to comment.