docs: fixes to search in API references (#11959)
This commit is contained in:
@@ -29,17 +29,19 @@ export async function GET() {
|
||||
const dom = await JSDOM.fromURL(getUrl(area))
|
||||
const headers = dom.window.document.querySelectorAll("h2")
|
||||
headers.forEach((header) => {
|
||||
if (!header.textContent) {
|
||||
if (!header.textContent || !header.nextSibling?.textContent) {
|
||||
return
|
||||
}
|
||||
const normalizedHeaderContent = header.textContent.replaceAll("#", "")
|
||||
const description = header.nextSibling?.textContent
|
||||
|
||||
const objectID = getSectionId([header.textContent])
|
||||
const objectID = getSectionId([normalizedHeaderContent])
|
||||
const url = getUrl(area, objectID)
|
||||
indices.push({
|
||||
objectID: getObjectId(area, `${objectID}-mdx-section`),
|
||||
hierarchy: getHierarchy(area, [header.textContent]),
|
||||
hierarchy: getHierarchy(area, [normalizedHeaderContent]),
|
||||
type: `content`,
|
||||
content: header.textContent,
|
||||
content: description || "",
|
||||
url,
|
||||
url_without_variables: url,
|
||||
url_without_anchor: url,
|
||||
@@ -60,6 +62,7 @@ export async function GET() {
|
||||
hierarchy: getHierarchy(area, [tag.name]),
|
||||
type: "lvl1",
|
||||
content: null,
|
||||
description: tag.description,
|
||||
url,
|
||||
url_without_variables: url,
|
||||
url_without_anchor: url,
|
||||
@@ -77,7 +80,7 @@ export async function GET() {
|
||||
const url = getUrl(area, operationName)
|
||||
indices.push({
|
||||
objectID: getObjectId(area, operationName),
|
||||
hierarchy: getHierarchy(area, [tag || "", operation.summary]),
|
||||
hierarchy: getHierarchy(area, [operation.summary]),
|
||||
type: "content",
|
||||
content: operation.summary,
|
||||
content_camel: operation.summary,
|
||||
@@ -100,7 +103,6 @@ export async function GET() {
|
||||
indices.push({
|
||||
objectID: getObjectId(area, operationDescriptionId),
|
||||
hierarchy: getHierarchy(area, [
|
||||
tag || "",
|
||||
operation.summary,
|
||||
operation.description,
|
||||
]),
|
||||
@@ -124,6 +126,7 @@ export async function GET() {
|
||||
|
||||
return NextResponse.json({
|
||||
message: "done",
|
||||
total: indices.length,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import type { OpenAPI } from "types"
|
||||
import { capitalize, usePrevious, useSearch, useSidebar } from "docs-ui"
|
||||
import { capitalize, usePrevious, useSidebar } from "docs-ui"
|
||||
import { createContext, useContext, useEffect, useMemo, useState } from "react"
|
||||
import { usePathname } from "next/navigation"
|
||||
|
||||
@@ -22,7 +22,6 @@ type AreaProviderProps = {
|
||||
const AreaProvider = ({ area: passedArea, children }: AreaProviderProps) => {
|
||||
const [area, setArea] = useState<OpenAPI.Area>(passedArea)
|
||||
const prevArea = usePrevious(area)
|
||||
const { defaultFilters, setDefaultFilters } = useSearch()
|
||||
const { setActivePath } = useSidebar()
|
||||
const pathname = usePathname()
|
||||
|
||||
@@ -30,12 +29,6 @@ const AreaProvider = ({ area: passedArea, children }: AreaProviderProps) => {
|
||||
return capitalize(area)
|
||||
}, [area])
|
||||
|
||||
useEffect(() => {
|
||||
if (!defaultFilters.includes(`${area}-v2`)) {
|
||||
setDefaultFilters([`${area}-v2`])
|
||||
}
|
||||
}, [area, defaultFilters, setDefaultFilters])
|
||||
|
||||
useEffect(() => {
|
||||
setActivePath(null)
|
||||
}, [pathname])
|
||||
|
||||
Reference in New Issue
Block a user