Skip to content

Commit

Permalink
rel="noopener"
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 13, 2018
1 parent 12db960 commit 98b7cc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/default-theme/NavLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<a v-if="githubLink"
:href="githubLink"
class="github-link"
target="_blank">
target="_blank"
rel="noopener">
Github
<OutboundLink/>
</a>
Expand Down
17 changes: 11 additions & 6 deletions lib/markdown/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ module.exports = md => {
const isExternal = /^https?:/.test(href)
const isSourceLink = /(\/|\.md|\.html)(#[\w-]*)?$/.test(href)
if (isExternal) {
const targetIndex = token.attrIndex('target')
if (targetIndex < 0) {
token.attrPush(['target', '_blank'])
} else {
token.attrs[targetIndex][1] = '_blank'
}
addAttr(token, 'target', '_blank')
addAttr(token, 'rel', 'noopener')
} else if (isSourceLink) {
hasOpenRouterLink = true
tokens[idx] = toRouterLink(token, link)
Expand Down Expand Up @@ -58,3 +54,12 @@ module.exports = md => {
return self.renderToken(tokens, idx, options)
}
}

function addAttr (token, name, val) {
const targetIndex = token.attrIndex(name)
if (targetIndex < 0) {
token.attrPush([name, val])
} else {
token.attrs[targetIndex][1] = val
}
}

0 comments on commit 98b7cc7

Please sign in to comment.