Skip to content

Commit

Permalink
fix(theme): ignore inner-page items in next/prev link (#3663)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
chgeo and brc-dd committed Mar 17, 2024
1 parent df8753b commit b50a8a1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/client/theme-default/composables/prev-next.ts
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}

0 comments on commit b50a8a1

Please sign in to comment.