From 6c4703f63fd6636a1220255d765113835c4c7df2 Mon Sep 17 00:00:00 2001 From: Anton Wilhelm Date: Thu, 11 Apr 2019 22:46:42 +0200 Subject: [PATCH] support external links in sidebar --- .../theme-default/components/SidebarLink.vue | 17 ++++++++++++++++- packages/@vuepress/theme-default/util/index.js | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/@vuepress/theme-default/components/SidebarLink.vue b/packages/@vuepress/theme-default/components/SidebarLink.vue index 7d128b4a98..243ce7630b 100644 --- a/packages/@vuepress/theme-default/components/SidebarLink.vue +++ b/packages/@vuepress/theme-default/components/SidebarLink.vue @@ -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 @@ -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')]) +}