Skip to content

Commit 98b7cc7

Browse files
committed
rel="noopener"
1 parent 12db960 commit 98b7cc7

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Diff for: lib/default-theme/NavLinks.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<a v-if="githubLink"
1111
:href="githubLink"
1212
class="github-link"
13-
target="_blank">
13+
target="_blank"
14+
rel="noopener">
1415
Github
1516
<OutboundLink/>
1617
</a>

Diff for: lib/markdown/link.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ module.exports = md => {
1414
const isExternal = /^https?:/.test(href)
1515
const isSourceLink = /(\/|\.md|\.html)(#[\w-]*)?$/.test(href)
1616
if (isExternal) {
17-
const targetIndex = token.attrIndex('target')
18-
if (targetIndex < 0) {
19-
token.attrPush(['target', '_blank'])
20-
} else {
21-
token.attrs[targetIndex][1] = '_blank'
22-
}
17+
addAttr(token, 'target', '_blank')
18+
addAttr(token, 'rel', 'noopener')
2319
} else if (isSourceLink) {
2420
hasOpenRouterLink = true
2521
tokens[idx] = toRouterLink(token, link)
@@ -58,3 +54,12 @@ module.exports = md => {
5854
return self.renderToken(tokens, idx, options)
5955
}
6056
}
57+
58+
function addAttr (token, name, val) {
59+
const targetIndex = token.attrIndex(name)
60+
if (targetIndex < 0) {
61+
token.attrPush([name, val])
62+
} else {
63+
token.attrs[targetIndex][1] = val
64+
}
65+
}

0 commit comments

Comments
 (0)