Skip to content

Commit b50a8a1

Browse files
chgeobrc-dd
andauthoredMar 17, 2024··
fix(theme): ignore inner-page items in next/prev link (#3663)
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
1 parent df8753b commit b50a8a1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎src/client/theme-default/composables/prev-next.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ export function usePrevNext() {
88

99
return computed(() => {
1010
const sidebar = getSidebar(theme.value.sidebar, page.value.relativePath)
11-
const candidates = getFlatSideBarLinks(sidebar)
11+
const links = getFlatSideBarLinks(sidebar)
12+
13+
// ignore inner-page links with hashes
14+
const candidates = uniqBy(links, (link) => link.link.replace(/[?#].*$/, ''))
1215

1316
const index = candidates.findIndex((link) => {
1417
return isActive(page.value.relativePath, link.link)
@@ -61,3 +64,11 @@ export function usePrevNext() {
6164
}
6265
})
6366
}
67+
68+
function uniqBy<T>(array: T[], keyFn: (item: T) => any): T[] {
69+
const seen = new Set()
70+
return array.filter((item) => {
71+
const k = keyFn(item)
72+
return seen.has(k) ? false : seen.add(k)
73+
})
74+
}

0 commit comments

Comments
 (0)
Please sign in to comment.