react-docs-module 0.1.0
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 +279 -0
- package/ai-chat.tsx +222 -0
- package/chat-api.ts +90 -0
- package/cn.ts +15 -0
- package/config.ts +29 -0
- package/dist/ai-chat.d.ts +12 -0
- package/dist/ai-chat.js +72 -0
- package/dist/ai-chat.js.map +1 -0
- package/dist/chat-api.d.ts +16 -0
- package/dist/chat-api.js +62 -0
- package/dist/chat-api.js.map +1 -0
- package/dist/cn.d.ts +4 -0
- package/dist/cn.js +14 -0
- package/dist/cn.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -0
- package/dist/doc-pagination.d.ts +13 -0
- package/dist/doc-pagination.js +8 -0
- package/dist/doc-pagination.js.map +1 -0
- package/dist/docs-index.d.ts +7 -0
- package/dist/docs-index.js +11 -0
- package/dist/docs-index.js.map +1 -0
- package/dist/docs-page.d.ts +15 -0
- package/dist/docs-page.js +38 -0
- package/dist/docs-page.js.map +1 -0
- package/dist/docs-sidebar.d.ts +18 -0
- package/dist/docs-sidebar.d.ts.map +1 -0
- package/dist/docs-sidebar.js +27 -0
- package/dist/docs-sidebar.js.map +1 -0
- package/dist/documentation-layout.d.ts +15 -0
- package/dist/documentation-layout.js +20 -0
- package/dist/documentation-layout.js.map +1 -0
- package/dist/heading.d.ts +10 -0
- package/dist/heading.js +16 -0
- package/dist/heading.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/mdx/callouts.d.ts +8 -0
- package/dist/mdx/callouts.js +8 -0
- package/dist/mdx/callouts.js.map +1 -0
- package/dist/mdx/code-block.d.ts +8 -0
- package/dist/mdx/code-block.js +29 -0
- package/dist/mdx/code-block.js.map +1 -0
- package/dist/mdx/components.d.ts +13 -0
- package/dist/mdx/components.js +21 -0
- package/dist/mdx/components.js.map +1 -0
- package/dist/mdx.d.ts +20 -0
- package/dist/mdx.js +109 -0
- package/dist/mdx.js.map +1 -0
- package/dist/search-index.d.ts +10 -0
- package/dist/search-index.js +38 -0
- package/dist/search-index.js.map +1 -0
- package/dist/search.d.ts +6 -0
- package/dist/search.js +142 -0
- package/dist/search.js.map +1 -0
- package/dist/table-of-contents-provider.d.ts +4 -0
- package/dist/table-of-contents-provider.js +30 -0
- package/dist/table-of-contents-provider.js.map +1 -0
- package/dist/table-of-contents.d.ts +11 -0
- package/dist/table-of-contents.js +9 -0
- package/dist/table-of-contents.js.map +1 -0
- package/dist/theme-context.d.ts +20 -0
- package/dist/theme-context.js +28 -0
- package/dist/theme-context.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/ui/button.d.ts +12 -0
- package/dist/ui/button.js +34 -0
- package/dist/ui/button.js.map +1 -0
- package/dist/ui/dialog.d.ts +17 -0
- package/dist/ui/dialog.js +22 -0
- package/dist/ui/dialog.js.map +1 -0
- package/dist/ui/input.d.ts +4 -0
- package/dist/ui/input.js +9 -0
- package/dist/ui/input.js.map +1 -0
- package/dist/util.d.ts +59 -0
- package/dist/util.js +96 -0
- package/dist/util.js.map +1 -0
- package/doc-pagination.tsx +67 -0
- package/docs-index.tsx +17 -0
- package/docs-page.tsx +68 -0
- package/docs-sidebar.tsx +165 -0
- package/documentation-layout.tsx +99 -0
- package/heading.tsx +63 -0
- package/index.ts +28 -0
- package/mdx/callouts.tsx +29 -0
- package/mdx/code-block.tsx +89 -0
- package/mdx/components.tsx +55 -0
- package/mdx.ts +138 -0
- package/package.json +99 -0
- package/search-index.ts +52 -0
- package/search.tsx +273 -0
- package/table-of-contents-provider.tsx +43 -0
- package/table-of-contents.tsx +44 -0
- package/theme-context.tsx +57 -0
- package/ui/button.tsx +56 -0
- package/ui/dialog.tsx +108 -0
- package/ui/input.tsx +22 -0
- package/util.ts +169 -0
package/util.ts
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
import fs from "node:fs";
|
2
|
+
import path from "node:path";
|
3
|
+
import matter from "gray-matter";
|
4
|
+
import { ReactDocsConfig } from "./config";
|
5
|
+
|
6
|
+
interface DocPage {
|
7
|
+
slug: string;
|
8
|
+
title: string;
|
9
|
+
icon?: string;
|
10
|
+
isExternal?: boolean;
|
11
|
+
}
|
12
|
+
|
13
|
+
interface DocSection {
|
14
|
+
group: string;
|
15
|
+
pages: DocPage[];
|
16
|
+
}
|
17
|
+
|
18
|
+
export interface DocsJsonConfig {
|
19
|
+
theme: string;
|
20
|
+
name: string;
|
21
|
+
description?: string;
|
22
|
+
navigation: {
|
23
|
+
groups?: {
|
24
|
+
group: string;
|
25
|
+
pages: string[];
|
26
|
+
}[];
|
27
|
+
anchors?: {
|
28
|
+
name: string;
|
29
|
+
icon: string;
|
30
|
+
url: string;
|
31
|
+
}[];
|
32
|
+
pages?: string[];
|
33
|
+
};
|
34
|
+
colors: {
|
35
|
+
primary: string;
|
36
|
+
light?: string;
|
37
|
+
dark?: string;
|
38
|
+
};
|
39
|
+
logo?: {
|
40
|
+
dark?: string;
|
41
|
+
light?: string;
|
42
|
+
};
|
43
|
+
favicon?: string;
|
44
|
+
navbar?: {
|
45
|
+
cta?: {
|
46
|
+
type: string;
|
47
|
+
url: string;
|
48
|
+
};
|
49
|
+
};
|
50
|
+
footer?: {
|
51
|
+
socials?: Record<string, string>;
|
52
|
+
};
|
53
|
+
feedback?: {
|
54
|
+
thumbsRating?: boolean;
|
55
|
+
};
|
56
|
+
}
|
57
|
+
|
58
|
+
export function getDocsSidebar(config: ReactDocsConfig) {
|
59
|
+
const docsDirectory = path.join(process.cwd(), config.contentPath);
|
60
|
+
const docsJsonPath = path.join(process.cwd(), config.contentPath, "docs.json");
|
61
|
+
|
62
|
+
if (!fs.existsSync(docsJsonPath)) {
|
63
|
+
throw new Error(`docs.json configuration file not found at ${config.contentPath}/docs.json`);
|
64
|
+
}
|
65
|
+
|
66
|
+
const docsConfig: DocsJsonConfig = JSON.parse(fs.readFileSync(docsJsonPath, 'utf8'));
|
67
|
+
|
68
|
+
const navigation: DocSection[] = [];
|
69
|
+
|
70
|
+
// Add anchors as the first section if they exist
|
71
|
+
if (docsConfig.navigation.anchors && docsConfig.navigation.anchors.length > 0) {
|
72
|
+
navigation.push({
|
73
|
+
group: "Links",
|
74
|
+
pages: docsConfig.navigation.anchors.map(anchor => ({
|
75
|
+
slug: anchor.url,
|
76
|
+
title: anchor.name,
|
77
|
+
icon: anchor.icon,
|
78
|
+
isExternal: true
|
79
|
+
}))
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
// Handle groups navigation
|
84
|
+
if (docsConfig.navigation.groups) {
|
85
|
+
docsConfig.navigation.groups.forEach(section => {
|
86
|
+
const pages: DocPage[] = [];
|
87
|
+
|
88
|
+
section.pages.forEach(pagePath => {
|
89
|
+
const fullPath = path.join(docsDirectory, `${pagePath}.mdx`);
|
90
|
+
if (fs.existsSync(fullPath)) {
|
91
|
+
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
92
|
+
const { data: frontmatter } = matter(fileContents);
|
93
|
+
|
94
|
+
pages.push({
|
95
|
+
slug: pagePath,
|
96
|
+
title: frontmatter.title || pagePath.split('/').pop()?.replace(/-/g, ' ') || '',
|
97
|
+
});
|
98
|
+
}
|
99
|
+
});
|
100
|
+
|
101
|
+
if (pages.length > 0) {
|
102
|
+
navigation.push({
|
103
|
+
group: section.group,
|
104
|
+
pages,
|
105
|
+
});
|
106
|
+
}
|
107
|
+
});
|
108
|
+
}
|
109
|
+
|
110
|
+
// Handle direct pages navigation (if no groups)
|
111
|
+
if (docsConfig.navigation.pages && !docsConfig.navigation.groups) {
|
112
|
+
const pages: DocPage[] = [];
|
113
|
+
|
114
|
+
docsConfig.navigation.pages.forEach(pagePath => {
|
115
|
+
const fullPath = path.join(docsDirectory, `${pagePath}.mdx`);
|
116
|
+
if (fs.existsSync(fullPath)) {
|
117
|
+
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
118
|
+
const { data: frontmatter } = matter(fileContents);
|
119
|
+
|
120
|
+
pages.push({
|
121
|
+
slug: pagePath,
|
122
|
+
title: frontmatter.title || pagePath.split('/').pop()?.replace(/-/g, ' ') || '',
|
123
|
+
});
|
124
|
+
}
|
125
|
+
});
|
126
|
+
|
127
|
+
if (pages.length > 0) {
|
128
|
+
navigation.push({
|
129
|
+
group: "Documentation",
|
130
|
+
pages,
|
131
|
+
});
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
return { navigation, config: docsConfig };
|
136
|
+
}
|
137
|
+
|
138
|
+
export function getAllDocSlugs(config: ReactDocsConfig) {
|
139
|
+
const docsDirectory = path.join(process.cwd(), config.contentPath);
|
140
|
+
const fileNames = fs.readdirSync(docsDirectory);
|
141
|
+
|
142
|
+
return fileNames
|
143
|
+
.filter((fileName) => fileName.endsWith(".mdx"))
|
144
|
+
.map((fileName) => ({
|
145
|
+
slug: fileName.replace(/\.mdx$/, ""),
|
146
|
+
}));
|
147
|
+
}
|
148
|
+
|
149
|
+
// Helper function to recursively read all MDX files from a directory
|
150
|
+
function getAllDocs(dir: string): string[] {
|
151
|
+
const files = fs.readdirSync(dir);
|
152
|
+
|
153
|
+
return files.flatMap(file => {
|
154
|
+
const filePath = path.join(dir, file);
|
155
|
+
const stats = fs.statSync(filePath);
|
156
|
+
|
157
|
+
if (stats.isDirectory()) {
|
158
|
+
return getAllDocs(filePath);
|
159
|
+
}
|
160
|
+
|
161
|
+
if (file.endsWith('.mdx')) {
|
162
|
+
const fileContents = fs.readFileSync(filePath, 'utf8');
|
163
|
+
const { content } = matter(fileContents);
|
164
|
+
return content;
|
165
|
+
}
|
166
|
+
|
167
|
+
return [];
|
168
|
+
});
|
169
|
+
}
|