|
|
@ -106,6 +106,7 @@ function createVitePressPlugin({
|
|
|
|
|
|
|
|
|
|
|
|
const pageDataWithLinks = {
|
|
|
|
const pageDataWithLinks = {
|
|
|
|
...pageData,
|
|
|
|
...pageData,
|
|
|
|
|
|
|
|
// TODO: this doesn't work with locales
|
|
|
|
...getNextAndPrev(siteData.themeConfig, ctx.path)
|
|
|
|
...getNextAndPrev(siteData.themeConfig, ctx.path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await next()
|
|
|
|
await next()
|
|
|
@ -131,21 +132,31 @@ function createVitePressPlugin({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: share types from SideBarLink, SideBarGroup, etc. We are also assuming
|
|
|
|
|
|
|
|
// all themes follow this structure, in which case, we should expose the type
|
|
|
|
|
|
|
|
// instead of having any for themeConfig or not nest `sidebar` inside
|
|
|
|
|
|
|
|
// `themeConfig`, specially given it must be specified inside `locales` if there
|
|
|
|
|
|
|
|
// are any
|
|
|
|
|
|
|
|
interface SideBarLink {
|
|
|
|
|
|
|
|
text: string
|
|
|
|
|
|
|
|
link: string
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getNextAndPrev(themeConfig: any, pagePath: string) {
|
|
|
|
function getNextAndPrev(themeConfig: any, pagePath: string) {
|
|
|
|
if (!themeConfig.sidebar) {
|
|
|
|
if (!themeConfig.sidebar) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const sidebar = themeConfig.sidebar
|
|
|
|
const sidebar = themeConfig.sidebar
|
|
|
|
let candidates: { text: string; link: string }[] = []
|
|
|
|
let candidates: SideBarLink[] = []
|
|
|
|
Object.keys(sidebar).forEach((k) => {
|
|
|
|
Object.keys(sidebar).forEach((k) => {
|
|
|
|
if (!pagePath.startsWith(k)) {
|
|
|
|
if (!pagePath.startsWith(k)) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sidebar[k].forEach((sidebarItem: { [key: string]: any }) => {
|
|
|
|
sidebar[k].forEach((sidebarItem: { children?: SideBarLink[] }) => {
|
|
|
|
if (!sidebarItem.children) {
|
|
|
|
if (!sidebarItem.children) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sidebarItem.children.forEach((candidate: any) => {
|
|
|
|
sidebarItem.children.forEach((candidate) => {
|
|
|
|
candidates.push(candidate)
|
|
|
|
candidates.push(candidate)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -153,17 +164,22 @@ function getNextAndPrev(themeConfig: any, pagePath: string) {
|
|
|
|
|
|
|
|
|
|
|
|
const path = pagePath.replace(/\.(md|html)$/, '')
|
|
|
|
const path = pagePath.replace(/\.(md|html)$/, '')
|
|
|
|
const currentLinkIndex = candidates.findIndex((v) => v.link === path)
|
|
|
|
const currentLinkIndex = candidates.findIndex((v) => v.link === path)
|
|
|
|
const hideNextLink = themeConfig.nextLinks === false
|
|
|
|
|
|
|
|
const hidePrevLink = themeConfig.prevLinks === false
|
|
|
|
const nextAndPrev: { prev?: SideBarLink; next?: SideBarLink } = {}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
if (
|
|
|
|
...(currentLinkIndex !== -1 && !hideNextLink
|
|
|
|
themeConfig.nextLinks !== false &&
|
|
|
|
? { next: candidates[currentLinkIndex + 1] }
|
|
|
|
currentLinkIndex > -1 &&
|
|
|
|
: {}),
|
|
|
|
currentLinkIndex < candidates.length - 1
|
|
|
|
...(currentLinkIndex !== -1 && !hidePrevLink
|
|
|
|
) {
|
|
|
|
? { prev: candidates[currentLinkIndex - 1] }
|
|
|
|
nextAndPrev.next = candidates[currentLinkIndex + 1]
|
|
|
|
: {})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (themeConfig.prevLinks !== false && currentLinkIndex > 0) {
|
|
|
|
|
|
|
|
nextAndPrev.next = candidates[currentLinkIndex - 1]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nextAndPrev
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function createServer(options: ServerConfig = {}) {
|
|
|
|
export async function createServer(options: ServerConfig = {}) {
|
|
|
|