Skip to content

Commit 62cd00e

Browse files
committed
fix: support mailto links in NavLink + style tweaks (close #93)
1 parent 1bbfa43 commit 62cd00e

File tree

6 files changed

+55
-49
lines changed

6 files changed

+55
-49
lines changed

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
home: true
33
heroImage: /hero.png
44
actionText: Get Started →
5-
actionLink: /guide/
5+
actionLink: https://github.com
66
features:
77
- title: Simplicity First
88
details: Minimal setup with markdown-centered project structure helps you focus on writing.

lib/default-theme/DropdownLink.vue

+20-20
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@
1515
class="dropdown-subitem"
1616
v-for="childSubItem in subItem.items"
1717
:key="childSubItem.link">
18-
<nav-link :item="childSubItem"></nav-link>
18+
<NavLink :item="childSubItem"/>
1919
</li>
2020
</ul>
21-
<nav-link v-else :item="subItem"></nav-link>
21+
<NavLink v-else :item="subItem"/>
2222
</li>
2323
</ul>
2424
</div>
2525
</template>
2626

2727
<script>
28-
import { isExternal, ensureExt } from './util'
29-
import NavLink from './NavLink.vue'
28+
import { isExternal, ensureExt } from './util'
29+
import NavLink from './NavLink.vue'
3030
31-
export default {
32-
components: { NavLink },
33-
data() {
34-
return {
35-
open: false
36-
}
37-
},
38-
props: {
39-
item: {
40-
required: true
41-
}
42-
},
43-
methods: {
44-
toggle() {
45-
this.open = !this.open
46-
}
31+
export default {
32+
components: { NavLink },
33+
data() {
34+
return {
35+
open: false
36+
}
37+
},
38+
props: {
39+
item: {
40+
required: true
41+
}
42+
},
43+
methods: {
44+
toggle() {
45+
this.open = !this.open
4746
}
4847
}
48+
}
4949
</script>
5050

5151
<style lang="stylus">

lib/default-theme/Home.vue

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
{{ data.tagline || $site.description }}
88
</p>
99
<p class="action" v-if="data.actionText && data.actionLink">
10-
<router-link class="action-button" :to="ensureExt(data.actionLink)">
11-
{{ data.actionText }}
12-
</router-link>
10+
<NavLink class="action-button" :item="actionLink"/>
1311
</p>
1412
</div>
1513
<div class="features">
@@ -26,15 +24,19 @@
2624
</template>
2725

2826
<script>
29-
import { ensureExt } from './util'
27+
import NavLink from './NavLink.vue'
3028
3129
export default {
32-
methods: {
33-
ensureExt
34-
},
30+
components: { NavLink },
3531
computed: {
3632
data () {
3733
return this.$page.frontmatter
34+
},
35+
actionLink () {
36+
return {
37+
link: this.data.actionLink,
38+
text: this.data.actionText
39+
}
3840
}
3941
}
4042
}

lib/default-theme/NavLink.vue

+18-16
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@
88
<a
99
v-else
1010
:href="link"
11-
target="_blank"
1211
class="nav-link"
13-
rel="noopener noreferrer"
12+
:target="isMailto(link) ? null : '_blank'"
13+
:rel="isMailto(link) ? null : 'noopener noreferrer'"
1414
>{{ item.text }}</a>
1515
</template>
1616

1717
<script>
18-
import { isExternal, ensureExt } from './util'
19-
export default {
20-
props: {
21-
item: {
22-
required: true
23-
}
24-
},
25-
computed: {
26-
link() {
27-
return ensureExt(this.item.link)
28-
}
29-
},
30-
methods: {
31-
isExternal
18+
import { isExternal, isMailto, ensureExt } from './util'
19+
20+
export default {
21+
props: {
22+
item: {
23+
required: true
24+
}
25+
},
26+
computed: {
27+
link() {
28+
return ensureExt(this.item.link)
3229
}
30+
},
31+
methods: {
32+
isExternal,
33+
isMailto
3334
}
35+
}
3436
</script>

lib/default-theme/NavLinks.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
class="nav-item"
66
v-for="item in userLinks"
77
:key="item.link">
8-
<dropdown-link
9-
v-if="item.type === 'links'"
10-
:item="item"></dropdown-link>
11-
<nav-link v-else :item="item"></nav-link>
8+
<DropdownLink v-if="item.type === 'links'" :item="item"/>
9+
<NavLink v-else :item="item"/>
1210
</div>
1311
<!-- github link -->
1412
<a v-if="githubLink"

lib/default-theme/util.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const hashRE = /#.*$/
22
export const extRE = /\.(md|html)$/
33
export const endingSlashRE = /\/$/
4-
export const outboundRE = /^https?:/
4+
export const outboundRE = /^(https?:|mailto:)/
55

66
export function normalize (path) {
77
return path
@@ -20,6 +20,10 @@ export function isExternal (path) {
2020
return outboundRE.test(path)
2121
}
2222

23+
export function isMailto (path) {
24+
return /^mailto:/.test(path)
25+
}
26+
2327
export function ensureExt (path) {
2428
if (isExternal(path)) {
2529
return path

0 commit comments

Comments
 (0)