|
1 | 1 | const { join, resolve } = require('node:path'); |
2 | 2 |
|
3 | 3 | 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'); |
5 | 5 |
|
6 | 6 | const { config } = require('./apify-docs-theme'); |
7 | 7 | const { collectSlugs } = require('./tools/utils/collectSlugs'); |
@@ -196,6 +196,38 @@ module.exports = { |
196 | 196 | md = md.replace('-->', '-->'); |
197 | 197 | } |
198 | 198 |
|
| 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 | + |
199 | 231 | return md; |
200 | 232 | }, |
201 | 233 | }, |
|
0 commit comments