refactor: Migrate documentation content, rebuild UI components, and update core architecture.
This commit is contained in:
5
lib/search/algolia.ts
Normal file
5
lib/search/algolia.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const algoliaConfig = {
|
||||
appId: process.env.NEXT_PUBLIC_ALGOLIA_DOCSEARCH_APP_ID,
|
||||
apiKey: process.env.NEXT_PUBLIC_ALGOLIA_DOCSEARCH_API_KEY,
|
||||
indexName: process.env.NEXT_PUBLIC_ALGOLIA_DOCSEARCH_INDEX_NAME,
|
||||
}
|
||||
43
lib/search/built-in.ts
Normal file
43
lib/search/built-in.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { ROUTES, type EachRoute } from "../routes"
|
||||
|
||||
export type SearchResult = {
|
||||
title: string
|
||||
href: string
|
||||
noLink?: boolean
|
||||
items?: undefined
|
||||
score?: number
|
||||
}
|
||||
|
||||
function helperSearch(
|
||||
query: string,
|
||||
node: EachRoute,
|
||||
prefix: string,
|
||||
currenLevel: number,
|
||||
maxLevel?: number
|
||||
) {
|
||||
const res: EachRoute[] = []
|
||||
let parentHas = false
|
||||
|
||||
const nextLink = `${prefix}${node.href}`
|
||||
if (!node.noLink && node.title.toLowerCase().includes(query.toLowerCase())) {
|
||||
res.push({ ...node, items: undefined, href: nextLink })
|
||||
parentHas = true
|
||||
}
|
||||
const goNext = maxLevel ? currenLevel < maxLevel : true
|
||||
if (goNext)
|
||||
node.items?.forEach((item) => {
|
||||
const innerRes = helperSearch(query, item, nextLink, currenLevel + 1, maxLevel)
|
||||
if (!!innerRes.length && !parentHas && !node.noLink) {
|
||||
res.push({ ...node, items: undefined, href: nextLink })
|
||||
parentHas = true
|
||||
}
|
||||
res.push(...innerRes)
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
export function advanceSearch(query: string) {
|
||||
return ROUTES.map((node) =>
|
||||
helperSearch(query, node, "", 1, query.length == 0 ? 2 : undefined)
|
||||
).flat()
|
||||
}
|
||||
7
lib/search/config.ts
Normal file
7
lib/search/config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import docuConfig from "@/docu.json"
|
||||
|
||||
export type SearchType = "default" | "algolia"
|
||||
|
||||
export const searchConfig = {
|
||||
type: (docuConfig.search?.type as SearchType) ?? "default",
|
||||
}
|
||||
Reference in New Issue
Block a user