Skip to content

Commit

Permalink
fix: support mailto links in NavLink + style tweaks (close #93)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 17, 2018
1 parent 1bbfa43 commit 62cd00e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 49 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
home: true
heroImage: /hero.png
actionText: Get Started →
actionLink: /guide/
actionLink: https://github.com
features:
- title: Simplicity First
details: Minimal setup with markdown-centered project structure helps you focus on writing.
Expand Down
40 changes: 20 additions & 20 deletions lib/default-theme/DropdownLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@
class="dropdown-subitem"
v-for="childSubItem in subItem.items"
:key="childSubItem.link">
<nav-link :item="childSubItem"></nav-link>
<NavLink :item="childSubItem"/>
</li>
</ul>
<nav-link v-else :item="subItem"></nav-link>
<NavLink v-else :item="subItem"/>
</li>
</ul>
</div>
</template>

<script>
import { isExternal, ensureExt } from './util'
import NavLink from './NavLink.vue'
import { isExternal, ensureExt } from './util'
import NavLink from './NavLink.vue'
export default {
components: { NavLink },
data() {
return {
open: false
}
},
props: {
item: {
required: true
}
},
methods: {
toggle() {
this.open = !this.open
}
export default {
components: { NavLink },
data() {
return {
open: false
}
},
props: {
item: {
required: true
}
},
methods: {
toggle() {
this.open = !this.open
}
}
}
</script>

<style lang="stylus">
Expand Down
16 changes: 9 additions & 7 deletions lib/default-theme/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
{{ data.tagline || $site.description }}
</p>
<p class="action" v-if="data.actionText && data.actionLink">
<router-link class="action-button" :to="ensureExt(data.actionLink)">
{{ data.actionText }}
</router-link>
<NavLink class="action-button" :item="actionLink"/>
</p>
</div>
<div class="features">
Expand All @@ -26,15 +24,19 @@
</template>

<script>
import { ensureExt } from './util'
import NavLink from './NavLink.vue'
export default {
methods: {
ensureExt
},
components: { NavLink },
computed: {
data () {
return this.$page.frontmatter
},
actionLink () {
return {
link: this.data.actionLink,
text: this.data.actionText
}
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions lib/default-theme/NavLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,29 @@
<a
v-else
:href="link"
target="_blank"
class="nav-link"
rel="noopener noreferrer"
:target="isMailto(link) ? null : '_blank'"
:rel="isMailto(link) ? null : 'noopener noreferrer'"
>{{ item.text }}</a>
</template>

<script>
import { isExternal, ensureExt } from './util'
export default {
props: {
item: {
required: true
}
},
computed: {
link() {
return ensureExt(this.item.link)
}
},
methods: {
isExternal
import { isExternal, isMailto, ensureExt } from './util'
export default {
props: {
item: {
required: true
}
},
computed: {
link() {
return ensureExt(this.item.link)
}
},
methods: {
isExternal,
isMailto
}
}
</script>
6 changes: 2 additions & 4 deletions lib/default-theme/NavLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
class="nav-item"
v-for="item in userLinks"
:key="item.link">
<dropdown-link
v-if="item.type === 'links'"
:item="item"></dropdown-link>
<nav-link v-else :item="item"></nav-link>
<DropdownLink v-if="item.type === 'links'" :item="item"/>
<NavLink v-else :item="item"/>
</div>
<!-- github link -->
<a v-if="githubLink"
Expand Down
6 changes: 5 additions & 1 deletion lib/default-theme/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const hashRE = /#.*$/
export const extRE = /\.(md|html)$/
export const endingSlashRE = /\/$/
export const outboundRE = /^https?:/
export const outboundRE = /^(https?:|mailto:)/

export function normalize (path) {
return path
Expand All @@ -20,6 +20,10 @@ export function isExternal (path) {
return outboundRE.test(path)
}

export function isMailto (path) {
return /^mailto:/.test(path)
}

export function ensureExt (path) {
if (isExternal(path)) {
return path
Expand Down

0 comments on commit 62cd00e

Please sign in to comment.