-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathdocusaurus.config.js
More file actions
538 lines (517 loc) · 21.3 KB
/
docusaurus.config.js
File metadata and controls
538 lines (517 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
const { join, resolve } = require('node:path');
const { parse } = require('node:url');
const clsx = require('clsx');
const { createApiPageMD } = require('docusaurus-plugin-openapi-docs/lib/markdown');
const { config } = require('./apify-docs-theme');
const { collectSlugs } = require('./tools/utils/collectSlugs');
const { externalLinkProcessor, isInternal } = require('./tools/utils/externalLink');
const { removeLlmButtons } = require('./tools/utils/removeLlmButtons');
/**
* Helper to extract text from a node recursively.
*/
function getNodeText(node) {
if (node.type === 'text' || node.type === 'code' || node.type === 'inlineCode') return node.value || '';
if (node.children) return node.children.map(getNodeText).join('');
return '';
}
/** @type {Partial<import('@docusaurus/types').DocusaurusConfig>} */
module.exports = {
title: 'Apify Documentation',
tagline: 'Apify Documentation',
url: config.absoluteUrl,
noIndex: config.noIndex,
baseUrl: '/',
trailingSlash: false,
organizationName: 'apify',
projectName: 'apify-docs',
scripts: [
'/js/custom.js',
...config.scripts ?? [],
],
future: {
experimental_faster: {
// swcJsLoader: true,
swcJsMinimizer: true,
swcHtmlMinimizer: true,
lightningCssMinimizer: true,
rspackBundler: true,
mdxCrossCompilerCache: true,
},
},
headTags: [
{
tagName: 'link',
attributes: {
rel: 'icon',
href: '/img/favicon.ico',
type: 'image/x-icon',
size: '48x48',
},
},
{
tagName: 'link',
attributes: {
rel: 'icon',
href: '/img/favicon.svg',
type: 'image/svg+xml',
sizes: 'any',
},
},
// Intercom messenger
process.env.INTERCOM_APP_ID && {
tagName: 'script',
innerHTML: `window.intercomSettings={api_base:"https://api-iam.intercom.io",app_id:"${process.env.INTERCOM_APP_ID}"};`,
attributes: {},
},
// Intercom messenger
process.env.INTERCOM_APP_ID && {
tagName: 'script',
innerHTML: `(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/${process.env.INTERCOM_APP_ID}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()`,
attributes: {},
},
].filter(Boolean),
onBrokenLinks:
/** @type {import('@docusaurus/types').ReportingSeverity} */ ('throw'),
onBrokenAnchors:
/** @type {import('@docusaurus/types').ReportingSeverity} */ ('warn'),
themes: [
[
require.resolve('./apify-docs-theme'),
/** @type {import('./apify-docs-theme/types').ThemeOptions} */
({
subNavbar: {
title: 'Academy',
pathRegex: '/academy',
to: '/academy',
items: [
{
label: 'Courses',
to: `/academy`,
activeBaseRegex: `${[
'academy$',
...collectSlugs(join(__dirname, 'sources', 'academy', 'webscraping')),
...collectSlugs(join(__dirname, 'sources', 'academy', 'platform')),
].join('$|')}$`,
},
{
label: 'Tutorials',
to: `/academy/tutorials`,
activeBaseRegex: `${collectSlugs(join(__dirname, 'sources', 'academy', 'tutorials')).join('$|')}$`,
},
],
},
}),
],
'docusaurus-theme-openapi-docs',
'@docusaurus/theme-mermaid',
],
presets: /** @type {import('@docusaurus/types').PresetConfig[]} */ ([
[
'classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
id: 'platform',
// Docusaurus shows the author and date of last commit to entire repo, which doesn't make sense,
// so let's just disable showing author and last modification
showLastUpdateAuthor: false,
showLastUpdateTime: false,
editUrl: 'https://github.com/apify/apify-docs/edit/master/',
path: './sources/platform',
routeBasePath: 'platform',
sidebarPath: require.resolve('./sources/platform/sidebars.js'),
rehypePlugins: [externalLinkProcessor],
},
sitemap: {
filename: 'sitemap_base.xml',
},
}),
],
]),
plugins: [
'docusaurus-plugin-image-zoom',
[
'@docusaurus/plugin-content-docs',
{
id: 'academy',
path: './sources/academy',
routeBasePath: 'academy',
rehypePlugins: [externalLinkProcessor],
// Docusaurus shows the author and date of last commit to entire repo, which doesn't make sense,
// so let's just disable showing author and last modification
showLastUpdateAuthor: false,
showLastUpdateTime: false,
editUrl: 'https://github.com/apify/apify-docs/edit/master/',
sidebarPath: require.resolve('./sources/academy/sidebars.js'),
},
],
[
'@docusaurus/plugin-content-docs',
{
id: 'legal',
path: './sources/legal',
routeBasePath: 'legal',
rehypePlugins: [externalLinkProcessor],
// Docusaurus shows the author and date of last commit to entire repo, which doesn't make sense,
// so let's just disable showing author and last modification
showLastUpdateAuthor: false,
showLastUpdateTime: false,
breadcrumbs: false,
sidebarPath: require.resolve('./sources/legal/sidebars.js'),
},
],
[
'@docusaurus/plugin-content-docs',
{
id: 'openapi',
path: './sources/api',
routeBasePath: 'api/v2',
rehypePlugins: [externalLinkProcessor],
showLastUpdateAuthor: false,
showLastUpdateTime: false,
breadcrumbs: false,
sidebarPath: require.resolve('./sources/api/sidebars.js'),
docItemComponent: '@theme/ApiItem', // Derived from docusaurus-theme-openapi
},
],
[
'docusaurus-plugin-openapi-docs',
{
id: 'openapi', // plugin id
docsPluginId: 'openapi', // configured for preset-classic
config: {
/** @type {import('docusaurus-plugin-openapi-docs').Options} */
v2: {
downloadUrl: '/api/openapi.yaml',
specPath: 'apify-api.yaml',
outputDir: './sources/api',
markdownGenerators: {
createApiPageMD: (pageData) => {
let md = createApiPageMD(pageData);
// HTML comments are wrongly escaped, we need to undo that
if (md.includes('<!--')) {
md = md.replace('<!--', '<!--');
md = md.replace('-->', '-->');
}
return md;
},
},
sidebarOptions: {
groupPathsBy: 'tagGroup',
categoryLinkSource: 'tag',
sidebarCollapsed: false,
sidebarCollapsible: false,
sidebarGenerators: {
createDocItem: (item, context) => {
const legacyUrls = item.api?.['x-legacy-doc-urls'] ?? [];
const altids = legacyUrls.map((url) => {
const { hash } = new URL(url);
return hash;
});
const sidebarLabel = item.frontMatter.sidebar_label;
const { title } = item;
const id = item.type === 'schema' ? `schemas/${item.id}` : item.id;
const className = item.type === 'api'
? clsx({
'menu__list-item--deprecated': item.api.deprecated,
'api-method': !!item.api.method,
}, item.api.method)
: clsx({
'menu__list-item--deprecated': item.schema.deprecated,
}, 'schema');
// const endpoint = item.api.servers[0].url + item.api.path;
const endpoint = item.api.path.replace('/v2', '');
const { method } = item.api;
return {
type: 'doc',
id: context.basePath === '' ? `${id}` : `${context.basePath}/${id}`,
label: sidebarLabel ?? title ?? id,
customProps: { altids, endpoint, method },
className,
};
},
},
},
},
},
},
],
[
resolve(__dirname, 'src/plugins/docusaurus-plugin-segment'),
{
writeKey: process.env.SEGMENT_TOKEN,
allowedInDev: false,
},
],
() => ({
name: 'webpack-loader-fix',
configureWebpack() {
return {
resolve: {
fallback: {
path: require.resolve('path-browserify'),
},
},
module: {
rules: [
{
test: /\/examples\//i,
type: 'asset/source',
},
],
},
};
},
}),
[
'@signalwire/docusaurus-plugin-llms-txt',
/** @type {import('@signalwire/docusaurus-plugin-llms-txt').PluginOptions} */
({
siteDescription: 'The entire content of Apify documentation is available in a single Markdown file at https://docs.apify.com/llms-full.txt',
content: {
includeVersionedDocs: false,
enableLlmsFullTxt: true,
includeBlog: true,
includeGeneratedIndex: false,
includePages: true,
relativePaths: false,
remarkStringify: {
handlers: {
link: (node) => {
if (node.title?.startsWith('Direct link to')) return '';
const parsedUrl = parse(node.url);
const isUrlInternal = isInternal(parsedUrl, config.absoluteUrl);
const url = isUrlInternal ? `${config.absoluteUrl}${parsedUrl.pathname}.md` : node.url;
if (isUrlInternal && !parsedUrl.pathname) return '';
if (node.title) return `[${node.title}](${url})`;
const linkText = getNodeText(node);
if (linkText) return `[${linkText}](${url})`;
return url;
},
code: (node) => {
const apiMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
const splitValueLines = node.value.trim().split('\n');
splitValueLines.forEach((item, i) => {
if (apiMethods.some((method) => item.trim() === method)) {
// try to parse as URL, if successful, prefix with absolute URL
try {
const parsedUrl = parse(splitValueLines[i + 1]);
if (isInternal(parsedUrl, config.absoluteUrl) && parsedUrl.pathname) {
if (splitValueLines[i + 1]) splitValueLines[i + 1] = `https://api.apify.com${parsedUrl.pathname}`;
}
} catch {
// do nothing, leave the line as is
}
}
});
if (apiMethods.some((method) => node.value.trim().startsWith(method))) {
node.lang = node.lang?.toLowerCase();
}
return `\n\`\`\`${node.lang || ''}\n${splitValueLines.join('\n')}\n\`\`\`\n`;
},
},
},
excludeRoutes: [
'/',
],
routeRules: [
{
route: '/api/**',
categoryName: 'Apify API',
},
{
route: '/academy/**',
categoryName: 'Apify academy',
},
{
route: '/legal/**',
categoryName: 'Legal documents',
},
{
route: '/platform/**',
categoryName: 'Platform documentation',
},
],
// Add custom remark processing to remove LLM button text
remarkPlugins: [removeLlmButtons],
},
}),
],
// TODO this should be somehow computed from all the external sources
// [
// '@docusaurus/plugin-client-redirects',
// {
// createRedirects(existingPath) {
// if (!existingPath.endsWith('/')) {
// return `${existingPath}/`;
// }
//
// return undefined; // Return a falsy value: no redirect created
// },
// },
// ],
...config.plugins,
],
markdown: {
mermaid: true,
hooks: {
onBrokenMarkdownLinks:
/** @type {import('@docusaurus/types').ReportingSeverity} */ ('throw'),
},
parseFrontMatter: async (params) => {
const result = await params.defaultParseFrontMatter(params);
if (result.frontMatter.api || result.content.startsWith('<span class="openapi-clients-box">')) {
result.frontMatter.pagination_next = null;
result.frontMatter.pagination_prev = null;
}
if (result.frontMatter.id === 'apify-api') {
result.frontMatter.slug = '/';
}
const isPartial = params.filePath.split('/').pop()[0] === '_';
if (!isPartial) {
const ogImageURL = new URL('https://apify.com/og-image/docs-article');
ogImageURL.searchParams.set('title', result.frontMatter.title);
result.frontMatter.image ??= ogImageURL.toString();
// Remove import statements and JSX/MDX tags from content
const contentText = result.content
.replace(/import\s+[^;]+;?/g, '') // Remove import statements
.replace(/<[^>]+>/g, '') // Remove all tags (JSX/MDX)
.replace(/\n+/g, ' ') // Replace newlines with space
.replace(/\s+/g, ' ') // Collapse whitespace
.trim();
const sentenceMatch = contentText.match(/^(.*?[.!?])\s/);
result.frontMatter.description ??= sentenceMatch ? sentenceMatch[1].trim() : contentText;
}
return result;
},
},
themeConfig: {
...config.themeConfig,
prism: {
...config.themeConfig.prism,
additionalLanguages: [
...config.themeConfig.prism.additionalLanguages,
'http', 'bash', 'ruby', 'java', 'scala', 'go', 'csharp', 'powershell', 'dart', 'objectivec', 'ocaml', 'r',
],
},
zoom: {
selector: '.markdown img:not(a img)',
},
languageTabs: [
{
highlight: 'bash',
label: 'CLI',
language: 'curl',
logoClass: 'curl',
},
{
highlight: 'javascript',
label: 'JavaScript',
language: 'javascript',
logoClass: 'javascript',
},
{
highlight: 'python',
label: 'Python',
language: 'python',
logoClass: 'python',
},
{
highlight: 'php',
label: 'PHP',
language: 'php',
logoClass: 'php',
},
{
highlight: 'java',
label: 'Java',
language: 'java',
logoClass: 'java',
variant: 'unirest',
},
{
highlight: 'c',
label: 'C',
language: 'c',
logoClass: 'c',
},
{
highlight: 'csharp',
label: 'C#',
language: 'csharp',
logoClass: 'csharp',
},
{
highlight: 'go',
label: 'Go',
language: 'go',
logoClass: 'go',
},
{
highlight: 'rust',
label: 'Rust',
language: 'rust',
logoClass: 'rust',
},
{
highlight: 'javascript',
label: 'Node.js',
language: 'nodejs',
logoClass: 'nodejs',
},
{
highlight: 'ruby',
label: 'Ruby',
language: 'ruby',
logoClass: 'ruby',
},
{
highlight: 'powershell',
label: 'PowerShell',
language: 'powershell',
logoClass: 'powershell',
},
{
highlight: 'dart',
label: 'Dart',
language: 'dart',
logoClass: 'dart',
},
{
highlight: 'objectivec',
label: 'Objective-C',
language: 'objective-c',
logoClass: 'objective-c',
},
{
highlight: 'ocaml',
label: 'OCaml',
language: 'ocaml',
logoClass: 'ocaml',
},
{
highlight: 'r',
label: 'R',
language: 'r',
logoClass: 'r',
},
{
highlight: 'swift',
label: 'Swift',
language: 'swift',
logoClass: 'swift',
},
{
highlight: 'kotlin',
label: 'Kotlin',
language: 'kotlin',
logoClass: 'kotlin',
},
],
},
staticDirectories: ['apify-docs-theme/static', 'static'],
customFields: {
...config.customFields ?? [],
},
clientModules: ['./clientModule.js'],
};