@neosjs/vitepress-theme
Version:
NeosJS VitePress theme
27 lines (26 loc) • 1.64 kB
JavaScript
import { computed } from "vue";
import { isActive } from "../shared.mjs";
import { getFlatSideBarLinks, getSidebar } from "../support/sidebar.mjs";
import { useData } from "./data.mjs";
export function usePrevNext() {
const { page, theme, frontmatter } = useData();
return computed(() => {
const sidebar = getSidebar(theme.value.sidebar, page.value.relativePath);
const candidates = getFlatSideBarLinks(sidebar);
const index = candidates.findIndex((link) => {
return isActive(page.value.relativePath, link.link);
});
const hidePrev = theme.value.docFooter?.prev === false && !frontmatter.value.prev || frontmatter.value.prev === false;
const hideNext = theme.value.docFooter?.next === false && !frontmatter.value.next || frontmatter.value.next === false;
return {
prev: hidePrev ? void 0 : {
text: (typeof frontmatter.value.prev === "string" ? frontmatter.value.prev : typeof frontmatter.value.prev === "object" ? frontmatter.value.prev.text : void 0) ?? candidates[index - 1]?.docFooterText ?? candidates[index - 1]?.text,
link: (typeof frontmatter.value.prev === "object" ? frontmatter.value.prev.link : void 0) ?? candidates[index - 1]?.link
},
next: hideNext ? void 0 : {
text: (typeof frontmatter.value.next === "string" ? frontmatter.value.next : typeof frontmatter.value.next === "object" ? frontmatter.value.next.text : void 0) ?? candidates[index + 1]?.docFooterText ?? candidates[index + 1]?.text,
link: (typeof frontmatter.value.next === "object" ? frontmatter.value.next.link : void 0) ?? candidates[index + 1]?.link
}
};
});
}