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

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
pull/5091/merge
TowyTowy 2 months 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('client/theme-default/support/sidebar', () => {
describe('getSidebar', () => { 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', () => { describe('hasActiveLink', () => {
test('checks `SidebarItem`', () => { test('checks `SidebarItem`', () => {
const item = { const item = {

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

@ -40,7 +40,15 @@ export function usePrevNext() {
link: link:
(typeof frontmatter.value.prev === 'object' (typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.link ? 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 next: hideNext
? undefined ? undefined
@ -56,11 +64,19 @@ export function usePrevNext() {
link: link:
(typeof frontmatter.value.next === 'object' (typeof frontmatter.value.next === 'object'
? frontmatter.value.next.link ? 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 { } as {
prev?: { text?: string; link?: string } prev?: { text?: string; link?: string; target?: string; rel?: string }
next?: { text?: string; link?: string } next?: { text?: string; link?: string; target?: string; rel?: string }
} }
}) })
} }

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

Loading…
Cancel
Save