doccupine 0.0.143 → 0.0.145
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +130 -22
- package/dist/generator/api-reference-generator.d.ts +22 -0
- package/dist/generator/api-reference-generator.js +96 -0
- package/dist/generator/app-scaffolder.d.ts +18 -0
- package/dist/generator/app-scaffolder.js +49 -0
- package/dist/generator/generated-route-manager.d.ts +18 -0
- package/dist/generator/generated-route-manager.js +114 -0
- package/dist/generator/page-catalog.d.ts +21 -0
- package/dist/generator/page-catalog.js +75 -0
- package/dist/generator/page-renderer.d.ts +31 -0
- package/dist/generator/page-renderer.js +248 -0
- package/dist/generator/project-config-repository.d.ts +33 -0
- package/dist/generator/project-config-repository.js +191 -0
- package/dist/generator/public-asset-manager.d.ts +20 -0
- package/dist/generator/public-asset-manager.js +225 -0
- package/dist/generator/section-resolver.d.ts +13 -0
- package/dist/generator/section-resolver.js +150 -0
- package/dist/generator/secure-source-fs.d.ts +31 -0
- package/dist/generator/secure-source-fs.js +470 -0
- package/dist/generator/site-artifacts.d.ts +23 -0
- package/dist/generator/site-artifacts.js +156 -0
- package/dist/generator/watch-coordinator.d.ts +58 -0
- package/dist/generator/watch-coordinator.js +456 -0
- package/dist/lib/config-manager.d.ts +1 -0
- package/dist/lib/config-manager.js +194 -12
- package/dist/lib/generated-artifacts.d.ts +11 -2
- package/dist/lib/generated-artifacts.js +52 -7
- package/dist/lib/layout.d.ts +1 -17
- package/dist/lib/layout.js +5 -4
- package/dist/lib/openapi.d.ts +4 -0
- package/dist/lib/openapi.js +36 -4
- package/dist/lib/project-config.d.ts +3 -0
- package/dist/lib/project-config.js +110 -0
- package/dist/lib/types.d.ts +14 -1
- package/dist/mdx-to-nextjs-generator.d.ts +50 -34
- package/dist/mdx-to-nextjs-generator.js +760 -1740
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +2 -1
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +2 -1
- package/dist/templates/components/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +2 -3
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +11 -2
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +26 -1
- package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.js +5 -0
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +2 -1
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +2 -2
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +3 -3
- package/dist/templates/mdx/space.mdx.d.ts +1 -1
- package/dist/templates/mdx/space.mdx.js +1 -5
- package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.js +8 -3
- package/dist/templates/next.config.js +2 -2
- package/dist/templates/package.js +3 -3
- package/dist/templates/proxy.js +1 -1
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +2 -12
- package/package.json +3 -3
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { resolveOutputPath, resolveWithin } from "../lib/output-safety.js";
|
|
5
|
+
import { writeFileAtomic } from "../lib/utils.js";
|
|
6
|
+
import { llmsPageTemplate } from "../templates/llms/llmsPage.js";
|
|
7
|
+
import { siteDocsSlug } from "../templates/llms/skillMd.js";
|
|
8
|
+
const PUBLIC_AGGREGATE_PATHS = new Set([
|
|
9
|
+
"llms.txt",
|
|
10
|
+
"llms-full.txt",
|
|
11
|
+
"skill.md",
|
|
12
|
+
".well-known/mcp.json",
|
|
13
|
+
]);
|
|
14
|
+
function normalizePublicArtifactPath(relativePath) {
|
|
15
|
+
return relativePath.replace(/\\/g, "/").toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
function isPublicAggregate(relativePath) {
|
|
18
|
+
return PUBLIC_AGGREGATE_PATHS.has(normalizePublicArtifactPath(relativePath));
|
|
19
|
+
}
|
|
20
|
+
function isManagedPublicArtifact(relativePath) {
|
|
21
|
+
const normalized = normalizePublicArtifactPath(relativePath);
|
|
22
|
+
return PUBLIC_AGGREGATE_PATHS.has(normalized) || normalized.endsWith(".md");
|
|
23
|
+
}
|
|
24
|
+
function publicDestinationRelativePath(relativePath) {
|
|
25
|
+
return isPublicAggregate(relativePath)
|
|
26
|
+
? normalizePublicArtifactPath(relativePath)
|
|
27
|
+
: relativePath.replace(/\\/g, "/");
|
|
28
|
+
}
|
|
29
|
+
export class PublicAssetManager {
|
|
30
|
+
rootDir;
|
|
31
|
+
outputDir;
|
|
32
|
+
artifacts;
|
|
33
|
+
sourceFs;
|
|
34
|
+
constructor(rootDir, outputDir, artifacts, sourceFs) {
|
|
35
|
+
this.rootDir = rootDir;
|
|
36
|
+
this.outputDir = outputDir;
|
|
37
|
+
this.artifacts = artifacts;
|
|
38
|
+
this.sourceFs = sourceFs;
|
|
39
|
+
}
|
|
40
|
+
outputPath(...segments) {
|
|
41
|
+
return resolveOutputPath(this.outputDir, ...segments);
|
|
42
|
+
}
|
|
43
|
+
publicOutputFilePath(relativePath) {
|
|
44
|
+
const parent = path.dirname(relativePath);
|
|
45
|
+
const outputParent = parent === "."
|
|
46
|
+
? this.outputPath("public")
|
|
47
|
+
: this.outputPath("public", parent);
|
|
48
|
+
return resolveWithin(outputParent, path.basename(relativePath));
|
|
49
|
+
}
|
|
50
|
+
async copyRegularPublicFile(sourcePath, destPath) {
|
|
51
|
+
const { data } = await this.sourceFs.readPublicSourceFile(sourcePath);
|
|
52
|
+
await writeFileAtomic(destPath, data);
|
|
53
|
+
}
|
|
54
|
+
async copyPublicFiles() {
|
|
55
|
+
const publicDir = path.join(this.rootDir, "public");
|
|
56
|
+
const previousFiles = this.artifacts.publicFiles();
|
|
57
|
+
console.log(chalk.blue(`🔍 Checking for public directory...`));
|
|
58
|
+
const files = await this.sourceFs.scanPublicFiles();
|
|
59
|
+
if (files === null) {
|
|
60
|
+
console.log(chalk.gray(` ✗ public directory not found, skipping`));
|
|
61
|
+
for (const stale of previousFiles) {
|
|
62
|
+
await fs.remove(this.publicOutputFilePath(stale));
|
|
63
|
+
}
|
|
64
|
+
this.artifacts.replacePublicFiles([]);
|
|
65
|
+
await this.artifacts.save();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const nextFiles = new Set();
|
|
69
|
+
const nextByFoldedPath = new Map();
|
|
70
|
+
for (const relativePath of files) {
|
|
71
|
+
const destRelativePath = publicDestinationRelativePath(relativePath);
|
|
72
|
+
nextFiles.add(destRelativePath);
|
|
73
|
+
nextByFoldedPath.set(destRelativePath.toLowerCase(), destRelativePath);
|
|
74
|
+
}
|
|
75
|
+
const removedBeforeCopy = new Set();
|
|
76
|
+
for (const stale of previousFiles) {
|
|
77
|
+
const replacement = nextByFoldedPath.get(stale.toLowerCase());
|
|
78
|
+
if (replacement &&
|
|
79
|
+
replacement !== stale &&
|
|
80
|
+
(await fs.pathExists(this.publicOutputFilePath(replacement)))) {
|
|
81
|
+
await fs.remove(this.publicOutputFilePath(stale));
|
|
82
|
+
removedBeforeCopy.add(stale);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const relativePath of files) {
|
|
86
|
+
const destRelativePath = publicDestinationRelativePath(relativePath);
|
|
87
|
+
await this.copyRegularPublicFile(path.join(publicDir, relativePath), this.publicOutputFilePath(destRelativePath));
|
|
88
|
+
}
|
|
89
|
+
for (const stale of previousFiles) {
|
|
90
|
+
if (!nextFiles.has(stale) && !removedBeforeCopy.has(stale)) {
|
|
91
|
+
await fs.remove(this.publicOutputFilePath(stale));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
this.artifacts.replacePublicFiles(nextFiles);
|
|
95
|
+
await this.artifacts.save();
|
|
96
|
+
console.log(chalk.green(` ✓ Copied public directory to Next.js app`));
|
|
97
|
+
}
|
|
98
|
+
async handlePublicFileChange(filePath, restoreGeneratedArtifacts) {
|
|
99
|
+
const publicDir = path.join(this.rootDir, "public");
|
|
100
|
+
const relativePath = path.relative(publicDir, filePath);
|
|
101
|
+
const destRelativePath = publicDestinationRelativePath(relativePath);
|
|
102
|
+
const destPath = this.publicOutputFilePath(destRelativePath);
|
|
103
|
+
try {
|
|
104
|
+
await this.copyRegularPublicFile(filePath, destPath);
|
|
105
|
+
const publicFiles = this.artifacts.publicFiles();
|
|
106
|
+
publicFiles.add(destRelativePath);
|
|
107
|
+
this.artifacts.replacePublicFiles(publicFiles);
|
|
108
|
+
await this.artifacts.save();
|
|
109
|
+
console.log(chalk.green(`📋 Updated public/${relativePath} in Next.js app`));
|
|
110
|
+
if (isManagedPublicArtifact(relativePath)) {
|
|
111
|
+
await restoreGeneratedArtifacts();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error(chalk.red(`❌ Error copying public/${relativePath}:`), error);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async handlePublicFileDelete(filePath, copyCurrentSource, restoreGeneratedArtifacts) {
|
|
120
|
+
const publicDir = path.join(this.rootDir, "public");
|
|
121
|
+
const relativePath = path.relative(publicDir, filePath);
|
|
122
|
+
const destRelativePath = publicDestinationRelativePath(relativePath);
|
|
123
|
+
const destPath = this.outputPath("public", destRelativePath);
|
|
124
|
+
try {
|
|
125
|
+
// A rapid replace can queue an unlink after the replacement already
|
|
126
|
+
// exists. Copy the current source instead of deleting its fresh mirror.
|
|
127
|
+
if (await fs.pathExists(filePath)) {
|
|
128
|
+
await copyCurrentSource();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (await fs.pathExists(destPath)) {
|
|
132
|
+
await fs.remove(destPath);
|
|
133
|
+
console.log(chalk.yellow(`🗑️ Removed public/${relativePath} from Next.js app`));
|
|
134
|
+
}
|
|
135
|
+
const publicFiles = this.artifacts.publicFiles();
|
|
136
|
+
publicFiles.delete(destRelativePath);
|
|
137
|
+
this.artifacts.replacePublicFiles(publicFiles);
|
|
138
|
+
await this.artifacts.save();
|
|
139
|
+
if (isManagedPublicArtifact(relativePath)) {
|
|
140
|
+
await restoreGeneratedArtifacts();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error(chalk.red(`❌ Error removing public/${relativePath}:`), error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async findSourcePublicAsset(relativePath) {
|
|
148
|
+
return this.sourceFs.findPublicAsset(relativePath);
|
|
149
|
+
}
|
|
150
|
+
async writePublicAggregate(relativePath, content) {
|
|
151
|
+
const sourcePath = await this.findSourcePublicAsset(relativePath);
|
|
152
|
+
const targetPath = this.publicOutputFilePath(relativePath);
|
|
153
|
+
if (sourcePath) {
|
|
154
|
+
console.warn(chalk.yellow(`⚠️ Skipping generated public/${relativePath}; a project public asset owns that path`));
|
|
155
|
+
await this.copyRegularPublicFile(sourcePath, targetPath);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
await fs.ensureDir(path.dirname(targetPath));
|
|
159
|
+
await writeFileAtomic(targetPath, content);
|
|
160
|
+
}
|
|
161
|
+
async syncMcpManifest(baseUrl, siteName) {
|
|
162
|
+
const relativePath = ".well-known/mcp.json";
|
|
163
|
+
const outputPath = this.publicOutputFilePath(relativePath);
|
|
164
|
+
const sourcePath = await this.findSourcePublicAsset(relativePath);
|
|
165
|
+
if (sourcePath) {
|
|
166
|
+
console.warn(chalk.yellow(`⚠️ Skipping generated public/${relativePath}; a project public asset owns that path`));
|
|
167
|
+
await this.copyRegularPublicFile(sourcePath, outputPath);
|
|
168
|
+
}
|
|
169
|
+
else if (baseUrl) {
|
|
170
|
+
const content = JSON.stringify({
|
|
171
|
+
mcpServers: {
|
|
172
|
+
[siteDocsSlug(siteName)]: {
|
|
173
|
+
url: `${baseUrl}/api/mcp`,
|
|
174
|
+
transport: "streamable-http",
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
}, null, 2) + "\n";
|
|
178
|
+
await fs.ensureDir(path.dirname(outputPath));
|
|
179
|
+
await writeFileAtomic(outputPath, content);
|
|
180
|
+
}
|
|
181
|
+
else if (await fs.pathExists(outputPath)) {
|
|
182
|
+
await fs.remove(outputPath);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async syncLlmsPageFiles(pages, baseUrl) {
|
|
186
|
+
const publicDir = this.outputPath("public");
|
|
187
|
+
const nextRelativePaths = new Set();
|
|
188
|
+
await Promise.all(pages.map(async (page) => {
|
|
189
|
+
const relativePath = page.slug === "" ? "index.md" : `${page.slug}.md`;
|
|
190
|
+
if (isPublicAggregate(relativePath))
|
|
191
|
+
return;
|
|
192
|
+
const sourcePath = await this.findSourcePublicAsset(relativePath);
|
|
193
|
+
if (sourcePath) {
|
|
194
|
+
console.warn(chalk.yellow(`⚠️ Skipping generated public/${relativePath}; a project public asset owns that path`));
|
|
195
|
+
const targetPath = this.publicOutputFilePath(relativePath);
|
|
196
|
+
await this.copyRegularPublicFile(sourcePath, targetPath);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const targetPath = this.publicOutputFilePath(relativePath);
|
|
200
|
+
await fs.ensureDir(path.dirname(targetPath));
|
|
201
|
+
await writeFileAtomic(targetPath, llmsPageTemplate(page, baseUrl));
|
|
202
|
+
nextRelativePaths.add(relativePath);
|
|
203
|
+
}));
|
|
204
|
+
const previousRelativePaths = this.artifacts.llmsPageFiles();
|
|
205
|
+
for (const stale of previousRelativePaths) {
|
|
206
|
+
if (!nextRelativePaths.has(stale)) {
|
|
207
|
+
try {
|
|
208
|
+
if (isPublicAggregate(stale))
|
|
209
|
+
continue;
|
|
210
|
+
if (await this.findSourcePublicAsset(stale))
|
|
211
|
+
continue;
|
|
212
|
+
const stalePath = resolveOutputPath(publicDir, stale);
|
|
213
|
+
if (await fs.pathExists(stalePath)) {
|
|
214
|
+
await fs.remove(stalePath);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// ignore
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
this.artifacts.replaceLlmsPageFiles(nextRelativePaths);
|
|
223
|
+
await this.artifacts.save();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SectionConfig } from "../lib/types.js";
|
|
2
|
+
export interface SectionDocument {
|
|
3
|
+
filePath: string;
|
|
4
|
+
frontmatter: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
export interface SectionRoute {
|
|
7
|
+
sectionSlug: string;
|
|
8
|
+
pageSlug: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function validateSectionsConfig(parsed: unknown): SectionConfig[] | null;
|
|
11
|
+
export declare function discoverSections(documents: SectionDocument[]): SectionConfig[] | null;
|
|
12
|
+
export declare function addApiReferenceSection(sections: SectionConfig[] | null, hasApiReference: boolean, apiBaseSlug: string): SectionConfig[] | null;
|
|
13
|
+
export declare function determineSectionRoute(filePath: string, frontmatter: Record<string, any>, sections: SectionConfig[] | null): SectionRoute;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { generateSlug } from "../lib/utils.js";
|
|
2
|
+
import { slugifySegment } from "../lib/openapi.js";
|
|
3
|
+
export function validateSectionsConfig(parsed) {
|
|
4
|
+
if (!Array.isArray(parsed) || parsed.length === 0)
|
|
5
|
+
return null;
|
|
6
|
+
const seenLabels = new Set();
|
|
7
|
+
const seenSlugs = new Set();
|
|
8
|
+
return parsed.map((entry, index) => {
|
|
9
|
+
if (!entry || typeof entry !== "object") {
|
|
10
|
+
throw new Error(`sections.json entry ${index + 1} must be an object`);
|
|
11
|
+
}
|
|
12
|
+
const candidate = entry;
|
|
13
|
+
const label = typeof candidate.label === "string" ? candidate.label.trim() : "";
|
|
14
|
+
const slug = typeof candidate.slug === "string" ? candidate.slug.trim() : "";
|
|
15
|
+
if (!label) {
|
|
16
|
+
throw new Error(`sections.json entry ${index + 1} needs a non-empty label`);
|
|
17
|
+
}
|
|
18
|
+
if (slug !== "" &&
|
|
19
|
+
(slug !== slugifySegment(slug) ||
|
|
20
|
+
slug.includes("/") ||
|
|
21
|
+
slug === "." ||
|
|
22
|
+
slug === "..")) {
|
|
23
|
+
throw new Error(`Unsafe section slug "${slug}"; use a lowercase URL segment such as "${slugifySegment(slug)}"`);
|
|
24
|
+
}
|
|
25
|
+
if (seenLabels.has(label) || seenSlugs.has(slug)) {
|
|
26
|
+
throw new Error(`Duplicate section label or slug at entry ${index + 1}`);
|
|
27
|
+
}
|
|
28
|
+
seenLabels.add(label);
|
|
29
|
+
seenSlugs.add(slug);
|
|
30
|
+
let directory;
|
|
31
|
+
if (candidate.directory !== undefined) {
|
|
32
|
+
if (typeof candidate.directory !== "string") {
|
|
33
|
+
throw new Error(`sections.json directory at entry ${index + 1} must be a string`);
|
|
34
|
+
}
|
|
35
|
+
directory = candidate.directory
|
|
36
|
+
.replace(/\\/g, "/")
|
|
37
|
+
.replace(/^\/+|\/+$/g, "");
|
|
38
|
+
const parts = directory.split("/");
|
|
39
|
+
if (!directory ||
|
|
40
|
+
parts.some((part) => part === "." || part === ".." || part !== slugifySegment(part))) {
|
|
41
|
+
throw new Error(`Unsafe section directory "${candidate.directory}"`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { label, slug, ...(directory ? { directory } : {}) };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function discoverSections(documents) {
|
|
48
|
+
const sectionMap = new Map();
|
|
49
|
+
let hasUnsectionedPages = false;
|
|
50
|
+
let defaultSectionLabel = "Docs";
|
|
51
|
+
for (const { filePath, frontmatter } of documents) {
|
|
52
|
+
if (typeof frontmatter.section === "string" && frontmatter.section.trim()) {
|
|
53
|
+
const label = frontmatter.section.trim();
|
|
54
|
+
const order = typeof frontmatter.sectionOrder === "number"
|
|
55
|
+
? frontmatter.sectionOrder
|
|
56
|
+
: 0;
|
|
57
|
+
const existing = sectionMap.get(label);
|
|
58
|
+
if (!existing || order < existing.order) {
|
|
59
|
+
sectionMap.set(label, { label, order });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
hasUnsectionedPages = true;
|
|
64
|
+
}
|
|
65
|
+
if ((filePath === "index.mdx" || filePath === "./index.mdx") &&
|
|
66
|
+
typeof frontmatter.sectionLabel === "string" &&
|
|
67
|
+
frontmatter.sectionLabel.trim()) {
|
|
68
|
+
defaultSectionLabel = frontmatter.sectionLabel.trim();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (sectionMap.size === 0)
|
|
72
|
+
return null;
|
|
73
|
+
const sorted = [...sectionMap.values()].sort((a, b) => a.order - b.order);
|
|
74
|
+
const sections = [];
|
|
75
|
+
if (hasUnsectionedPages) {
|
|
76
|
+
sections.push({ label: defaultSectionLabel, slug: "" });
|
|
77
|
+
}
|
|
78
|
+
const usedSlugs = new Set(sections.map((section) => section.slug));
|
|
79
|
+
for (const section of sorted) {
|
|
80
|
+
const slug = slugifySegment(section.label);
|
|
81
|
+
if (usedSlugs.has(slug)) {
|
|
82
|
+
throw new Error(`Section labels resolve to the same slug "${slug}". Rename one section or define sections.json explicitly.`);
|
|
83
|
+
}
|
|
84
|
+
usedSlugs.add(slug);
|
|
85
|
+
sections.push({ label: section.label, slug });
|
|
86
|
+
}
|
|
87
|
+
return sections;
|
|
88
|
+
}
|
|
89
|
+
export function addApiReferenceSection(sections, hasApiReference, apiBaseSlug) {
|
|
90
|
+
if (!hasApiReference)
|
|
91
|
+
return sections;
|
|
92
|
+
const apiSection = {
|
|
93
|
+
label: "API Reference",
|
|
94
|
+
slug: apiBaseSlug,
|
|
95
|
+
};
|
|
96
|
+
if (!sections || sections.length === 0) {
|
|
97
|
+
return [{ label: "Documentation", slug: "" }, apiSection];
|
|
98
|
+
}
|
|
99
|
+
if (sections.some((section) => section.slug === apiBaseSlug))
|
|
100
|
+
return sections;
|
|
101
|
+
return [...sections, apiSection];
|
|
102
|
+
}
|
|
103
|
+
export function determineSectionRoute(filePath, frontmatter, sections) {
|
|
104
|
+
if (!sections || sections.length === 0) {
|
|
105
|
+
return { sectionSlug: "", pageSlug: generateSlug(filePath) };
|
|
106
|
+
}
|
|
107
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
108
|
+
const firstDir = normalizedPath.includes("/")
|
|
109
|
+
? normalizedPath.split("/")[0]
|
|
110
|
+
: "";
|
|
111
|
+
for (const section of sections) {
|
|
112
|
+
if (!section.directory)
|
|
113
|
+
continue;
|
|
114
|
+
const dirPrefix = section.directory + "/";
|
|
115
|
+
if (normalizedPath.startsWith(dirPrefix)) {
|
|
116
|
+
return {
|
|
117
|
+
sectionSlug: section.slug,
|
|
118
|
+
pageSlug: generateSlug(normalizedPath.slice(dirPrefix.length)),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (firstDir) {
|
|
123
|
+
const match = sections.find((section) => section.slug === firstDir);
|
|
124
|
+
if (match) {
|
|
125
|
+
const pathForSlug = normalizedPath.slice(firstDir.length + 1);
|
|
126
|
+
return {
|
|
127
|
+
sectionSlug: match.slug,
|
|
128
|
+
pageSlug: generateSlug(pathForSlug),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (frontmatter.section) {
|
|
133
|
+
const label = frontmatter.section;
|
|
134
|
+
const match = sections.find((section) => section.label === label);
|
|
135
|
+
if (match) {
|
|
136
|
+
let pathForSlug = filePath;
|
|
137
|
+
if (firstDir && firstDir === match.slug) {
|
|
138
|
+
pathForSlug = normalizedPath.slice(firstDir.length + 1);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
sectionSlug: match.slug,
|
|
142
|
+
pageSlug: generateSlug(pathForSlug),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
sectionSlug: "",
|
|
148
|
+
pageSlug: generateSlug(filePath),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
export declare class SecureSourceFs {
|
|
3
|
+
private documentationRoot;
|
|
4
|
+
private projectRoot;
|
|
5
|
+
constructor(documentationRoot: string, projectRoot: string);
|
|
6
|
+
private sourcePathError;
|
|
7
|
+
private realSourceRoot;
|
|
8
|
+
private readSafeSourceFile;
|
|
9
|
+
readMdxSourceFile(filePath: string): Promise<{
|
|
10
|
+
content: string;
|
|
11
|
+
stat: fs.Stats;
|
|
12
|
+
}>;
|
|
13
|
+
readProjectSourceFile(sourcePath: string, label: string): Promise<{
|
|
14
|
+
data: Buffer;
|
|
15
|
+
stat: fs.Stats;
|
|
16
|
+
}>;
|
|
17
|
+
readPublicSourceFile(sourcePath: string): Promise<{
|
|
18
|
+
data: Buffer;
|
|
19
|
+
stat: fs.Stats;
|
|
20
|
+
}>;
|
|
21
|
+
private assertPinnedDocumentationRoot;
|
|
22
|
+
private pinDocumentationRoot;
|
|
23
|
+
private removeCreatedStarterFile;
|
|
24
|
+
private writeStarterFile;
|
|
25
|
+
writeStarterFilesIfEmpty(files: Iterable<readonly [string, string | Uint8Array]> | AsyncIterable<readonly [string, string | Uint8Array]>): Promise<void>;
|
|
26
|
+
pathState(filePath: string, hashContents?: boolean): Promise<string>;
|
|
27
|
+
treeState(root: string, includeFile: (relativePath: string) => boolean, hashContents?: boolean): Promise<string>;
|
|
28
|
+
scanPublicFiles(): Promise<string[] | null>;
|
|
29
|
+
getAllMdxFiles(): Promise<string[]>;
|
|
30
|
+
findPublicAsset(relativePath: string): Promise<string | null>;
|
|
31
|
+
}
|