Skip to content

Commit 1427dd9

Browse files
Fix issues with API docs
1 parent dd76b66 commit 1427dd9

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

docusaurus.config.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { join, resolve } = require('node:path');
22

33
const clsx = require('clsx');
4-
const { createApiPageMD } = require('docusaurus-plugin-openapi-docs/lib/markdown');
4+
const { createApiPageMD, createInfoPageMD } = require('docusaurus-plugin-openapi-docs/lib/markdown');
55

66
const { config } = require('./apify-docs-theme');
77
const { collectSlugs } = require('./tools/utils/collectSlugs');
@@ -196,6 +196,38 @@ module.exports = {
196196
md = md.replace('-->', '-->');
197197
}
198198

199+
// Add LLMButtons import and component
200+
if (!md.includes('import LLMButtons')) {
201+
// Find the first import statement and add LLMButtons import after it
202+
const firstImportMatch = md.match(/^import\s+.*?from\s+["'][^"']*["'];?\s*$/m);
203+
if (firstImportMatch) {
204+
const importEnd = md.indexOf(firstImportMatch[0]) + firstImportMatch[0].length;
205+
const llmButtonsImport = '\nimport LLMButtons from "@site/src/components/LLMButtons";';
206+
md = md.slice(0, importEnd) + llmButtonsImport + md.slice(importEnd);
207+
}
208+
}
209+
210+
// Find the first Heading h1 and add LLMButtons after it
211+
// eslint-disable-next-line max-len
212+
const headingRegex = /(<Heading[^>]*as=\{"h1"\}[^>]*className=\{"openapi__heading"\}[^>]*children=\{[^}]*\}[^>]*>\s*<\/Heading>)/;
213+
md = md.replace(headingRegex, '$1\n\n<LLMButtons />\n');
214+
215+
return md;
216+
},
217+
createInfoPageMD: (pageData) => {
218+
let md = createInfoPageMD(pageData);
219+
220+
// Add LLMButtons import and component
221+
if (!md.includes('import LLMButtons')) {
222+
// eslint-disable-next-line max-len
223+
md = md.replace('import Heading from "@theme/Heading";', 'import Heading from "@theme/Heading";\nimport LLMButtons from "@site/src/components/LLMButtons";');
224+
}
225+
226+
// Find the first Heading h1 and add LLMButtons after it
227+
// eslint-disable-next-line max-len
228+
const headingRegex = /(<Heading[^>]*as=\{"h1"\}[^>]*className=\{"openapi__heading"\}[^>]*children=\{[^}]*\}[^>]*>\s*<\/Heading>)/;
229+
md = md.replace(headingRegex, '$1\n\n<LLMButtons />\n');
230+
199231
return md;
200232
},
201233
},

src/theme/DocItem/Content/index.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,42 @@ function useSyntheticTitle() {
2222
export default function DocItemContent({ children }) {
2323
const syntheticTitle = useSyntheticTitle();
2424
const location = useLocation();
25-
const shouldShowLLMButtons = !location.pathname.startsWith('/legal');
25+
26+
// Define the allowed API v2 paths that should show LLMButtons (tag/info pages)
27+
// The logic is handled here, and also in docusaurus.config.js (see docusaurus-plugin-openapi-docs)
28+
const allowedApiV2Paths = [
29+
'/api/v2/getting-started',
30+
'/api/v2/actors',
31+
'/api/v2/actors-actor-versions',
32+
'/api/v2/actors-actor-builds',
33+
'/api/v2/actors-actor-runs',
34+
'/api/v2/actors-webhook-collection',
35+
'/api/v2/actor-builds',
36+
'/api/v2/actor-runs',
37+
'/api/v2/actor-tasks',
38+
'/api/v2/storage-datasets',
39+
'/api/v2/storage-key-value-stores',
40+
'/api/v2/storage-request-queues',
41+
'/api/v2/storage-request-queues-requests',
42+
'/api/v2/storage-request-queues-requests-locks',
43+
'/api/v2/webhooks-webhooks',
44+
'/api/v2/webhooks-webhook-dispatches',
45+
'/api/v2/schedules',
46+
'/api/v2/store',
47+
'/api/v2/logs',
48+
'/api/v2/users',
49+
'/platform',
50+
];
51+
52+
const shouldShowLLMButtons = allowedApiV2Paths.some((path) => location.pathname.startsWith(path));
2653

2754
return (
2855
<div className={clsx(ThemeClassNames.docs.docMarkdown, 'markdown')}>
2956
<header>
30-
<Heading as="h1">{syntheticTitle}</Heading>
31-
{shouldShowLLMButtons && <LLMButtons />}
32-
<MDXContent>{children}</MDXContent>
33-
</header>
57+
<Heading as="h1">{syntheticTitle}</Heading>
58+
{shouldShowLLMButtons && <LLMButtons />}
59+
<MDXContent>{children}</MDXContent>
60+
</header>
3461
</div>
3562
);
3663
}

0 commit comments

Comments
 (0)