Skip to content

Commit e477cdf

Browse files
committedAug 25, 2023
feat(theme): allow setting rel and target on sidebar links
closes #2851
1 parent 3992202 commit e477cdf

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed
 

‎src/client/theme-default/components/VPSidebarItem.vue

+23-8
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ const {
2020
toggle
2121
} = useSidebarControl(computed(() => props.item))
2222
23-
const sectionTag = computed(() => hasChildren.value ? 'section' : `div`)
23+
const sectionTag = computed(() => (hasChildren.value ? 'section' : `div`))
2424
25-
const linkTag = computed(() => isLink.value ? 'a' : 'div')
25+
const linkTag = computed(() => (isLink.value ? 'a' : 'div'))
2626
2727
const textTag = computed(() => {
2828
return !hasChildren.value
2929
? 'p'
30-
: props.depth + 2 === 7 ? 'p' : `h${props.depth + 2}`
30+
: props.depth + 2 === 7
31+
? 'p'
32+
: `h${props.depth + 2}`
3133
})
3234
33-
const itemRole = computed(() => isLink.value ? undefined : 'button')
35+
const itemRole = computed(() => (isLink.value ? undefined : 'button'))
3436
3537
const classes = computed(() => [
3638
[`level-${props.depth}`],
@@ -55,20 +57,33 @@ function onCaretClick() {
5557

5658
<template>
5759
<component :is="sectionTag" class="VPSidebarItem" :class="classes">
58-
<div v-if="item.text"
60+
<div
61+
v-if="item.text"
5962
class="item"
6063
:role="itemRole"
61-
v-on="item.items ? { click: onItemInteraction, keydown: onItemInteraction } : {}"
64+
v-on="
65+
item.items
66+
? { click: onItemInteraction, keydown: onItemInteraction }
67+
: {}
68+
"
6269
:tabindex="item.items && 0"
6370
>
6471
<div class="indicator" />
6572

66-
<VPLink v-if="item.link" :tag="linkTag" class="link" :href="item.link">
73+
<VPLink
74+
v-if="item.link"
75+
:tag="linkTag"
76+
class="link"
77+
:href="item.link"
78+
:rel="item.rel"
79+
:target="item.target"
80+
>
6781
<component :is="textTag" class="text" v-html="item.text" />
6882
</VPLink>
6983
<component v-else :is="textTag" class="text" v-html="item.text" />
7084

71-
<div v-if="item.collapsed != null"
85+
<div
86+
v-if="item.collapsed != null"
7287
class="caret"
7388
role="button"
7489
aria-label="toggle section"

‎types/default-theme.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ export namespace DefaultTheme {
240240
* Customize text that appears on the footer of previous/next page.
241241
*/
242242
docFooterText?: string
243+
244+
rel?: string
245+
target?: string
243246
}
244247

245248
/**

0 commit comments

Comments
 (0)
Please sign in to comment.