docstra 1.6.3 → 1.7.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 +120 -60
- package/dist/client/index.d.mts +12 -6
- package/dist/client/index.d.ts +12 -6
- package/dist/client/index.js +269 -285
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +266 -283
- package/dist/client/index.mjs.map +1 -1
- package/dist/server/docstra-loader.d.mts +5 -0
- package/dist/server/docstra-loader.d.ts +5 -0
- package/dist/server/docstra-loader.js +30894 -0
- package/dist/server/docstra-loader.js.map +1 -0
- package/dist/server/docstra-loader.mjs +30885 -0
- package/dist/server/docstra-loader.mjs.map +1 -0
- package/dist/server/index.d.mts +20 -5
- package/dist/server/index.d.ts +20 -5
- package/dist/server/index.js +110 -88
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +108 -86
- package/dist/server/index.mjs.map +1 -1
- package/dist/{types-BCr1htTq.d.mts → types-QzxGYJU4.d.mts} +22 -12
- package/dist/{types-BCr1htTq.d.ts → types-QzxGYJU4.d.ts} +22 -12
- package/package.json +2 -1
package/dist/server/index.d.mts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { D as DocstraConfig,
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
1
|
+
import { D as DocstraConfig, p as pageDataContent, g as getSitemapProps } from '../types-QzxGYJU4.mjs';
|
|
3
2
|
import { NextConfig } from 'next';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
declare function defineDocstraConfig<T extends DocstraConfig>(config: T): T;
|
|
6
6
|
|
|
7
|
-
declare function DocstraMDXCompiler({ content, components }: DocstraMdxCompilerProps): react_jsx_runtime.JSX.Element;
|
|
8
|
-
|
|
9
7
|
declare function withDocstra<T extends NextConfig>(nextConfig?: T): T;
|
|
10
8
|
|
|
11
9
|
declare function defaultMdxComponents(): {
|
|
@@ -26,4 +24,21 @@ declare function defaultMdxComponents(): {
|
|
|
26
24
|
|
|
27
25
|
declare function getPageData(slug: string[], docs: any[]): any;
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
declare function createSource(docs: any[]): {
|
|
28
|
+
getPage: (slug: string[] | undefined) => {
|
|
29
|
+
info: any;
|
|
30
|
+
body: any;
|
|
31
|
+
} | null;
|
|
32
|
+
generateStaticParams: () => {
|
|
33
|
+
slug: any;
|
|
34
|
+
}[];
|
|
35
|
+
files: pageDataContent[];
|
|
36
|
+
generateSitemap: ({ baseUrl, lastmod, changefreq, priority }: getSitemapProps) => {
|
|
37
|
+
url: string;
|
|
38
|
+
lastModified: string | undefined;
|
|
39
|
+
changeFrequency: any;
|
|
40
|
+
priority: number | undefined;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { createSource, defaultMdxComponents, defineDocstraConfig, getPageData, withDocstra };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { D as DocstraConfig,
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
1
|
+
import { D as DocstraConfig, p as pageDataContent, g as getSitemapProps } from '../types-QzxGYJU4.js';
|
|
3
2
|
import { NextConfig } from 'next';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
declare function defineDocstraConfig<T extends DocstraConfig>(config: T): T;
|
|
6
6
|
|
|
7
|
-
declare function DocstraMDXCompiler({ content, components }: DocstraMdxCompilerProps): react_jsx_runtime.JSX.Element;
|
|
8
|
-
|
|
9
7
|
declare function withDocstra<T extends NextConfig>(nextConfig?: T): T;
|
|
10
8
|
|
|
11
9
|
declare function defaultMdxComponents(): {
|
|
@@ -26,4 +24,21 @@ declare function defaultMdxComponents(): {
|
|
|
26
24
|
|
|
27
25
|
declare function getPageData(slug: string[], docs: any[]): any;
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
declare function createSource(docs: any[]): {
|
|
28
|
+
getPage: (slug: string[] | undefined) => {
|
|
29
|
+
info: any;
|
|
30
|
+
body: any;
|
|
31
|
+
} | null;
|
|
32
|
+
generateStaticParams: () => {
|
|
33
|
+
slug: any;
|
|
34
|
+
}[];
|
|
35
|
+
files: pageDataContent[];
|
|
36
|
+
generateSitemap: ({ baseUrl, lastmod, changefreq, priority }: getSitemapProps) => {
|
|
37
|
+
url: string;
|
|
38
|
+
lastModified: string | undefined;
|
|
39
|
+
changeFrequency: any;
|
|
40
|
+
priority: number | undefined;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { createSource, defaultMdxComponents, defineDocstraConfig, getPageData, withDocstra };
|
package/dist/server/index.js
CHANGED
|
@@ -1749,7 +1749,7 @@ var init_esm2 = __esm({
|
|
|
1749
1749
|
// src/server/index.ts
|
|
1750
1750
|
var server_exports = {};
|
|
1751
1751
|
__export(server_exports, {
|
|
1752
|
-
|
|
1752
|
+
createSource: () => createSource,
|
|
1753
1753
|
defaultMdxComponents: () => defaultMdxComponents,
|
|
1754
1754
|
defineDocstraConfig: () => defineDocstraConfig,
|
|
1755
1755
|
getPageData: () => getPageData,
|
|
@@ -1762,54 +1762,9 @@ function defineDocstraConfig(config) {
|
|
|
1762
1762
|
return config;
|
|
1763
1763
|
}
|
|
1764
1764
|
|
|
1765
|
-
// src/server/mdx-compiler.tsx
|
|
1766
|
-
var import_rsc = require("next-mdx-remote/rsc");
|
|
1767
|
-
|
|
1768
|
-
// src/plugins/rehype-code-meta.ts
|
|
1769
|
-
var import_unist_util_visit = require("unist-util-visit");
|
|
1770
|
-
function rehypeCodeMetaProps() {
|
|
1771
|
-
return (tree) => {
|
|
1772
|
-
(0, import_unist_util_visit.visit)(tree, "element", (node) => {
|
|
1773
|
-
if (node.tagName !== "pre") return;
|
|
1774
|
-
const code = node.children?.[0];
|
|
1775
|
-
if (!code || code.tagName !== "code") return;
|
|
1776
|
-
const className = code.properties?.className?.[0];
|
|
1777
|
-
const language = className?.replace("language-", "");
|
|
1778
|
-
const meta = code.data?.meta || "";
|
|
1779
|
-
const metaProps = {};
|
|
1780
|
-
meta.replace(
|
|
1781
|
-
/(\w+)=["']?([^"'\s]+)["']?/g,
|
|
1782
|
-
(_match, key, value) => {
|
|
1783
|
-
metaProps[key] = value;
|
|
1784
|
-
return "";
|
|
1785
|
-
}
|
|
1786
|
-
);
|
|
1787
|
-
node.properties = { ...node.properties || {}, language, ...metaProps };
|
|
1788
|
-
});
|
|
1789
|
-
};
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
// src/server/mdx-compiler.tsx
|
|
1793
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1794
|
-
function DocstraMDXCompiler({ content, components = {} }) {
|
|
1795
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1796
|
-
import_rsc.MDXRemote,
|
|
1797
|
-
{
|
|
1798
|
-
source: content,
|
|
1799
|
-
components,
|
|
1800
|
-
options: {
|
|
1801
|
-
mdxOptions: {
|
|
1802
|
-
rehypePlugins: [rehypeCodeMetaProps]
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
);
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
1765
|
// src/server/build.ts
|
|
1810
1766
|
var import_fs = __toESM(require("fs"));
|
|
1811
1767
|
var import_path = __toESM(require("path"));
|
|
1812
|
-
var import_gray_matter = __toESM(require("gray-matter"));
|
|
1813
1768
|
function runDocstraBuild(contentDir) {
|
|
1814
1769
|
const root = process.cwd();
|
|
1815
1770
|
const outDir = import_path.default.join(root, ".docstra");
|
|
@@ -1817,28 +1772,30 @@ function runDocstraBuild(contentDir) {
|
|
|
1817
1772
|
if (!import_fs.default.existsSync(contentDir)) return;
|
|
1818
1773
|
if (!import_fs.default.existsSync(outDir)) import_fs.default.mkdirSync(outDir, { recursive: true });
|
|
1819
1774
|
const files = getAllMdxFiles(contentDir);
|
|
1820
|
-
const
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
const
|
|
1775
|
+
const imports = [];
|
|
1776
|
+
const docEntries = [];
|
|
1777
|
+
files.forEach((file, index) => {
|
|
1778
|
+
const relPath = import_path.default.relative(outDir, file).replace(/\\/g, "/");
|
|
1779
|
+
const importName = `d${index}`;
|
|
1780
|
+
imports.push(`import * as ${importName} from "${relPath}?docstra";`);
|
|
1824
1781
|
const relFromContent = import_path.default.relative(contentDir, file).replace(/\\/g, "/");
|
|
1825
1782
|
const slug = resolveSlugFromFile(relFromContent);
|
|
1826
|
-
|
|
1827
|
-
|
|
1783
|
+
docEntries.push(`{
|
|
1784
|
+
slug: "${slug}",
|
|
1828
1785
|
path: "${relFromContent}",
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
}`);
|
|
1786
|
+
data: {
|
|
1787
|
+
metadata: ${importName}.metadata,
|
|
1788
|
+
raw: ${importName}.raw,
|
|
1789
|
+
tableOfContents: ${importName}.tableOfContents,
|
|
1790
|
+
mdxContent: ${importName}.mdxContent
|
|
1791
|
+
}
|
|
1792
|
+
}`);
|
|
1837
1793
|
});
|
|
1838
1794
|
const finalOutput = `// @ts-nocheck -- auto generated by docstra
|
|
1795
|
+
${imports.join("\n")}
|
|
1839
1796
|
|
|
1840
1797
|
export const docs = [
|
|
1841
|
-
${
|
|
1798
|
+
${docEntries.join(",\n ")}
|
|
1842
1799
|
];
|
|
1843
1800
|
`;
|
|
1844
1801
|
import_fs.default.writeFileSync(outFile, finalOutput, "utf8");
|
|
@@ -1859,9 +1816,6 @@ function getAllMdxFiles(dir) {
|
|
|
1859
1816
|
function resolveSlugFromFile(relFromContent) {
|
|
1860
1817
|
return relFromContent.replace(/\\/g, "/").replace(/\/index\.(md|mdx)$/, "").replace(/\.(md|mdx)$/, "");
|
|
1861
1818
|
}
|
|
1862
|
-
function extractHeadings(content) {
|
|
1863
|
-
return content.split("\n").filter((line) => line.startsWith("#")).map((h) => h.replace(/#/g, "").trim());
|
|
1864
|
-
}
|
|
1865
1819
|
|
|
1866
1820
|
// src/server/dev.ts
|
|
1867
1821
|
var watcherStarted = false;
|
|
@@ -1939,11 +1893,26 @@ function withDocstra(nextConfig = {}) {
|
|
|
1939
1893
|
}
|
|
1940
1894
|
return {
|
|
1941
1895
|
...nextConfig,
|
|
1942
|
-
pageExtensions: nextConfig.pageExtensions ?? ["ts", "tsx", "js", "jsx", "md", "mdx"]
|
|
1896
|
+
pageExtensions: nextConfig.pageExtensions ?? ["ts", "tsx", "js", "jsx", "md", "mdx"],
|
|
1897
|
+
webpack: (config, options) => {
|
|
1898
|
+
config.module.rules.push({
|
|
1899
|
+
test: /\.(md|mdx)$/,
|
|
1900
|
+
resourceQuery: /docstra/,
|
|
1901
|
+
use: [
|
|
1902
|
+
{
|
|
1903
|
+
loader: require.resolve("./docstra-loader")
|
|
1904
|
+
}
|
|
1905
|
+
]
|
|
1906
|
+
});
|
|
1907
|
+
if (typeof nextConfig.webpack === "function") {
|
|
1908
|
+
return nextConfig.webpack(config, options);
|
|
1909
|
+
}
|
|
1910
|
+
return config;
|
|
1911
|
+
}
|
|
1943
1912
|
};
|
|
1944
1913
|
}
|
|
1945
1914
|
|
|
1946
|
-
// src/client/create-heading.tsx
|
|
1915
|
+
// src/client/components/create-heading.tsx
|
|
1947
1916
|
var import_lucide_react = require("lucide-react");
|
|
1948
1917
|
|
|
1949
1918
|
// src/utils/generate-id-from-text.ts
|
|
@@ -1951,8 +1920,8 @@ function generateIdFromText(text) {
|
|
|
1951
1920
|
return text.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
1952
1921
|
}
|
|
1953
1922
|
|
|
1954
|
-
// src/client/create-heading.tsx
|
|
1955
|
-
var
|
|
1923
|
+
// src/client/components/create-heading.tsx
|
|
1924
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1956
1925
|
function CreateHeading({ children, level }) {
|
|
1957
1926
|
const Heading = `h${level}`;
|
|
1958
1927
|
const text = typeof children === "string" ? children : "";
|
|
@@ -1980,14 +1949,14 @@ function CreateHeading({ children, level }) {
|
|
|
1980
1949
|
fontSize = "text-base";
|
|
1981
1950
|
iconSize = "size-3.5";
|
|
1982
1951
|
}
|
|
1983
|
-
return /* @__PURE__ */ (0,
|
|
1952
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1984
1953
|
Heading,
|
|
1985
1954
|
{
|
|
1986
1955
|
id,
|
|
1987
1956
|
className: `group mt-10 gap-2 mb-4 flex items-center scroll-mt-26 ${fontSize} font-semibold text-gray-900`,
|
|
1988
1957
|
children: [
|
|
1989
|
-
/* @__PURE__ */ (0,
|
|
1990
|
-
/* @__PURE__ */ (0,
|
|
1958
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: `#${id}`, children }),
|
|
1959
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.LinkIcon, { className: `${iconSize} text-gray-400 opacity-0 group-hover:opacity-100 transition` })
|
|
1991
1960
|
]
|
|
1992
1961
|
}
|
|
1993
1962
|
);
|
|
@@ -1995,38 +1964,91 @@ function CreateHeading({ children, level }) {
|
|
|
1995
1964
|
|
|
1996
1965
|
// src/server/mdx-components.tsx
|
|
1997
1966
|
var import_link = __toESM(require("next/link"));
|
|
1998
|
-
var
|
|
1967
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1999
1968
|
function defaultMdxComponents() {
|
|
2000
1969
|
return {
|
|
2001
|
-
h1: (props) => /* @__PURE__ */ (0,
|
|
2002
|
-
h2: (props) => /* @__PURE__ */ (0,
|
|
2003
|
-
h3: (props) => /* @__PURE__ */ (0,
|
|
2004
|
-
h4: (props) => /* @__PURE__ */ (0,
|
|
2005
|
-
h5: (props) => /* @__PURE__ */ (0,
|
|
2006
|
-
code: (props) => /* @__PURE__ */ (0,
|
|
2007
|
-
p: (props) => /* @__PURE__ */ (0,
|
|
2008
|
-
hr: () => /* @__PURE__ */ (0,
|
|
1970
|
+
h1: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h1", { className: "text-3xl font-bold text-gray-900 mb-4", children: props.children }),
|
|
1971
|
+
h2: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 2 }),
|
|
1972
|
+
h3: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 3 }),
|
|
1973
|
+
h4: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 4 }),
|
|
1974
|
+
h5: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CreateHeading, { ...props, level: 5 }),
|
|
1975
|
+
code: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { className: "px-1 py-0.5 rounded border border-gray-200 text-gray-800 text-sm", children: props.children }),
|
|
1976
|
+
p: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "my-5", children: props.children }),
|
|
1977
|
+
hr: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("hr", { className: "my-10 border-gray-200" }),
|
|
2009
1978
|
a: (props) => {
|
|
2010
1979
|
if (props.href.startsWith("http")) {
|
|
2011
|
-
return /* @__PURE__ */ (0,
|
|
1980
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: props.href, className: "underline underline-offset-4", ...props, target: "_blank", rel: "noopener noreferrer", children: props.children });
|
|
2012
1981
|
}
|
|
2013
|
-
return /* @__PURE__ */ (0,
|
|
1982
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_link.default, { href: props.href, className: "underline underline-offset-4", ...props, children: props.children });
|
|
2014
1983
|
},
|
|
2015
|
-
ul: (props) => /* @__PURE__ */ (0,
|
|
2016
|
-
li: (props) => /* @__PURE__ */ (0,
|
|
2017
|
-
ol: (props) => /* @__PURE__ */ (0,
|
|
2018
|
-
blockquote: (props) => /* @__PURE__ */ (0,
|
|
1984
|
+
ul: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "list-['-'] pl-4 space-y-2", children: props.children }),
|
|
1985
|
+
li: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("li", { className: "mb-2 pl-3 text-gray-700", children: props.children }),
|
|
1986
|
+
ol: (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ol", { className: "list-decimal pl-4 space-y-2", children: props.children }),
|
|
1987
|
+
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 })
|
|
2019
1988
|
};
|
|
2020
1989
|
}
|
|
2021
1990
|
|
|
2022
1991
|
// src/server/get-page-data.ts
|
|
2023
1992
|
function getPageData(slug, docs) {
|
|
2024
|
-
const pageData = docs.find((d) => d.
|
|
1993
|
+
const pageData = docs.find((d) => d.slug === (slug?.join("/") || "index"));
|
|
2025
1994
|
return pageData;
|
|
2026
1995
|
}
|
|
1996
|
+
|
|
1997
|
+
// src/server/source.ts
|
|
1998
|
+
function createSource(docs) {
|
|
1999
|
+
return {
|
|
2000
|
+
getPage: (slug) => {
|
|
2001
|
+
const slugStr = slug?.join("/") || "index";
|
|
2002
|
+
const doc = docs.find((d) => d.slug === slugStr);
|
|
2003
|
+
if (!doc) return null;
|
|
2004
|
+
const { mdxContent, ...safeData } = doc.data;
|
|
2005
|
+
return {
|
|
2006
|
+
info: {
|
|
2007
|
+
...doc,
|
|
2008
|
+
data: safeData
|
|
2009
|
+
},
|
|
2010
|
+
body: doc.data.mdxContent
|
|
2011
|
+
};
|
|
2012
|
+
},
|
|
2013
|
+
generateStaticParams: () => {
|
|
2014
|
+
return docs.map((d) => ({
|
|
2015
|
+
slug: d.slug === "index" ? [] : d.slug.split("/")
|
|
2016
|
+
}));
|
|
2017
|
+
},
|
|
2018
|
+
// Returns generic metadata for all pages (stripped of MDX component)
|
|
2019
|
+
// Useful for Sidebar, Search, global context
|
|
2020
|
+
files: docs.map((d) => {
|
|
2021
|
+
const { mdxContent, ...safeData } = d.data;
|
|
2022
|
+
return {
|
|
2023
|
+
...d,
|
|
2024
|
+
data: safeData
|
|
2025
|
+
};
|
|
2026
|
+
}),
|
|
2027
|
+
// Returns user to sitemap with
|
|
2028
|
+
// <url>
|
|
2029
|
+
// <loc>https://example.com/page</loc>
|
|
2030
|
+
// <lastmod>2022-01-01</lastmod>
|
|
2031
|
+
// <changefreq>monthly</changefreq>
|
|
2032
|
+
// <priority>0.5</priority>
|
|
2033
|
+
// </url>
|
|
2034
|
+
generateSitemap: ({
|
|
2035
|
+
baseUrl,
|
|
2036
|
+
lastmod,
|
|
2037
|
+
changefreq,
|
|
2038
|
+
priority
|
|
2039
|
+
}) => {
|
|
2040
|
+
return docs.map((d) => ({
|
|
2041
|
+
url: `${baseUrl}/${d.slug.replace("index", "")}`,
|
|
2042
|
+
lastModified: lastmod,
|
|
2043
|
+
changeFrequency: changefreq,
|
|
2044
|
+
priority
|
|
2045
|
+
}));
|
|
2046
|
+
}
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2027
2049
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2028
2050
|
0 && (module.exports = {
|
|
2029
|
-
|
|
2051
|
+
createSource,
|
|
2030
2052
|
defaultMdxComponents,
|
|
2031
2053
|
defineDocstraConfig,
|
|
2032
2054
|
getPageData,
|