diff --git a/theme/src/client/components/VPSidebarItem.vue b/theme/src/client/components/VPSidebarItem.vue index 083f3a12..7b03646d 100644 --- a/theme/src/client/components/VPSidebarItem.vue +++ b/theme/src/client/components/VPSidebarItem.vue @@ -38,7 +38,8 @@ const textTag = computed(() => { const itemRole = computed(() => (isLink.value ? undefined : 'button')) -const isSeparator = computed(() => item.link?.startsWith('---')) +const SEPARATOR_RE = /^-{3,}$/ +const isSeparator = computed(() => item.link && SEPARATOR_RE.test(item.link)) const classes = computed(() => [ [`level-${depth}`], diff --git a/theme/src/client/composables/prev-next.ts b/theme/src/client/composables/prev-next.ts index 1e64a64f..51b292f7 100644 --- a/theme/src/client/composables/prev-next.ts +++ b/theme/src/client/composables/prev-next.ts @@ -14,6 +14,8 @@ interface UsePrevNextResult { next: ComputedRef } +const SEPARATOR_RE = /^-{3,}$/ + export function usePrevNext(): UsePrevNextResult { const route = useRoute() const { frontmatter, theme } = useData() @@ -100,10 +102,13 @@ function flatSidebar(sidebar: ThemeSidebarItem[], res: NavItemWithLink[] = []): * Resolve `prev` or `next` config from sidebar items */ function resolveFromSidebarItems(sidebarItems: NavItemWithLink[], currentPath: string, offset: number): null | NavItemWithLink { - const index = sidebarItems.findIndex(item => resolveRouteFullPath(item.link) === currentPath) - if (index !== -1) { - const targetItem = sidebarItems[index + offset] - if (targetItem?.link) { + let index = sidebarItems.findIndex(item => resolveRouteFullPath(item.link) === currentPath) + if (index === -1) + return null + // eslint-disable-next-line no-cond-assign + while ((index += offset) >= 0) { + const targetItem = sidebarItems[index] + if (targetItem?.link && !SEPARATOR_RE.test(targetItem.link)) { return targetItem } }