Skip to content

Commit

Permalink
feat($theme-default): support external links in sidebar (close: #764)(#…
Browse files Browse the repository at this point in the history
  • Loading branch information
timaschew authored and ulivz committed Apr 16, 2019
1 parent 1b6c4cd commit 141bd11
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/@vuepress/theme-default/components/SidebarLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default {
const active = item.type === 'auto'
? selfActive || item.children.some(c => isActive($route, item.basePath + '#' + c.slug))
: selfActive
const link = renderLink(h, item.path, item.title || item.path, active)
const link = item.type === 'external'
? renderExternal(h, item.path, item.title || item.path)
: renderLink(h, item.path, item.title || item.path, active)
const configDepth = $page.frontmatter.sidebarDepth
|| sidebarDepth
Expand Down Expand Up @@ -75,6 +77,19 @@ function renderChildren (h, children, path, route, maxDepth, depth = 1) {
])
}))
}
function renderExternal (h, to, text) {
return h('a', {
attrs: {
href: to,
target: '_blank',
rel: 'noopener noreferrer'
},
class: {
'sidebar-link': true
}
}, [text, h('OutboundLink')])
}
</script>

<style lang="stylus">
Expand Down
6 changes: 6 additions & 0 deletions packages/@vuepress/theme-default/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export function isActive (route, path) {
}

export function resolvePage (pages, rawPath, base) {
if (isExternal(rawPath)) {
return {
type: 'external',
path: rawPath
}
}
if (base) {
rawPath = resolvePath(rawPath, base)
}
Expand Down

0 comments on commit 141bd11

Please sign in to comment.