Skip to content

Commit

Permalink
feat(theme): support external links in sidebar
Browse files Browse the repository at this point in the history
close vuejs#205
  • Loading branch information
FrodeI committed Jan 2, 2022
1 parent 51978a3 commit 9e032ef
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/client/theme-default/components/SideBarLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { FunctionalComponent, h, VNode } from 'vue'
import { useRoute, useData } from 'vitepress'
import { Header } from '../../shared'
import { DefaultTheme } from '../config'
import { joinUrl, isActive } from '../utils'
import { joinUrl, isActive, isExternal as isExternalCheck } from '../utils'
import OutboundLink from './icons/OutboundLink.vue'

interface HeaderWithChildren extends Header {
children?: Header[]
Expand All @@ -19,7 +20,8 @@ export const SideBarLink: FunctionalComponent<{

const headers = route.data.headers
const text = props.item.text
const link = resolveLink(site.value.base, props.item.link)
const isExternal = props.item.link && isExternalCheck(props.item.link)
const link = isExternal ? props.item.link : resolveLink(site.value.base, props.item.link)
const children = (props.item as DefaultTheme.SideBarGroup).children
const active = isActive(route, props.item.link)
const childItems =
Expand All @@ -32,9 +34,16 @@ export const SideBarLink: FunctionalComponent<{
link ? 'a' : 'p',
{
class: { 'sidebar-link-item': true, active },
href: link
},
text
href: link,
target: isExternal ? `_blank` : null,
rel: isExternal ? `noopener noreferrer` : null
}, isExternal
? [
text,
' ',
h(OutboundLink),
]
: text
),
childItems
])
Expand Down

0 comments on commit 9e032ef

Please sign in to comment.