Repository navigation
Expand file tree
/
Copy pathdocusaurus.config.ts
More file actions
468 lines (442 loc) · 13.3 KB
/
Copy pathdocusaurus.config.ts
File metadata and controls
468 lines (442 loc) · 13.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
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion
import fs from "fs";
import path from "path";
import type { Options, ThemeConfig } from "@docusaurus/preset-classic";
import type { Config } from "@docusaurus/types";
import autoprefixer from "autoprefixer";
import { themes } from "prism-react-renderer";
import katex from "rehype-katex";
import math from "remark-math";
import tailwind from "tailwindcss";
export default {
title: "OpenBB Docs",
tagline: "OpenBB Docs",
url: "https://docs.openbb.co", // Your website URL
baseUrl: "/",
projectName: "OpenBB",
organizationName: "OpenBB-finance",
trailingSlash: false,
onBrokenLinks: "warn",
onBrokenAnchors: "warn",
"markdown": {
"hooks": {
onBrokenMarkdownLinks: "warn",
}
},
favicon: "img/favicon.ico",
// GitHub pages deployment config.
// If you aren't using GitHub pages, you don't need these.
// Even if you don't use internalization, you can use this field to set useful
// metadata like html lang. For example, if your site is Chinese, you may want
// to replace "en" with "zh-Hans".
i18n: {
defaultLocale: "en",
locales: ["en"],
},
plugins: [
[
"@docusaurus/plugin-client-redirects",
{
redirects: [
{
from: "/pro/",
to: "/workspace/developers/data-integration",
},
{
from: "/pro/enterprise",
to: "/workspace/getting-started/enterprise",
},
{
from: "/pro/openbb-copilot",
to: "/workspace/analysts/ai-features/copilot-basics",
},
{
from: "/pro/platform-installer",
to: "/workspace/getting-started/platform-installer",
},
{
from: "/workspace/data-connector",
to: "/workspace/developers/data-integration",
},
{
from: "/workspace/developers/agent-skills",
to: "/agents/app-builder-resources",
},
{
from: "/agents/building-an-app",
to: "/agents/app-builder-resources",
},
{
from: "/agents/app-building-skill",
to: "/agents/app-builder-resources",
},
{
from: "/excel/enterprise",
to: "https://openbb.co/pricing",
},
{
from: "/bot",
to: "https://openbb.co/blog/we-are-handing-over-the-openbb-bot-to-focus-on-our-mission",
},
// Add redirects for old excel paths
{
from: "/excel",
to: "/workspace/analysts/excel-addin/excel-overview",
},
// Add redirects for old getting-started paths
{
from: "/getting-started/enterprise",
to: "/workspace/getting-started/enterprise",
},
{
from: "/getting-started/excel-installation",
to: "/workspace/analysts/excel-addin/excel-installation",
},
{
from: "/getting-started/faqs",
to: "/workspace/getting-started/faqs",
},
// Redirects for old ODP paths
{
from: "/platform",
to: "/odp/python",
},
{
from: "/desktop",
to: "/odp/desktop",
},
{
from: "/python",
to: "/odp/python",
},
{
from: "/cli",
to: "/odp/cli",
},
],
createRedirects: (existingPath) => {
// Redirect old paths to new /odp/* structure
if (existingPath.startsWith("/odp/desktop/")) {
return existingPath.replace("/odp/desktop/", "/desktop/");
}
if (existingPath.startsWith("/odp/python/")) {
return [
existingPath.replace("/odp/python/", "/python/"),
existingPath.replace("/odp/python/", "/platform/"),
];
}
if (existingPath.startsWith("/odp/cli/")) {
return existingPath.replace("/odp/cli/", "/cli/");
}
if (existingPath.startsWith("/pro/")) {
const newPath = existingPath.replace("/pro/", "/workspace/developers/");
if (newPath.includes("data-connector")) {
return newPath.replace("/data-connector/", "/data-integration/");
}
return newPath;
}
if (existingPath.includes("data-connector")) {
return existingPath.replace(
"/data-connector/",
"/data-integration/",
);
}
return undefined;
},
},
],
async function twPlugin(context, options) {
return {
name: "docusaurus-tailwindcss",
configurePostCss(postcssOptions) {
// Appends TailwindCSS and AutoPrefixer.
postcssOptions.plugins.push(tailwind);
postcssOptions.plugins.push(autoprefixer);
return postcssOptions;
},
};
},
async function sidebarExportPlugin(context) {
return {
name: "sidebar-export-plugin",
async contentLoaded({ content, actions }) {
// This runs after docs plugin processes content
},
async allContentLoaded({ allContent, actions }) {
const { setGlobalData, createData } = actions;
const docsContent = allContent["docusaurus-plugin-content-docs"]?.default;
const loadedVersion = docsContent?.loadedVersions?.[0];
if (loadedVersion?.sidebars?.tutorialSidebar) {
// Get the docs metadata to resolve labels
const docsMetadata = loadedVersion.docs;
// Recursively resolve labels for sidebar items
const resolveLabels = (items: any[]): any[] => {
return items.map(item => {
if (item.type === "doc") {
const doc = docsMetadata.find((d: any) => d.id === item.id);
return {
...item,
label: item.label || doc?.title || doc?.id?.split("/").pop(),
href: doc?.permalink,
};
}
if (item.type === "category") {
let categoryHref = null;
if (item.link?.type === "doc" && item.link?.id) {
const linkDoc = docsMetadata.find((d: any) => d.id === item.link.id);
categoryHref = linkDoc?.permalink;
}
return {
...item,
href: categoryHref,
items: item.items ? resolveLabels(item.items) : [],
};
}
return item;
});
};
const resolvedSidebar = resolveLabels(loadedVersion.sidebars.tutorialSidebar);
setGlobalData({ sidebar: resolvedSidebar });
}
},
};
},
async function pluginLlmsTxt(context) {
return {
name: "llms-txt-plugin",
loadContent: async () => {
const { siteDir } = context;
const contentDir = path.join(siteDir, "content");
// ODP has sub-sections that each get their own llms.txt
const sectionContent: Record<string, string[]> = {
agents: [],
workspace: [],
"odp/desktop": [],
"odp/python": [],
"odp/cli": [],
snowflake: [],
};
// recursive function to get all mdx files
const getMdxFiles = async (dir: string) => {
const entries = await fs.promises.readdir(dir, {
withFileTypes: true,
});
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
await getMdxFiles(fullPath);
} else if (
entry.name.endsWith(".mdx") ||
entry.name.endsWith(".md")
) {
try {
const content = await fs.promises.readFile(fullPath, "utf8");
// Determine which section this file belongs to
const relativePath = path.relative(contentDir, fullPath);
const pathParts = relativePath.split(path.sep);
// Check for ODP sub-sections first (odp/desktop, odp/python, odp/cli)
if (pathParts[0] === "odp" && pathParts.length > 1) {
const subSection = `odp/${pathParts[1]}`;
if (subSection in sectionContent) {
sectionContent[subSection].push(content);
}
} else if (pathParts[0] in sectionContent) {
sectionContent[pathParts[0]].push(content);
}
} catch (err) {
console.error(`Error processing file ${fullPath}:`, err);
}
}
}
};
await getMdxFiles(contentDir);
// Log content sizes for each section
for (const [section, content] of Object.entries(sectionContent)) {
const totalSize = content.reduce(
(acc, curr) => acc + curr.length,
0,
);
console.log(
`Section ${section} has ${content.length} files with total size of ${(totalSize / 1024 / 1024).toFixed(2)}MB`,
);
}
return { sectionContent };
},
postBuild: async ({ content, routes, outDir }) => {
const { sectionContent } = content as {
sectionContent: Record<string, string[]>;
};
const { siteDir } = context;
const staticDir = path.join(siteDir, "static");
// Find docs plugin route config
const docsPluginRouteConfig = routes.filter(
(route) => route.plugin.name === "docusaurus-plugin-content-docs",
)[0];
const allDocsRouteConfig = docsPluginRouteConfig.routes?.filter(
(route) => route.path === "/",
)[0];
if (!allDocsRouteConfig?.props?.version) {
return;
}
const currentVersionDocsRoutes = (
allDocsRouteConfig.props.version as Record<string, unknown>
).docs as Record<string, Record<string, unknown>>;
// Group routes by section
// ODP has sub-sections that each get their own llms.txt
const sectionRoutes: Record<string, string[]> = {
agents: [],
workspace: [],
"odp/desktop": [],
"odp/python": [],
"odp/cli": [],
snowflake: [],
};
for (const [docPath, record] of Object.entries(
currentVersionDocsRoutes,
)) {
const pathParts = docPath.split("/");
// Check for ODP sub-sections first (odp/desktop, odp/python, odp/cli)
if (pathParts[0] === "odp" && pathParts.length > 1) {
const subSection = `odp/${pathParts[1]}`;
if (subSection in sectionRoutes) {
const fullUrl = `${context.siteConfig.url}/${docPath}`;
sectionRoutes[subSection].push(
`- [${record.title}](${fullUrl}): ${record.description}`,
);
}
} else if (pathParts[0] in sectionRoutes) {
const fullUrl = `${context.siteConfig.url}/${docPath}`;
sectionRoutes[pathParts[0]].push(
`- [${record.title}](${fullUrl}): ${record.description}`,
);
}
}
// Process each section
for (const [section, routes] of Object.entries(sectionRoutes)) {
try {
// Create directory in static folder
const sectionDir = path.join(staticDir, section);
await fs.promises.mkdir(sectionDir, { recursive: true });
// Write section-specific llms.txt
const llmsTxt = `# ${context.siteConfig.title} - ${section}\n\n## Docs\n\n${routes.join("\n")}`;
await fs.promises.writeFile(
path.join(sectionDir, "llms.txt"),
llmsTxt,
);
// Also write to build output directory for direct access
const buildSectionDir = path.join(outDir, section);
await fs.promises.mkdir(buildSectionDir, { recursive: true });
await fs.promises.writeFile(
path.join(buildSectionDir, "llms.txt"),
llmsTxt,
);
// Write section-specific llms-full.txt
const sectionFullContent =
sectionContent[section].join("\n\n---\n\n");
await fs.promises.writeFile(
path.join(sectionDir, "llms-full.txt"),
sectionFullContent,
);
// Also write to build output directory for direct access
await fs.promises.writeFile(
path.join(buildSectionDir, "llms-full.txt"),
sectionFullContent,
);
} catch (err) {
console.error(`Error processing section ${section}:`, err);
}
}
},
};
},
],
presets: [
[
"classic",
{
docs: {
sidebarPath: "./sidebars.js",
editUrl: "https://github.com/OpenBB-finance/openbb-docs/edit/main/",
showLastUpdateTime: true,
showLastUpdateAuthor: true,
routeBasePath: "/",
path: "content",
remarkPlugins: [math],
rehypePlugins: [katex],
},
theme: {
customCss: "./src/css/custom.css",
},
} satisfies Options,
],
],
headTags: [
{
tagName: "meta",
attributes: {
"http-equiv": "Content-Security-Policy",
content:
"object-src 'self'; img-src * blob: data:; connect-src *; script-src 'self' 'unsafe-eval' 'unsafe-inline'; frame-ancestors 'self' 'https://pro.openbb.co' 'https://openbb.co' 'https://my.openbb.co'",
},
},
{
tagName: "meta",
attributes: {
"http-equiv": "Cache-Control",
content: "max-age=3600, must-revalidate",
},
},
{
tagName: "meta",
attributes: {
"http-equiv": "X-Content-Type-Options",
content: "nosniff",
},
},
],
themeConfig: {
image: "img/banner.png",
docs: {
sidebar: {
autoCollapseCategories: true,
},
},
prism: {
theme: themes.vsLight,
darkTheme: themes.vsDark,
additionalLanguages: ["json"],
},
// csp: {
// "default-src": ["'self'"],
// "script-src": ["self"],
// "style-src": ["'self'"],
// "img-src": ["*", "data:", "blob:"],
// "connect-src": ["*"],
// "frame-ancestors": [
// "'self'",
// "https://pro.openbb.co",
// "https://openbb.co",
// "https://my.openbb.co",
// ],
// },
// TODO - Jose can you make this so we get lighter color on main view - like bot docs
colorMode: {
defaultMode: "dark",
disableSwitch: false,
respectPrefersColorScheme: false,
},
algolia: {
appId: "7D1HQ0IXAS",
apiKey: "a2e289977b4b663ed9cf3d4635a438fd", // pragma: allowlist secret
indexName: "openbbterminal",
contextualSearch: false,
},
} satisfies ThemeConfig,
stylesheets: [
{
href: "/katex/katex.min.css",
type: "text/css",
},
],
} satisfies Config;