fix(theme): ignore inner-page items in next/prev link (#3663)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/3664/head
Christian Georgi 8 months ago committed by GitHub
parent df8753bd92
commit b50a8a1325
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -8,7 +8,10 @@ export function usePrevNext() {
return computed(() => {
const sidebar = getSidebar(theme.value.sidebar, page.value.relativePath)
const candidates = getFlatSideBarLinks(sidebar)
const links = getFlatSideBarLinks(sidebar)
// ignore inner-page links with hashes
const candidates = uniqBy(links, (link) => link.link.replace(/[?#].*$/, ''))
const index = candidates.findIndex((link) => {
return isActive(page.value.relativePath, link.link)
@ -61,3 +64,11 @@ export function usePrevNext() {
}
})
}
function uniqBy<T>(array: T[], keyFn: (item: T) => any): T[] {
const seen = new Set()
return array.filter((item) => {
const k = keyFn(item)
return seen.has(k) ? false : seen.add(k)
})
}

Loading…
Cancel
Save