fix(theme): pass target and rel to prev/next page links (#5297)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
pull/4493/merge
TowyTowy 1 week ago committed by GitHub
parent d30f32246d
commit 6b5e7704a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,4 +1,8 @@
import { getSidebar, hasActiveLink } from 'client/theme-default/support/sidebar'
import {
getFlatSideBarLinks,
getSidebar,
hasActiveLink
} from 'client/theme-default/support/sidebar'
describe('client/theme-default/support/sidebar', () => {
describe('getSidebar', () => {
@ -137,6 +141,43 @@ describe('client/theme-default/support/sidebar', () => {
})
})
describe('getFlatSideBarLinks', () => {
test('flattens nested items and preserves link metadata', () => {
const sidebar = [
{
text: 'Group',
items: [
{ text: 'Intro', link: '/intro' },
{
text: 'External',
link: 'https://example.com/',
target: '_self',
rel: 'noopener',
docFooterText: 'Go external'
}
]
}
]
expect(getFlatSideBarLinks(sidebar)).toStrictEqual([
{
text: 'Intro',
link: '/intro',
docFooterText: undefined,
rel: undefined,
target: undefined
},
{
text: 'External',
link: 'https://example.com/',
docFooterText: 'Go external',
rel: 'noopener',
target: '_self'
}
])
})
})
describe('hasActiveLink', () => {
test('checks `SidebarItem`', () => {
const item = {

@ -53,6 +53,8 @@ const showFooter = computed(
v-if="control.prev?.link"
class="pager-link prev"
:href="control.prev.link"
:target="control.prev.target"
:rel="control.prev.rel"
>
<span
class="desc"
@ -66,6 +68,8 @@ const showFooter = computed(
v-if="control.next?.link"
class="pager-link next"
:href="control.next.link"
:target="control.next.target"
:rel="control.next.rel"
>
<span
class="desc"

@ -40,7 +40,15 @@ export function usePrevNext() {
link:
(typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.link
: undefined) ?? candidates[index - 1]?.link
: undefined) ?? candidates[index - 1]?.link,
target:
(typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.target
: undefined) ?? candidates[index - 1]?.target,
rel:
(typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.rel
: undefined) ?? candidates[index - 1]?.rel
},
next: hideNext
? undefined
@ -56,11 +64,19 @@ export function usePrevNext() {
link:
(typeof frontmatter.value.next === 'object'
? frontmatter.value.next.link
: undefined) ?? candidates[index + 1]?.link
: undefined) ?? candidates[index + 1]?.link,
target:
(typeof frontmatter.value.next === 'object'
? frontmatter.value.next.target
: undefined) ?? candidates[index + 1]?.target,
rel:
(typeof frontmatter.value.next === 'object'
? frontmatter.value.next.rel
: undefined) ?? candidates[index + 1]?.rel
}
} as {
prev?: { text?: string; link?: string }
next?: { text?: string; link?: string }
prev?: { text?: string; link?: string; target?: string; rel?: string }
next?: { text?: string; link?: string; target?: string; rel?: string }
}
})
}

@ -6,6 +6,8 @@ export interface SidebarLink {
text: string
link: string
docFooterText?: string
rel?: string
target?: string
}
type SidebarItem = DefaultTheme.SidebarItem
@ -75,7 +77,9 @@ export function getFlatSideBarLinks(sidebar: SidebarItem[]): SidebarLink[] {
links.push({
text: item.text,
link: item.link,
docFooterText: item.docFooterText
docFooterText: item.docFooterText,
rel: item.rel,
target: item.target
})
}

Loading…
Cancel
Save