Skip to content

Commit 1d520ae

Browse files
committed
support external links in sidebar
1 parent 23b0ce3 commit 1d520ae

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/@vuepress/theme-default/components/SidebarLink.vue

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export default {
2828
const active = item.type === 'auto'
2929
? selfActive || item.children.some(c => isActive($route, item.basePath + '#' + c.slug))
3030
: selfActive
31-
const link = renderLink(h, item.path, item.title || item.path, active)
31+
const link = item.type === 'external'
32+
? renderExternal(h, item.path, item.title || item.path)
33+
: renderLink(h, item.path, item.title || item.path, active)
3234
3335
const configDepth = $page.frontmatter.sidebarDepth
3436
|| sidebarDepth
@@ -75,6 +77,18 @@ function renderChildren (h, children, path, route, maxDepth, depth = 1) {
7577
])
7678
}))
7779
}
80+
81+
function renderExternal (h, to, text) {
82+
return h('a', {
83+
attrs: {
84+
href: to,
85+
target: '_blank'
86+
},
87+
class: {
88+
'sidebar-link': true
89+
}
90+
}, [text, h('OutboundLink')])
91+
}
7892
</script>
7993

8094
<style lang="stylus">

packages/@vuepress/theme-default/util/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export function isActive (route, path) {
5454
}
5555

5656
export function resolvePage (pages, rawPath, base) {
57+
if (isExternal(rawPath)) {
58+
return {
59+
type: 'external',
60+
title: rawPath,
61+
path: rawPath
62+
}
63+
}
5764
if (base) {
5865
rawPath = resolvePath(rawPath, base)
5966
}

0 commit comments

Comments
 (0)