Skip to content

Commit 65e5d18

Browse files
Copilotbarjin
andauthored
docs: ApiLink generates correct URL for versioned docs (#1870)
`ApiLink` always resolved to `/api/<ClassName>` regardless of the active Docusaurus version, causing broken-link CI failures for PRs that introduce new public classes (which only exist in the unreleased `next` API docs). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
1 parent 6b91edc commit 65e5d18

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

‎website/src/components/ApiLink.jsx‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import React from 'react';
22
import Link from '@docusaurus/Link';
3-
// eslint-disable-next-line import/no-extraneous-dependencies
4-
import { useDocsVersion } from '@docusaurus/theme-common/internal';
3+
import { useDocsVersion } from '@docusaurus/plugin-content-docs/client';
54
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
65

7-
// const pkg = require('../../../packages/crawlee/package.json');
8-
//
9-
// const [v1, v2] = pkg.version.split('.');
10-
// const stable = [v1, v2].join('.');
11-
126
const ApiLink = ({ to, children }) => {
7+
const version = useDocsVersion();
8+
const { siteConfig } = useDocusaurusContext();
9+
10+
if (siteConfig.presets[0][1].docs.disableVersioning || version.isLast) {
11+
return (
12+
<Link to={`/api/${to}`}>{children}</Link>
13+
);
14+
}
15+
1316
return (
14-
<Link to={`/api/${to}`}>{children}</Link>
17+
<Link to={`/api/${version.version === 'current' ? 'next' : version.version}/${to}`}>{children}</Link>
1518
);
16-
17-
// const version = useDocsVersion();
18-
// const { siteConfig } = useDocusaurusContext();
19-
//
20-
// // if (siteConfig.presets[0][1].docs.disableVersioning || version.version === stable) {
21-
// if (siteConfig.presets[0][1].docs.disableVersioning) {
22-
// return (
23-
// <Link to={`/api/${to}`}>{children}</Link>
24-
// );
25-
// }
26-
//
27-
// return (
28-
// <Link to={`/api/${version.version === 'current' ? 'next' : version.version}/${to}`}>{children}</Link>
29-
// );
3019
};
3120

3221
export default ApiLink;

0 commit comments

Comments
 (0)