|
|
@ -9,8 +9,10 @@ import { createMarkdownRenderer } from '../markdown/markdown'
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
getLocaleForPath,
|
|
|
|
getLocaleForPath,
|
|
|
|
slash,
|
|
|
|
slash,
|
|
|
|
|
|
|
|
getSidebar,
|
|
|
|
type DefaultTheme,
|
|
|
|
type DefaultTheme,
|
|
|
|
type MarkdownEnv
|
|
|
|
type MarkdownEnv,
|
|
|
|
|
|
|
|
type SidebarItem
|
|
|
|
} from '../shared'
|
|
|
|
} from '../shared'
|
|
|
|
import { processIncludes } from '../utils/processIncludes'
|
|
|
|
import { processIncludes } from '../utils/processIncludes'
|
|
|
|
|
|
|
|
|
|
|
@ -116,12 +118,37 @@ export async function localSearchPlugin(
|
|
|
|
return id
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getParentTitles(sidebar: SidebarItem[], fileId: string) {
|
|
|
|
|
|
|
|
const titles: string[] = [],
|
|
|
|
|
|
|
|
path: string[] = []
|
|
|
|
|
|
|
|
const backtrack = (sidebar: SidebarItem[] | undefined) => {
|
|
|
|
|
|
|
|
if (!sidebar) return
|
|
|
|
|
|
|
|
for (let i = 0; i < sidebar?.length; i++) {
|
|
|
|
|
|
|
|
if (sidebar[i].link === fileId) {
|
|
|
|
|
|
|
|
titles.push(...path)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
path.push(sidebar[i].text!)
|
|
|
|
|
|
|
|
backtrack(sidebar[i].items)
|
|
|
|
|
|
|
|
path.pop()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
backtrack(sidebar)
|
|
|
|
|
|
|
|
return titles
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function indexFile(page: string) {
|
|
|
|
async function indexFile(page: string) {
|
|
|
|
const file = path.join(siteConfig.srcDir, page)
|
|
|
|
const file = path.join(siteConfig.srcDir, page)
|
|
|
|
// get file metadata
|
|
|
|
// get file metadata
|
|
|
|
const fileId = getDocId(file)
|
|
|
|
const fileId = getDocId(file)
|
|
|
|
const locale = getLocaleForPath(siteConfig.site, page)
|
|
|
|
const locale = getLocaleForPath(siteConfig.site, page)
|
|
|
|
const index = getIndexByLocale(locale)
|
|
|
|
const index = getIndexByLocale(locale)
|
|
|
|
|
|
|
|
const sidebar = getSidebar(
|
|
|
|
|
|
|
|
siteConfig.site?.locales[locale]?.themeConfig?.sidebar ??
|
|
|
|
|
|
|
|
siteConfig.site?.themeConfig.sidebar,
|
|
|
|
|
|
|
|
fileId
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
const parentTitles = getParentTitles(sidebar, fileId.replace(/\.html$/, ''))
|
|
|
|
// retrieve file and split into "sections"
|
|
|
|
// retrieve file and split into "sections"
|
|
|
|
const html = await render(file)
|
|
|
|
const html = await render(file)
|
|
|
|
const sections =
|
|
|
|
const sections =
|
|
|
@ -132,7 +159,8 @@ export async function localSearchPlugin(
|
|
|
|
// add sections to the locale index
|
|
|
|
// add sections to the locale index
|
|
|
|
for await (const section of sections) {
|
|
|
|
for await (const section of sections) {
|
|
|
|
if (!section || !(section.text || section.titles)) break
|
|
|
|
if (!section || !(section.text || section.titles)) break
|
|
|
|
const { anchor, text, titles } = section
|
|
|
|
let { anchor, text, titles } = section
|
|
|
|
|
|
|
|
titles = [...parentTitles, ...titles]
|
|
|
|
const id = anchor ? [fileId, anchor].join('#') : fileId
|
|
|
|
const id = anchor ? [fileId, anchor].join('#') : fileId
|
|
|
|
index.add({
|
|
|
|
index.add({
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|