Skip to content

Commit 942a2b9

Browse files
ycmjasonulivz
authored andcommittedMay 13, 2018
feat: show OutboundLink icon for external links (#428)
1 parent 2076f7b commit 942a2b9

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed
 

‎lib/app/app.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue'
22
import Router from 'vue-router'
33
import Content from './Content'
4+
import OutboundLink from '../default-theme/OutboundLink.vue'
45
import ClientOnly from './ClientOnly'
56
import dataMixin from './dataMixin'
67
import store from './store'
@@ -28,6 +29,7 @@ Vue.use(Router)
2829
Vue.mixin(dataMixin)
2930
// component for rendering markdown content and setting title etc.
3031
Vue.component('Content', Content)
32+
Vue.component('OutboundLink', OutboundLink)
3133
// component for client-only content
3234
Vue.component('ClientOnly', ClientOnly)
3335

‎lib/default-theme/NavLink.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
<a
99
v-else
1010
:href="link"
11-
class="nav-link"
11+
class="nav-link external"
1212
:target="isMailto(link) || isTel(link) ? null : '_blank'"
1313
:rel="isMailto(link) || isTel(link) ? null : 'noopener noreferrer'"
14-
>{{ item.text }}</a>
14+
>
15+
{{ item.text }}
16+
<OutboundLink/>
17+
</a>
1518
</template>
1619

1720
<script>

‎lib/default-theme/NavLinks.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
</template>
2222

2323
<script>
24-
import OutboundLink from './OutboundLink.vue'
2524
import DropdownLink from './DropdownLink.vue'
2625
import { resolveNavLinkItem } from './util'
2726
import NavLink from './NavLink.vue'
2827
2928
export default {
30-
components: { OutboundLink, NavLink, DropdownLink },
29+
components: { NavLink, DropdownLink },
3130
computed: {
3231
userNav () {
3332
return this.$themeLocaleConfig.nav || this.$site.themeConfig.nav || []
@@ -126,7 +125,7 @@ export default {
126125
.nav-links a
127126
&:hover, &.router-link-active
128127
color $textColor
129-
.nav-item > a
128+
.nav-item > a:not(.external)
130129
&:hover, &.router-link-active
131130
margin-bottom -2px
132131
border-bottom 2px solid lighten($accentColor, 8%)

‎lib/default-theme/Page.vue

-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
</template>
2929

3030
<script>
31-
import OutboundLink from './OutboundLink.vue'
3231
import { resolvePage, normalize, outboundRE, endingSlashRE } from './util'
3332
3433
export default {
35-
components: { OutboundLink },
3634
props: ['sidebarItems'],
3735
computed: {
3836
lastUpdated () {

‎lib/markdown/link.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ module.exports = (md, externalAttrs) => {
1515
const isSourceLink = /(\/|\.md|\.html)(#.*)?$/.test(href)
1616
if (isExternal) {
1717
Object.entries(externalAttrs).forEach(([key, val]) => {
18-
addAttr(token, key, val)
18+
token.attrSet(key, val)
1919
})
20+
21+
if (/_blank/i.test(externalAttrs['target'])) {
22+
// add OutBoundLink to content if it opens in _blank
23+
tokens[idx + 1].type = 'html_block'
24+
tokens[idx + 1].content += '<OutboundLink/>'
25+
}
2026
} else if (isSourceLink) {
2127
hasOpenRouterLink = true
2228
tokens[idx] = toRouterLink(token, link)
@@ -56,12 +62,3 @@ module.exports = (md, externalAttrs) => {
5662
return self.renderToken(tokens, idx, options)
5763
}
5864
}
59-
60-
function addAttr (token, name, val) {
61-
const targetIndex = token.attrIndex(name)
62-
if (targetIndex < 0) {
63-
token.attrPush([name, val])
64-
} else {
65-
token.attrs[targetIndex][1] = val
66-
}
67-
}

0 commit comments

Comments
 (0)
Please sign in to comment.