-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdocs.ts
More file actions
167 lines (145 loc) · 4.64 KB
/
docs.ts
File metadata and controls
167 lines (145 loc) · 4.64 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
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import { getAllNotebooks } from "./notebooks";
// Path to the docs content directory (relative to project root)
const DOCS_DIR = path.join(process.cwd(), "..", "docs");
export interface DocMeta {
slug: string;
title: string;
description?: string;
category: string;
format: "md" | "mdx";
}
export interface Doc extends DocMeta {
content: string;
}
function slugToTitle(slug: string): string {
return slug
.replace(/-/g, " ")
.replace(/\b\w/g, (c) => c.toUpperCase())
.replace(/Llm/g, "LLM")
.replace(/Ml/g, "ML")
.replace(/Api/g, "API");
}
function getCategory(filePath: string): string {
if (filePath.includes("reference/")) return "Reference";
if (filePath.includes("case_studies/")) return "Case Studies";
return "Guides";
}
export function getAllDocs(): DocMeta[] {
const docs: DocMeta[] = [];
function scanDir(dir: string, prefix: string = "") {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
// Skip data directory
if (entry.name === "data") continue;
scanDir(fullPath, path.join(prefix, entry.name));
} else if (entry.name.endsWith(".md") || entry.name.endsWith(".mdx")) {
const isMdx = entry.name.endsWith(".mdx");
const relativePath = path.join(prefix, entry.name);
const slug = relativePath.replace(/\.mdx?$/, "");
const content = fs.readFileSync(fullPath, "utf-8");
const { data } = matter(content);
docs.push({
slug,
title: data.title || slugToTitle(path.basename(slug)),
description: data.description,
category: getCategory(relativePath),
format: isMdx ? "mdx" : "md",
});
}
}
}
scanDir(DOCS_DIR);
return docs;
}
export function getDocBySlug(slug: string): Doc | null {
// Try .mdx first, then .md
const baseSlug = slug.replace(/\.mdx?$/, "");
for (const ext of [".mdx", ".md"] as const) {
const fullPath = path.join(DOCS_DIR, `${baseSlug}${ext}`);
if (fs.existsSync(fullPath)) {
const fileContent = fs.readFileSync(fullPath, "utf-8");
const { data, content } = matter(fileContent);
return {
slug: baseSlug,
title: data.title || slugToTitle(path.basename(baseSlug)),
description: data.description,
category: getCategory(baseSlug),
format: ext === ".mdx" ? "mdx" : "md",
content,
};
}
}
return null;
}
// Slugs that are rendered inline on the homepage, not as standalone pages
const HOMEPAGE_ONLY_SLUGS = new Set(["installation"]);
export function getDocSlugs(): string[] {
return getAllDocs()
.filter((doc) => !HOMEPAGE_ONLY_SLUGS.has(doc.slug))
.map((doc) => doc.slug);
}
// Navigation structure
export interface NavSection {
title: string;
href?: string;
items: { slug: string; title: string; href?: string }[];
}
export function getNavigation(): NavSection[] {
const docs = getAllDocs();
const notebooks = getAllNotebooks();
const guides = docs.filter((d) => d.category === "Guides");
const reference = docs.filter((d) => d.category === "Reference");
return [
{
title: "Overview",
items: [
{ slug: "installation", title: "Installation", href: "/" },
{ slug: "getting-started", title: "Getting Started" },
{ slug: "api-key", title: "API Key", href: "https://everyrow.io/api-key" },
{ slug: "mcp-server", title: "MCP Server" },
{ slug: "skills-vs-mcp", title: "Skills vs MCP" },
{ slug: "progress-monitoring", title: "Progress Monitoring" },
{ slug: "chaining-operations", title: "Chaining Operations" },
{ slug: "github", title: "GitHub", href: "https://github.com/futuresearch/everyrow-sdk" },
],
},
{
title: "API Reference",
href: "/api",
items: reference.map((d) => ({
slug: d.slug,
title: d.title.replace(/^reference\//, ""),
})),
},
{
title: "Guides",
href: "/guides",
items: guides
.filter((d) => ![
"getting-started",
"chaining-operations",
"installation",
"progress-monitoring",
"mcp-server",
"skills-vs-mcp",
"guides",
"notebooks",
"api",
].includes(d.slug))
.map((d) => ({ slug: d.slug, title: d.title })),
},
{
title: "Case Studies",
href: "/notebooks",
items: notebooks.map((n) => ({
slug: `notebooks/${n.slug}`,
title: n.title,
})),
},
];
}