docstra 0.1.0 → 1.0.1

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.
@@ -0,0 +1,51 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface DocstraConfig {
4
+ siteName?: string;
5
+ editOnGithub?: boolean;
6
+ formSyncFormID?: string;
7
+ githubRepo?: string;
8
+ navbar?: {
9
+ logo?: {
10
+ link: string;
11
+ src: string;
12
+ alt: string;
13
+ className?: string;
14
+ };
15
+ links?: {
16
+ name: string;
17
+ href: string;
18
+ }[];
19
+ };
20
+ sidebar?: {
21
+ links?: DocsLinkGroup[];
22
+ };
23
+ }
24
+ interface DocsLinkItem {
25
+ name: string;
26
+ href: string;
27
+ icon?: string;
28
+ }
29
+ interface DocsLinkGroup {
30
+ section: string;
31
+ items: DocsLinkItem[];
32
+ }
33
+ type Slug = string | string[] | undefined;
34
+ interface FileContent {
35
+ metadata: Record<string, any>;
36
+ mdxContent: string;
37
+ rawMdxContent: string;
38
+ mdxFilePath: string;
39
+ }
40
+
41
+ declare function getFilePath(slug: Slug): string;
42
+ declare function getFileContents(slug: Slug): FileContent;
43
+
44
+ declare function defineDocstraConfig(config: DocstraConfig): DocstraConfig;
45
+
46
+ declare function DocstraMDXCompiler({ mdxContent, components }: {
47
+ mdxContent: string;
48
+ components?: Record<string, any>;
49
+ }): react_jsx_runtime.JSX.Element;
50
+
51
+ export { DocstraMDXCompiler, defineDocstraConfig, getFileContents, getFilePath };
@@ -0,0 +1,51 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface DocstraConfig {
4
+ siteName?: string;
5
+ editOnGithub?: boolean;
6
+ formSyncFormID?: string;
7
+ githubRepo?: string;
8
+ navbar?: {
9
+ logo?: {
10
+ link: string;
11
+ src: string;
12
+ alt: string;
13
+ className?: string;
14
+ };
15
+ links?: {
16
+ name: string;
17
+ href: string;
18
+ }[];
19
+ };
20
+ sidebar?: {
21
+ links?: DocsLinkGroup[];
22
+ };
23
+ }
24
+ interface DocsLinkItem {
25
+ name: string;
26
+ href: string;
27
+ icon?: string;
28
+ }
29
+ interface DocsLinkGroup {
30
+ section: string;
31
+ items: DocsLinkItem[];
32
+ }
33
+ type Slug = string | string[] | undefined;
34
+ interface FileContent {
35
+ metadata: Record<string, any>;
36
+ mdxContent: string;
37
+ rawMdxContent: string;
38
+ mdxFilePath: string;
39
+ }
40
+
41
+ declare function getFilePath(slug: Slug): string;
42
+ declare function getFileContents(slug: Slug): FileContent;
43
+
44
+ declare function defineDocstraConfig(config: DocstraConfig): DocstraConfig;
45
+
46
+ declare function DocstraMDXCompiler({ mdxContent, components }: {
47
+ mdxContent: string;
48
+ components?: Record<string, any>;
49
+ }): react_jsx_runtime.JSX.Element;
50
+
51
+ export { DocstraMDXCompiler, defineDocstraConfig, getFileContents, getFilePath };
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/server/index.ts
31
+ var server_exports = {};
32
+ __export(server_exports, {
33
+ DocstraMDXCompiler: () => DocstraMDXCompiler,
34
+ defineDocstraConfig: () => defineDocstraConfig,
35
+ getFileContents: () => getFileContents,
36
+ getFilePath: () => getFilePath
37
+ });
38
+ module.exports = __toCommonJS(server_exports);
39
+
40
+ // src/server/get-mdx-content.ts
41
+ var import_fs = __toESM(require("fs"));
42
+ var import_path = __toESM(require("path"));
43
+ var import_gray_matter = __toESM(require("gray-matter"));
44
+ var CONTENT_DIR = import_path.default.join(process.cwd(), "app", "docs", "content");
45
+ function getFilePath(slug) {
46
+ const slugArray = Array.isArray(slug) && slug.length > 0 ? slug : ["index"];
47
+ const possiblePaths = [
48
+ import_path.default.join(CONTENT_DIR, ...slugArray) + ".mdx",
49
+ import_path.default.join(CONTENT_DIR, ...slugArray) + ".md",
50
+ import_path.default.join(CONTENT_DIR, ...slugArray, "index.mdx"),
51
+ import_path.default.join(CONTENT_DIR, ...slugArray, "index.md")
52
+ ];
53
+ for (const filePath of possiblePaths) {
54
+ if (import_fs.default.existsSync(filePath)) {
55
+ return filePath;
56
+ }
57
+ }
58
+ throw new Error(`\u274C MDX file not found for slug: ${slugArray.join("/")} `);
59
+ }
60
+ function getFileContents(slug) {
61
+ const filePath = getFilePath(slug);
62
+ const rawFile = import_fs.default.readFileSync(filePath, "utf-8");
63
+ const { data, content } = (0, import_gray_matter.default)(rawFile);
64
+ return {
65
+ metadata: data,
66
+ mdxContent: content,
67
+ rawMdxContent: rawFile,
68
+ mdxFilePath: filePath
69
+ };
70
+ }
71
+
72
+ // src/server/docstra-config.ts
73
+ function defineDocstraConfig(config) {
74
+ return config;
75
+ }
76
+
77
+ // src/server/mdx-compiler.tsx
78
+ var import_rsc = require("next-mdx-remote/rsc");
79
+
80
+ // src/client/mdx-components.tsx
81
+ var import_link = __toESM(require("next/link"));
82
+
83
+ // src/client/create-heading.tsx
84
+ var import_lucide_react = require("lucide-react");
85
+
86
+ // src/utils/generate-id-from-text.ts
87
+ function generateIdFromText(text) {
88
+ return text.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
89
+ }
90
+
91
+ // src/client/create-heading.tsx
92
+ var import_jsx_runtime = require("react/jsx-runtime");
93
+ function CreateHeading({ children, level }) {
94
+ const Heading = `h${level}`;
95
+ const text = typeof children === "string" ? children : "";
96
+ const id = generateIdFromText(text);
97
+ let fontSize;
98
+ let iconSize;
99
+ switch (level) {
100
+ case 1:
101
+ fontSize = "text-3xl";
102
+ break;
103
+ case 2:
104
+ fontSize = "text-2xl";
105
+ iconSize = "size-5";
106
+ break;
107
+ case 3:
108
+ fontSize = "text-xl";
109
+ iconSize = "size-4.5";
110
+ break;
111
+ case 4:
112
+ fontSize = "text-lg";
113
+ iconSize = "size-4.5";
114
+ break;
115
+ case 5:
116
+ fontSize = "text-base";
117
+ iconSize = "size-3.5";
118
+ break;
119
+ default:
120
+ fontSize = "text-base";
121
+ iconSize = "size-3.5";
122
+ }
123
+ return level === 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { className: "text-3xl font-bold text-gray-900 mb-4", children }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
124
+ Heading,
125
+ {
126
+ id,
127
+ className: `group mt-10 gap-2 mb-4 flex items-center scroll-mt-26 ${fontSize} font-semibold text-gray-900`,
128
+ children: [
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: `#${id}`, children }),
130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.LinkIcon, { className: `${iconSize} text-gray-400 opacity-0 group-hover:opacity-100 transition` })
131
+ ]
132
+ }
133
+ );
134
+ }
135
+
136
+ // src/client/mdx-components.tsx
137
+ var import_jsx_runtime2 = require("react/jsx-runtime");
138
+ var defaultMdxComponents = {
139
+ h1: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 1 }),
140
+ h2: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 2 }),
141
+ h3: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 3 }),
142
+ h4: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 4 }),
143
+ h5: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 5 }),
144
+ p: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "my-5", children: props.children }),
145
+ hr: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("hr", { className: "my-10 border-gray-200" }),
146
+ a: (props) => props.href.startsWith("/") ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_link.default, { className: "underline underline-offset-4", href: props.href, children: props.children }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { className: "underline underline-offset-4", href: props.href, children: props.children }),
147
+ ul: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "list-['-'] pl-4 space-y-2", children: props.children }),
148
+ li: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { className: "mb-2 pl-3 text-gray-700", children: props.children }),
149
+ ol: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ol", { className: "list-decimal pl-4 space-y-2", children: props.children }),
150
+ blockquote: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("blockquote", { className: "border-l-4 border-gray-200 pl-4 my-8 text-gray-700", children: props.children })
151
+ };
152
+
153
+ // src/server/mdx-compiler.tsx
154
+ var import_jsx_runtime3 = require("react/jsx-runtime");
155
+ function DocstraMDXCompiler({
156
+ mdxContent,
157
+ components = {}
158
+ }) {
159
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
160
+ import_rsc.MDXRemote,
161
+ {
162
+ source: mdxContent,
163
+ components: {
164
+ ...defaultMdxComponents,
165
+ ...components
166
+ }
167
+ }
168
+ ) });
169
+ }
170
+ // Annotate the CommonJS export names for ESM import in node:
171
+ 0 && (module.exports = {
172
+ DocstraMDXCompiler,
173
+ defineDocstraConfig,
174
+ getFileContents,
175
+ getFilePath
176
+ });
@@ -0,0 +1,136 @@
1
+ // src/server/get-mdx-content.ts
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import matter from "gray-matter";
5
+ var CONTENT_DIR = path.join(process.cwd(), "app", "docs", "content");
6
+ function getFilePath(slug) {
7
+ const slugArray = Array.isArray(slug) && slug.length > 0 ? slug : ["index"];
8
+ const possiblePaths = [
9
+ path.join(CONTENT_DIR, ...slugArray) + ".mdx",
10
+ path.join(CONTENT_DIR, ...slugArray) + ".md",
11
+ path.join(CONTENT_DIR, ...slugArray, "index.mdx"),
12
+ path.join(CONTENT_DIR, ...slugArray, "index.md")
13
+ ];
14
+ for (const filePath of possiblePaths) {
15
+ if (fs.existsSync(filePath)) {
16
+ return filePath;
17
+ }
18
+ }
19
+ throw new Error(`\u274C MDX file not found for slug: ${slugArray.join("/")} `);
20
+ }
21
+ function getFileContents(slug) {
22
+ const filePath = getFilePath(slug);
23
+ const rawFile = fs.readFileSync(filePath, "utf-8");
24
+ const { data, content } = matter(rawFile);
25
+ return {
26
+ metadata: data,
27
+ mdxContent: content,
28
+ rawMdxContent: rawFile,
29
+ mdxFilePath: filePath
30
+ };
31
+ }
32
+
33
+ // src/server/docstra-config.ts
34
+ function defineDocstraConfig(config) {
35
+ return config;
36
+ }
37
+
38
+ // src/server/mdx-compiler.tsx
39
+ import { MDXRemote } from "next-mdx-remote/rsc";
40
+
41
+ // src/client/mdx-components.tsx
42
+ import Link from "next/link";
43
+
44
+ // src/client/create-heading.tsx
45
+ import { LinkIcon } from "lucide-react";
46
+
47
+ // src/utils/generate-id-from-text.ts
48
+ function generateIdFromText(text) {
49
+ return text.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
50
+ }
51
+
52
+ // src/client/create-heading.tsx
53
+ import { jsx, jsxs } from "react/jsx-runtime";
54
+ function CreateHeading({ children, level }) {
55
+ const Heading = `h${level}`;
56
+ const text = typeof children === "string" ? children : "";
57
+ const id = generateIdFromText(text);
58
+ let fontSize;
59
+ let iconSize;
60
+ switch (level) {
61
+ case 1:
62
+ fontSize = "text-3xl";
63
+ break;
64
+ case 2:
65
+ fontSize = "text-2xl";
66
+ iconSize = "size-5";
67
+ break;
68
+ case 3:
69
+ fontSize = "text-xl";
70
+ iconSize = "size-4.5";
71
+ break;
72
+ case 4:
73
+ fontSize = "text-lg";
74
+ iconSize = "size-4.5";
75
+ break;
76
+ case 5:
77
+ fontSize = "text-base";
78
+ iconSize = "size-3.5";
79
+ break;
80
+ default:
81
+ fontSize = "text-base";
82
+ iconSize = "size-3.5";
83
+ }
84
+ return level === 1 ? /* @__PURE__ */ jsx("h1", { className: "text-3xl font-bold text-gray-900 mb-4", children }) : /* @__PURE__ */ jsxs(
85
+ Heading,
86
+ {
87
+ id,
88
+ className: `group mt-10 gap-2 mb-4 flex items-center scroll-mt-26 ${fontSize} font-semibold text-gray-900`,
89
+ children: [
90
+ /* @__PURE__ */ jsx("a", { href: `#${id}`, children }),
91
+ /* @__PURE__ */ jsx(LinkIcon, { className: `${iconSize} text-gray-400 opacity-0 group-hover:opacity-100 transition` })
92
+ ]
93
+ }
94
+ );
95
+ }
96
+
97
+ // src/client/mdx-components.tsx
98
+ import { jsx as jsx2 } from "react/jsx-runtime";
99
+ var defaultMdxComponents = {
100
+ h1: (props) => /* @__PURE__ */ jsx2(CreateHeading, { ...props, level: 1 }),
101
+ h2: (props) => /* @__PURE__ */ jsx2(CreateHeading, { ...props, level: 2 }),
102
+ h3: (props) => /* @__PURE__ */ jsx2(CreateHeading, { ...props, level: 3 }),
103
+ h4: (props) => /* @__PURE__ */ jsx2(CreateHeading, { ...props, level: 4 }),
104
+ h5: (props) => /* @__PURE__ */ jsx2(CreateHeading, { ...props, level: 5 }),
105
+ p: (props) => /* @__PURE__ */ jsx2("p", { className: "my-5", children: props.children }),
106
+ hr: () => /* @__PURE__ */ jsx2("hr", { className: "my-10 border-gray-200" }),
107
+ a: (props) => props.href.startsWith("/") ? /* @__PURE__ */ jsx2(Link, { className: "underline underline-offset-4", href: props.href, children: props.children }) : /* @__PURE__ */ jsx2("a", { className: "underline underline-offset-4", href: props.href, children: props.children }),
108
+ ul: (props) => /* @__PURE__ */ jsx2("ul", { className: "list-['-'] pl-4 space-y-2", children: props.children }),
109
+ li: (props) => /* @__PURE__ */ jsx2("li", { className: "mb-2 pl-3 text-gray-700", children: props.children }),
110
+ ol: (props) => /* @__PURE__ */ jsx2("ol", { className: "list-decimal pl-4 space-y-2", children: props.children }),
111
+ blockquote: (props) => /* @__PURE__ */ jsx2("blockquote", { className: "border-l-4 border-gray-200 pl-4 my-8 text-gray-700", children: props.children })
112
+ };
113
+
114
+ // src/server/mdx-compiler.tsx
115
+ import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
116
+ function DocstraMDXCompiler({
117
+ mdxContent,
118
+ components = {}
119
+ }) {
120
+ return /* @__PURE__ */ jsx3(Fragment, { children: /* @__PURE__ */ jsx3(
121
+ MDXRemote,
122
+ {
123
+ source: mdxContent,
124
+ components: {
125
+ ...defaultMdxComponents,
126
+ ...components
127
+ }
128
+ }
129
+ ) });
130
+ }
131
+ export {
132
+ DocstraMDXCompiler,
133
+ defineDocstraConfig,
134
+ getFileContents,
135
+ getFilePath
136
+ };