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