Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-squids-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": patch
---

fix: incorrect auto generated API anchor links
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
"version": "changeset version && yarn --no-immutable"
},
"dependencies": {
"@cspell/eslint-plugin": "^8.19.4 || ^9.0.2",
"@eslint-react/eslint-plugin": "^1.52.1",
"@cspell/eslint-plugin": "^8.19.4 || ^9.1.1",
"@eslint-react/eslint-plugin": "^1.52.2",
"@inquirer/prompts": "^7.5.3",
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
"@playwright/browser-chromium": "^1.53.0",
"@playwright/browser-chromium": "^1.53.1",
"@rsbuild/plugin-react": "^1.3.2",
"@rsbuild/plugin-sass": "^1.3.2",
"@rsbuild/plugin-svgr": "^1.2.0",
Expand All @@ -77,19 +77,19 @@
"commander": "^13.1.0 || ^14.0.0",
"ejs": "^3.1.10",
"es-toolkit": "^1.39.3",
"eslint": "^9.28.0",
"eslint-plugin-mdx": "^3.4.2",
"eslint": "^9.29.0",
"eslint-plugin-mdx": "^3.5.0",
"html-tag-names": "^2.1.0",
"mdast-util-mdx": "^3.0.0",
"mdast-util-mdx-jsx": "^3.2.0",
"mermaid": "^11.6.0",
"openai": "^5.3.0",
"openai": "^5.5.1",
"openapi-types": "^12.1.3",
"p-ratelimit": "^1.0.1",
"pdf-lib": "^1.17.1",
"pdf-merger-js": "^5.1.2",
"picomatch": "^4.0.2",
"playwright": "^1.53.0",
"playwright": "^1.53.1",
"react-markdown": "^10.1.0",
"rehype-raw": "^7.0.0",
"rehype-sanitize": "^6.0.0",
Expand All @@ -104,20 +104,20 @@
"tinyglobby": "^0.2.14",
"type-fest": "^4.41.0",
"typescript": "^5.8.3",
"typescript-eslint": "^8.34.0",
"typescript-eslint": "^8.34.1",
"x-fetch": "^0.2.6",
"yaml": "^2.8.0",
"yoctocolors": "^2.1.1"
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.29.4",
"@eslint/js": "^9.28.0",
"@eslint/js": "^9.29.0",
"@swc-node/register": "^1.10.10",
"@swc/core": "1.12.0",
"@swc/core": "1.12.2",
"@types/cli-progress": "^3.11.6",
"@types/ejs": "^3.1.5",
"@types/node": "^22.15.31",
"@types/node": "^22.15.32",
"@types/picomatch": "^4.0.0",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/sitemap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ export function sitemapPlugin(options?: Options): RspressPlugin {
...options,
}
const sitemaps: Sitemap[] = []
const set = new Set()
const set = new Set<string>()
return {
name: 'rspress-plugin-sitemap',
extendPageData(pageData, isProd) {
if (!isProd || set.has(pageData.id)) {
if (!isProd || set.has(pageData.routePath)) {
return
}
set.add(pageData.id)
set.add(pageData.routePath)
sitemaps.push({
loc: `${options.domain}${pageData.routePath}`,
lastmod: fs.statSync(pageData._filepath).mtime.toISOString(),
Expand Down
18 changes: 9 additions & 9 deletions src/runtime/components/OpenAPIPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { OpenAPIProperties, OpenAPIProperty, OpenAPIRef } from './OpenAPIRef.js'
import { HeadingTitle } from './_HeadingTitle.js'
import { RefLink } from './_RefLink.js'
import { X } from './_X.js'
import { UidProvider } from './_context.js'

export interface OpenAPIPathProps {
/**
Expand Down Expand Up @@ -212,15 +213,15 @@ export const OpenAPIPath = ({
}

return (
<>
<HeadingTitle slugger={slugger} uid={uid} level={2}>
<UidProvider value={uid}>
<HeadingTitle slugger={slugger} level={2}>
{pathPrefix}
{path}
</HeadingTitle>

{pathItem.parameters && (
<>
<HeadingTitle slugger={slugger} uid={uid} level={3}>
<HeadingTitle slugger={slugger} level={3}>
Common Parameters
</HeadingTitle>
<OpenAPIParameters
Expand Down Expand Up @@ -254,22 +255,22 @@ export const OpenAPIPath = ({

return (
<Fragment key={method}>
<HeadingTitle slugger={slugger} uid={uid} level={3}>
<HeadingTitle slugger={slugger} level={3}>
<code>{method}</code>
{summary}
</HeadingTitle>
<Markdown>{description}</Markdown>
{parameters && (
<>
<HeadingTitle slugger={slugger} uid={uid} level={4}>
<HeadingTitle slugger={slugger} level={4}>
Parameters
</HeadingTitle>
<OpenAPIParameters parameters={parameters} openapi={openapi} />
</>
)}
{requestBodySchema && (
<>
<HeadingTitle slugger={slugger} uid={uid} level={4}>
<HeadingTitle slugger={slugger} level={4}>
Request Body
</HeadingTitle>
<X.p>
Expand All @@ -281,7 +282,7 @@ export const OpenAPIPath = ({
{/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */}
{responses && (
<>
<HeadingTitle slugger={slugger} uid={uid} level={4}>
<HeadingTitle slugger={slugger} level={4}>
Response
</HeadingTitle>
<OpenAPIResponses responses={responses} openapi={openapi} />
Expand All @@ -297,12 +298,11 @@ export const OpenAPIPath = ({
key={ref}
schema={ref}
openapiPath={openapiPath}
uid={uid}
collectRefs={false}
/>
)
})}
</>
</UidProvider>
)
}

Expand Down
14 changes: 7 additions & 7 deletions src/runtime/components/OpenAPIRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Markdown } from './Markdown.js'
import { HeadingTitle } from './_HeadingTitle.js'
import { RefLink } from './_RefLink.js'
import { X } from './_X.js'
import { UidProvider, useUid } from './_context.js'

export interface OpenAPIRefProps {
/**
Expand All @@ -19,7 +20,6 @@ export interface OpenAPIRefProps {
* The specific path to the OpenAPI schema, otherwise the first matched will be used.
*/
openapiPath?: string
uid?: string
collectRefs?: boolean
}

Expand Down Expand Up @@ -150,14 +150,15 @@ const getRefsForSchema = (
export const OpenAPIRef = ({
schema,
openapiPath: openapiPath_,
uid,
collectRefs = true,
}: OpenAPIRefProps) => {
const { page } = usePageData()

let uid = useUid()

const innerUid = useId()

if (uid == null) {
if (!uid) {
uid = innerUid
}

Expand Down Expand Up @@ -190,8 +191,8 @@ export const OpenAPIRef = ({
}

return (
<>
<HeadingTitle uid={uid} slug={schema} level={2}>
<UidProvider value={uid}>
<HeadingTitle slug={schema} level={2}>
{modelName(schema)}
</HeadingTitle>
<Markdown>{schemaItem.description}</Markdown>
Expand All @@ -206,11 +207,10 @@ export const OpenAPIRef = ({
key={schema}
schema={schema}
openapiPath={openapiPath}
uid={uid}
collectRefs={false}
/>
))}
</>
</UidProvider>
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/components/_HeadingTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import BananaSlug from 'github-slugger'
import { Children, type ReactNode, useMemo } from 'react'

import { X } from './_X.js'
import { useUid } from './_context.js'

export interface HeadingTitleProps {
slug?: string
slugger?: BananaSlug
uid?: string
level: 1 | 2 | 3 | 4 | 5 | 6
children: ReactNode
}

// TODO: use context to simplify the usage of `slugger` and `uid`
// TODO: use context to simplify the usage of `slugger`
export const HeadingTitle = ({
slug,
slugger,
uid,
level,
children,
}: HeadingTitleProps) => {
const uid = useUid()
const HeadingComponents = useMemo(() => {
return [null, X.h1, X.h2, X.h3, X.h4, X.h5, X.h6] as const
}, [])
Expand Down
7 changes: 5 additions & 2 deletions src/runtime/components/_RefLink.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { COMMON_REFS, modelName } from '../utils.js'

import { X } from './_X.js'
import { useUid } from './_context.js'

export interface RefLinkProps {
$ref?: string
}

export const RefLink = ({ $ref }: RefLinkProps) => {
const uid = useUid()

if (!$ref) {
return null
}

const ref = $ref.replace('/components/schemas/', '')
const ref = $ref.replace('/components/schemas/', '').slice(1)
const refName = modelName(ref)
return <X.a href={COMMON_REFS[ref.slice(1)] || ref}>{refName}</X.a>
return <X.a href={COMMON_REFS[ref] || `#${uid}-${ref}`}>{refName}</X.a>
}
7 changes: 7 additions & 0 deletions src/runtime/components/_context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createContext, use } from 'react'

export const UidContext = createContext<string>('')

export const useUid = () => use(UidContext)

export const UidProvider = UidContext.Provider
Loading