docs: add prepare script to generate sidebar (#11894)
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
"use client"
|
||||
|
||||
import { useScrollController, useSidebar, H2 as UiH2 } from "docs-ui"
|
||||
import { getSectionId } from "docs-utils"
|
||||
import { useEffect, useMemo, useRef, useState } from "react"
|
||||
import getSectionId from "../../../utils/get-section-id"
|
||||
import { Sidebar } from "types"
|
||||
|
||||
type H2Props = React.HTMLAttributes<HTMLHeadingElement>
|
||||
|
||||
const H2 = ({ children, ...props }: H2Props) => {
|
||||
const headingRef = useRef<HTMLHeadingElement>(null)
|
||||
const { activePath, addItems, removeItems, shownSidebar } = useSidebar()
|
||||
const { activePath } = useSidebar()
|
||||
const { scrollableElement, scrollToElement } = useScrollController()
|
||||
const [scrolledFirstTime, setScrolledFirstTime] = useState(false)
|
||||
|
||||
@@ -28,30 +27,6 @@ const H2 = ({ children, ...props }: H2Props) => {
|
||||
setScrolledFirstTime(scrolledFirstTime)
|
||||
}, [scrollableElement, headingRef, id])
|
||||
|
||||
useEffect(() => {
|
||||
if (!shownSidebar) {
|
||||
return
|
||||
}
|
||||
const items: Sidebar.SidebarItem[] = [
|
||||
{
|
||||
type: "link",
|
||||
path: `${id}`,
|
||||
title: children as string,
|
||||
loaded: true,
|
||||
},
|
||||
]
|
||||
addItems(items, {
|
||||
sidebar_id: shownSidebar.sidebar_id,
|
||||
})
|
||||
|
||||
return () => {
|
||||
removeItems({
|
||||
items,
|
||||
sidebar_id: shownSidebar.sidebar_id,
|
||||
})
|
||||
}
|
||||
}, [id, shownSidebar?.sidebar_id])
|
||||
|
||||
return (
|
||||
<UiH2 {...props} id={id} passRef={headingRef}>
|
||||
{children}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { MDXContentClientProps } from "@/components/MDXContent/Client"
|
||||
import type { MDXContentServerProps } from "@/components/MDXContent/Server"
|
||||
import type { SecuritySchemeObject } from "@/types/openapi"
|
||||
import type { OpenAPI } from "types"
|
||||
import getSecuritySchemaTypeName from "@/utils/get-security-schema-type-name"
|
||||
import clsx from "clsx"
|
||||
import { Loading } from "docs-ui"
|
||||
@@ -21,7 +21,7 @@ const MDXContentServer = dynamic<MDXContentServerProps>(
|
||||
) as React.FC<MDXContentServerProps>
|
||||
|
||||
export type SecurityDescriptionProps = {
|
||||
securitySchema: SecuritySchemeObject
|
||||
securitySchema: OpenAPI.SecuritySchemeObject
|
||||
isServer?: boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import dynamic from "next/dynamic"
|
||||
import type { OpenAPIV3 } from "openapi-types"
|
||||
import type { OpenAPI } from "types"
|
||||
import type { SecurityDescriptionProps } from "./Description"
|
||||
import { Fragment } from "react"
|
||||
|
||||
@@ -8,7 +8,7 @@ const SecurityDescription = dynamic<SecurityDescriptionProps>(
|
||||
) as React.FC<SecurityDescriptionProps>
|
||||
|
||||
type SecurityProps = {
|
||||
specs?: OpenAPIV3.Document
|
||||
specs?: OpenAPI.OpenAPIV3.Document
|
||||
}
|
||||
|
||||
const Security = ({ specs }: SecurityProps) => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { MDXComponents } from "mdx/types"
|
||||
import Security from "./Security"
|
||||
import type { OpenAPIV3 } from "openapi-types"
|
||||
import type { OpenAPI } from "types"
|
||||
import H2 from "./H2"
|
||||
import { Link, MDXComponents as UiMDXComponents } from "docs-ui"
|
||||
|
||||
export type ScopeType = {
|
||||
specs?: OpenAPIV3.Document
|
||||
specs?: OpenAPI.OpenAPIV3.Document
|
||||
addToSidebar?: boolean
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user