Skip to content

Commit 3cd84ff

Browse files
Return logic
1 parent a881ad6 commit 3cd84ff

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
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
},

0 commit comments

Comments
 (0)