diff --git a/docs/01-getting-started/03-initialization.md b/docs/01-getting-started/03-initialization.md
index 3a583d23..fb914a8d 100644
--- a/docs/01-getting-started/03-initialization.md
+++ b/docs/01-getting-started/03-initialization.md
@@ -4,12 +4,12 @@ To use Robindoc with all its features, you need to initialize it. To do this, yo
## Calling the Method
-The method will return dynamic components [`Page`](../03-customization/01-elements/page.md) and [`Sidebar`](../03-customization/01-elements/sidebar.md), as well as the methods [`getPages`](../03-customization/02-tools/get-pages.md), [`getMeta`](../03-customization/02-tools/get-meta.md), and [`getPageContent`](../03-customization/02-tools/get-page-content.md).
+The method will return dynamic components [`Page`](../03-customization/01-elements/page.md) and [`Sidebar`](../03-customization/01-elements/sidebar.md), as well as the methods [`getStaticParams`](../03-customization/02-tools/get-static-params.md), [`getMetadata`](../03-customization/02-tools/get-metadata.md), and [`getPageData`](../03-customization/02-tools/get-page-data.md).
```tsx filename="app/docs/robindoc.ts" tab="TypeScript" switcher clone="jsx|JavaScript|app/docs/robindoc.js"
import { initializeRobindoc } from "robindoc";
-export const { Page, Sidebar, getPages, getMeta, getPageContent } =
+export const { Page, Sidebar, getStaticParams, getMetadata, getPageData } =
initializeRobindoc({
configuration: {
sourceRoot: "../docs",
diff --git a/docs/01-getting-started/04-app-organization.md b/docs/01-getting-started/04-app-organization.md
index f10899d9..03c97581 100644
--- a/docs/01-getting-started/04-app-organization.md
+++ b/docs/01-getting-started/04-app-organization.md
@@ -19,7 +19,7 @@ However, when using the automatic mode for generating the structure, the documen
You can initialize Robindoc on any subpath of your site, as long as you specify the [`basePath`](../02-structure/01-configuration.md) in the project initialization and pass the correct path in the Robindoc components.
-After initialization, you will receive Sidebar, Page, getPages, getMeta, and getPageContent. Read more on the [Initialization](../03-initialization.md) page.
+After initialization, you will receive Sidebar, Page, getStaticParams, getMetadata, and getPageData. Read more on the [Initialization](../03-initialization.md) page.
Global elements - [`RobinProvider`](../03-customization/01-elements/robin-provider.md), [`Header`](../03-customization/01-elements/header.md), [`Footer`](../03-customization/01-elements/footer.md), [`Containers`](../03-customization/01-elements/containers.md) and [`Sidebar`](../03-customization/01-elements/sidebar.md) - should ideally be placed above all pages and reused across all.
Currently, Robindoc works only with the App Router. Once RSC is available for the Pages Router, Robindoc will automatically support it as well.
@@ -28,11 +28,11 @@ Currently, Robindoc works only with the App Router. Once RSC is available for th
Next.js supports dynamic routes, so it is recommended to set up one [dynamic segment](https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes#optional-catch-all-segments) for all documentation pages.
-```tsx filename="app/docs/[[...path]]/page.tsx" switcher tab="v14 TSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```tsx filename="app/docs/[[...segments]]/page.tsx" switcher tab="v14 TSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
-const Page: React.FC<{ params }: { params: { path?: string[] } }> = async ({ params }) => {
- const pathname = "/docs/" + (params.path?.join("/") || "");
+const Page: React.FC<{ params }: { params: { segments?: string[] } }> = async ({ params }) => {
+ const pathname = "/docs/" + (params.segments?.join("/") || "");
return ;
};
@@ -40,11 +40,11 @@ const Page: React.FC<{ params }: { params: { path?: string[] } }> = async ({ par
export default Page;
```
-```jsx filename="app/docs/[[...path]]/page.js" switcher tab="v14 JSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```jsx filename="app/docs/[[...segments]]/page.js" switcher tab="v14 JSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
const Page = async ({ params }) => {
- const pathname = "/docs/" + (params.path?.join("/") || "");
+ const pathname = "/docs/" + (params.segments?.join("/") || "");
return ;
};
@@ -52,12 +52,12 @@ const Page = async ({ params }) => {
export default Page;
```
-```tsx filename="app/docs/[[...path]]/page.tsx" switcher tab="v15 TSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```tsx filename="app/docs/[[...segments]]/page.tsx" switcher tab="v15 TSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
-const Page: React.FC<{ params }: { params: Promise<{ path?: string[] }> }> = async ({ params }) => {
- const { path } = await params;
- const pathname = "/docs/" + (path?.join("/") || "");
+const Page: React.FC<{ params }: { params: Promise<{ segments?: string[] }> }> = async ({ params }) => {
+ const { segments } = await params;
+ const pathname = "/docs/" + (segments?.join("/") || "");
return ;
};
@@ -65,12 +65,12 @@ const Page: React.FC<{ params }: { params: Promise<{ path?: string[] }> }> = asy
export default Page;
```
-```jsx filename="app/docs/[[...path]]/page.js" switcher tab="v15 JSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```jsx filename="app/docs/[[...segments]]/page.js" switcher tab="v15 JSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
const Page = async ({ params }) => {
- const { path } = await params;
- const pathname = "/docs/" + (path?.join("/") || "");
+ const { segments } = await params;
+ const pathname = "/docs/" + (segments?.join("/") || "");
return ;
};
@@ -82,85 +82,85 @@ For more details about the props, refer to the [`Page`](../03-customization/01-e
You should also set up metadata generation and static parameters generation (if you want to use SSG, which is highly recommended):
-```tsx filename="app/docs/[[...path]]/page.tsx" switcher tab="v14 TSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```tsx filename="app/docs/[[...segments]]/page.tsx" switcher tab="v14 TSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
// ...
export const generateMetadata = async ({
params,
}: {
- params: { path?: string[] };
+ params: { segments?: string[] };
}) => {
- const pathname = "/docs/" + (params.path?.join("/") || "");
- const meta = await getMeta(pathname);
+ const pathname = "/docs/" + (params.segments?.join("/") || "");
+ const metadata = await getMetadata(pathname);
- return meta;
+ return metadata;
};
export const generateStaticParams = async () => {
- const pages = await getPages("/docs/");
- return pages.map((page) => ({ path: page.split("/").slice(2) }));
+ const staticParams = await getStaticParams("/docs/");
+ return staticParams;
};
```
-```jsx filename="app/docs/[[...path]]/page.js" switcher tab="v14 JSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```jsx filename="app/docs/[[...segments]]/page.js" switcher tab="v14 JSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
// ...
export const generateMetadata = async ({ params }) => {
- const pathname = "/docs/" + (params.path?.join("/") || "");
- const meta = await getMeta(pathname);
+ const pathname = "/docs/" + (params.segments?.join("/") || "");
+ const metadata = await getMetadata(pathname);
- return meta;
+ return metadata;
};
export const generateStaticParams = async () => {
- const pages = await getPages("/docs/");
- return pages.map((page) => ({ path: page.split("/").slice(2) }));
+ const staticParams = await getStaticParams("/docs/");
+ return staticParams;
};
```
-```tsx filename="app/docs/[[...path]]/page.tsx" switcher tab="v15 TSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```tsx filename="app/docs/[[...segments]]/page.tsx" switcher tab="v15 TSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
// ...
export const generateMetadata = async ({
params,
}: {
- params: Promise<{ path?: string[] }>;
+ params: Promise<{ segments?: string[] }>;
}) => {
- const { path } = await params;
- const pathname = "/docs/" + (path?.join("/") || "");
- const meta = await getMeta(pathname);
+ const { segments } = await params;
+ const pathname = "/docs/" + (segments?.join("/") || "");
+ const metadata = await getMetadata(pathname);
- return meta;
+ return metadata;
};
export const generateStaticParams = async () => {
- const pages = await getPages("/docs/");
- return pages.map((page) => ({ path: page.split("/").slice(2) }));
+ const staticParams = await getStaticParams("/docs/");
+ return staticParams;
};
```
-```jsx filename="app/docs/[[...path]]/page.js" switcher tab="v15 JSX"
-import { Page, Sidebar, getMeta, getPages } from "../robindoc";
+```jsx filename="app/docs/[[...segments]]/page.js" switcher tab="v15 JSX"
+import { Page, Sidebar, getMetadata, getStaticParams } from "../robindoc";
// ...
export const generateMetadata = async ({ params }) => {
- const { path } = await params;
- const pathname = "/docs/" + (path?.join("/") || "");
- const meta = await getMeta(pathname);
+ const { segments } = await params;
+ const pathname = "/docs/" + (segments?.join("/") || "");
+ const metadata = await getMetadata(pathname);
- return meta;
+ return metadata;
};
export const generateStaticParams = async () => {
- const pages = await getPages("/docs/");
- return pages.map((page) => ({ path: page.split("/").slice(2) }));
+ const staticParams = await getStaticParams("/docs/");
+ return staticParams;
};
```
@@ -171,7 +171,7 @@ It is recommended to place the Robindoc initialization near this route.
```ts filename="app/docs/robindoc.ts" switcher tab="TypeScript" clone="js|JavaScript|app/docs/robindoc.js"
import { initializeRobindoc } from "robindoc";
-export const { Page, Sidebar, getPages, getMeta, getPageContent } =
+export const { Page, Sidebar, getStaticParams, getMetadata, getPageData } =
initializeRobindoc({
configuration: {
sourceRoot: "../docs",
@@ -339,21 +339,21 @@ const nextConfig: NextConfig = {
};
```
-For more details on search configuration, refer to the [Search](../03-customization/03-search.md) page.
+For more details on search configuration, refer to the [Search](../03-customization/04-search.md) page.
## Sitemap Setup
-To generate a sitemap in next.js, you can use a [special sitemap file](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap) in combination with [getPages](../03-customization/02-tools/get-pages.md) tool:
+To generate a sitemap in next.js, you can use a [special sitemap file](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap) in combination with [getStaticParams](../03-customization/02-tools/get-static-params.md) tool:
```ts filename="app/sitemap.ts" switcher tab="TypeScript"
import { type MetadataRoute } from "next";
-import { getPages } from "./docs/robindoc";
+import { getStaticParams } from "./docs/robindoc";
const sitemap = async (): Promise => {
- const pages = await getPages();
+ const staticParams = await getStaticParams();
- return pages.map((page) => ({
- url: `https://robindoc.com${page}`,
+ return staticParams.map(({ segments }) => ({
+ url: `https://robindoc.com${segments.join("/")}`,
lastModified: new Date(),
changeFrequency: "daily",
priority: 0.7,
@@ -365,13 +365,13 @@ export default sitemap;
```js filename="app/sitemap.js" switcher tab="JavaScript"
import { type MetadataRoute } from "next";
-import { getPages } from "./docs/robindoc";
+import { getStaticParams } from "./docs/robindoc";
const sitemap = async () => {
- const pages = await getPages();
+ const staticParams = await getStaticParams();
- return pages.map((page) => ({
- url: `https://robindoc.com${page}`,
+ return staticParams.map(({ segments }) => ({
+ url: `https://robindoc.com/${segments.join('/')}`,
lastModified: new Date(),
changeFrequency: "daily",
priority: 0.7,
diff --git a/docs/02-structure/02-items.md b/docs/02-structure/02-items.md
index 6596fb43..13b925aa 100644
--- a/docs/02-structure/02-items.md
+++ b/docs/02-structure/02-items.md
@@ -135,7 +135,7 @@ export const { Page, Sidebar } = initializeRobindoc({
In automatic mode, Robindoc first looks for a `structure.json` file in the current directory.
-If the `structure.json` file is not in the current directory, Robindoc will try to create the structure on its own based on the files in the directory. In this case, it will determine all paths, slugs, as well as the header for the sidebar link. The header is formed according to the same principles as the meta-header. Learn more about getting metadata on the [Get Meta](../03-customization/02-tools/get-meta.md) page.
+If the `structure.json` file is not in the current directory, Robindoc will try to create the structure on its own based on the files in the directory. In this case, it will determine all paths, slugs, as well as the header for the sidebar link. The header is formed according to the same principles as the meta-header. Learn more about getting metadata on the [Get Meta](../03-customization/02-tools/get-metadata.md) page.
## structure.json
diff --git a/docs/03-customization/01-elements/header.md b/docs/03-customization/01-elements/header.md
index 0f9acf57..13ef56bf 100644
--- a/docs/03-customization/01-elements/header.md
+++ b/docs/03-customization/01-elements/header.md
@@ -38,7 +38,7 @@ All customization in Robindoc happens through the structure and props of the com
`links` [`{ title: string; href: string }[]`] - a list of links to pages on your site unrelated to the documentation section. This could include blog, showcases, about, etc.;
-`searcher` - the route for search functionality or a client-side async callback. If this field is not provided, search functionality will not be available. Read more on the "[Search](../03-search.md)" page;
+`searcher` - the route for search functionality or a client-side async callback. If this field is not provided, search functionality will not be available. Read more on the "[Search](../04-search.md)" page;
`translations` [`{ [key: string]: string }`] - translations for the current block. The key is the term identifier, and the value is the corresponding translation. _For the latest list of terms, check the editor hints_;
diff --git a/docs/03-customization/02-tools/README.md b/docs/03-customization/02-tools/README.md
index 1dfe3598..de450ae1 100644
--- a/docs/03-customization/02-tools/README.md
+++ b/docs/03-customization/02-tools/README.md
@@ -7,7 +7,7 @@ These utilities work based on the structure and documentation files. They are ne
```ts filename="app/docs/robindoc.ts" switcher tab="TypeScript" clone="js|JavaScript|app/docs/robindoc.js"
import { initializeRobindoc } from "robindoc";
-export const { Page, Sidebar, getPages, getMeta, getPageContent } =
+export const { Page, Sidebar, getStaticParams, getMetadata, getPageData } =
initializeRobindoc({
configuration: {
sourceRoot: "../docs",
@@ -18,4 +18,4 @@ export const { Page, Sidebar, getPages, getMeta, getPageContent } =
});
```
-For more information on using the utilities, refer to their respective pages - [`getMeta`](./get-meta.md), [`getPages`](./get-pages.md), [`getPageContent`](./get-page-content.md).
+For more information on using the utilities, refer to their respective pages - [`getMetadata`](./get-metadata.md), [`getStaticParams`](./get-static-params.md), [`getPageData`](./get-page-data.md).
diff --git a/docs/03-customization/02-tools/get-meta.md b/docs/03-customization/02-tools/get-meta.md
deleted file mode 100644
index 4e66f316..00000000
--- a/docs/03-customization/02-tools/get-meta.md
+++ /dev/null
@@ -1,55 +0,0 @@
-# Get Meta
-
-`getMeta` generates a metadata object for the current structure (including those automatically generated during initialization).
-
-## Metadata Generation
-
-To collect metadata, Robindoc supports front-matter:
-
-```markdown filename="README.md"
----
-title: "Get Meta | Robindoc"
-description: "Robindoc AAAAAA"
----
-```
-
-If you do not provide a front-matter title, the first-level heading of the page will be used as the title.
-
-## Usage
-
-`getMeta` is obtained as a result of [initializing Robindoc](../../01-getting-started/03-initialization.md).
-
-For more details on using the utility in your application, refer to the section [App Organization](../../01-getting-started/04-app-organization.md).
-
-You can get the metadata object for a specific page using the following method:
-
-```tsx filename="app/docs/page.tsx" switcher tab="TypeScript"
-import { getMeta } from "./robindoc";
-
-export const generateMetadata = async ({
- params,
-}: {
- params: { path?: string[] };
-}) => {
- const pathname = "/docs/" + (params.path?.join("/") || "");
- const meta = await getMeta(pathname);
-
- return meta;
-};
-```
-
-```jsx filename="app/docs/page.jsx" switcher tab="JavaScript"
-import { getMeta } from "./robindoc";
-
-export const generateMetadata = async ({ params }) => {
- const { path } = await params;
- const pathname = "/docs/" + (path?.join("/") || "");
- const meta = await getMeta(pathname);
-
- return meta;
-};
-```
-
-## Arguments
-
-`pathname` - the full path of the current page (e.g., `/docs/02-tools/get-meta`) must be provided to obtain the metadata.
diff --git a/docs/03-customization/02-tools/get-metadata.md b/docs/03-customization/02-tools/get-metadata.md
new file mode 100644
index 00000000..95c3390d
--- /dev/null
+++ b/docs/03-customization/02-tools/get-metadata.md
@@ -0,0 +1,55 @@
+# Get Metadata
+
+`getMetadata` generates a metadata object for the current structure (_including those automatically generated during initialization_).
+
+## Metadata Generation
+
+To collect metadata, Robindoc supports front-matter:
+
+```markdown filename="README.md"
+---
+title: "Get Metadata | Robindoc"
+description: "Robindoc AAAAAA"
+---
+```
+
+If you do not provide a front-matter title, the first-level heading of the page will be used as the title.
+
+## Usage
+
+`getMetadata` is obtained as a result of [initializing Robindoc](../../01-getting-started/03-initialization.md).
+
+For more details on using the utility in your application, refer to the section [App Organization](../../01-getting-started/04-app-organization.md).
+
+You can get the metadata object for a specific page using the following method:
+
+```tsx filename="app/docs/page.tsx" switcher tab="TypeScript"
+import { getMetadata } from "./robindoc";
+
+export const generateMetadata = async ({
+ params,
+}: {
+ params: { segments?: string[] };
+}) => {
+ const pathname = "/docs/" + (params.segments?.join("/") || "");
+ const metadata = await getMetadata(pathname);
+
+ return metadata;
+};
+```
+
+```jsx filename="app/docs/page.jsx" switcher tab="JavaScript"
+import { getMetadata } from "./robindoc";
+
+export const generateMetadata = async ({ params }) => {
+ const { segments } = await params;
+ const pathname = "/docs/" + (segments?.join("/") || "");
+ const metadata = await getMetadata(pathname);
+
+ return metadata;
+};
+```
+
+## Arguments
+
+`pathname` - the full path of the current page (f.e., `/docs/02-tools/get-metadata`) must be provided to obtain the metadata.
diff --git a/docs/03-customization/02-tools/get-page-content.md b/docs/03-customization/02-tools/get-page-content.md
deleted file mode 100644
index 9c9e245c..00000000
--- a/docs/03-customization/02-tools/get-page-content.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# Get Page Content
-
-`getPageContent` is a utility that returns the markdown document and its title (generated for the structure).
-
-## Usage
-
-`getPageContent` is obtained as a result of [initializing Robindoc](../../01-getting-started/03-initialization.md).
-
-It can be used, for example, for search functionality. For more details on general search configuration, refer to the [Search](../03-search.md) page. For Next.js-specific setup, refer to the [App Organization](../../01-getting-started/04-app-organization.md) page.
-
-```ts filename="app/api/search/route.ts" switcher tab="TypeScript" clone="js|JavaScript|app/api/search/route.js"
-const searchResults = [];
-const { content, title } = await getPageContent("/docs/introduction");
-
-if (content.includes(search)) {
- searchResults.push({ href: "/docs/introduction", content, title });
-}
-```
-
-## Arguments
-
-`pathname` - the full path of the current page (e.g., `/docs/introduction`) must be provided to obtain the page data.
diff --git a/docs/03-customization/02-tools/get-page-data.md b/docs/03-customization/02-tools/get-page-data.md
new file mode 100644
index 00000000..a2351c6d
--- /dev/null
+++ b/docs/03-customization/02-tools/get-page-data.md
@@ -0,0 +1,22 @@
+# Get Page Data
+
+`getPageData` is a utility that returns the markdown document and its title (generated for the structure).
+
+## Usage
+
+`getPageData` is obtained as a result of [initializing Robindoc](../../01-getting-started/03-initialization.md).
+
+It can be used, for example, for search functionality. For more details on general search configuration, refer to the [Search](../04-search.md) page. For Next.js-specific setup, refer to the [App Organization](../../01-getting-started/04-app-organization.md) page.
+
+```ts filename="app/api/search/route.ts" switcher tab="TypeScript" clone="js|JavaScript|app/api/search/route.js"
+const searchResults = [];
+const { raw, title } = await getPageData("/docs/introduction");
+
+if (raw.includes(search)) {
+ searchResults.push({ href: "/docs/introduction", raw, title });
+}
+```
+
+## Arguments
+
+`pathname` - the full path of the current page (f.e., `/docs/introduction`) must be provided to obtain the page data.
diff --git a/docs/03-customization/02-tools/get-pages.md b/docs/03-customization/02-tools/get-pages.md
deleted file mode 100644
index 06a254d1..00000000
--- a/docs/03-customization/02-tools/get-pages.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# Get Pages
-
-`getPages` allows you to retrieve a list of all pages for the current structure (including those automatically generated).
-
-## Usage
-
-`getPages` is obtained as a result of [initializing Robindoc](../../01-getting-started/03-initialization.md).
-
-For more details on using the utility in your application, refer to the [App Organization](../../01-getting-started/04-app-organization.md) page.
-
-You can obtain an array of objects with the list of segments for each page using the following method:
-
-```tsx filename="app/docs/[[...path]]/page.tsx" switcher tab="TypeScript" clone="jsx|JavaScript|app/docs/[[...path]]/page.jsx"
-import { getPages } from "./robindoc";
-
-export const generateStaticParams = async () => {
- const pages = await getPages();
- return pages.map((page) => ({ path: page.split("/").slice(2) }));
-};
-```
-
-## Arguments
-
-In some cases, you might want to retrieve a specific section of the documentation, such as `/docs` or `/blog`. To get a filtered list of pages, simply pass the desired prefix as an argument.
-
-```tsx filename="app/docs/[[...path]]/page.tsx" switcher tab="TypeScript" clone="jsx|JavaScript|app/docs/[[...path]]/page.jsx"
-const pages = await getPages("/docs");
-```
diff --git a/docs/03-customization/02-tools/get-static-params.md b/docs/03-customization/02-tools/get-static-params.md
new file mode 100644
index 00000000..ba64c671
--- /dev/null
+++ b/docs/03-customization/02-tools/get-static-params.md
@@ -0,0 +1,34 @@
+# Get Static Params
+
+`getStaticParams` allows you to retrieve a list of all pages for the current structure (including those automatically generated).
+
+## Usage
+
+`getStaticParams` is obtained as a result of [initializing Robindoc](../../01-getting-started/03-initialization.md).
+
+For more details on using the utility in your application, refer to the [App Organization](../../01-getting-started/04-app-organization.md) page.
+
+You can obtain an array of objects with the list of segments for each page using the following method:
+
+```tsx filename="app/docs/[[...segments]]/page.tsx" switcher tab="TypeScript" clone="jsx|JavaScript|app/docs/[[...segments]]/page.jsx"
+import { getStaticParams } from "./robindoc";
+
+export const generateStaticParams = async () => {
+ const staticParams = await getStaticParams();
+ return staticParams;
+};
+```
+
+## Arguments
+
+In some cases, you might want to retrieve a specific section of the documentation, such as `/docs` or `/blog`. To get a filtered list of pages, simply pass the desired `prefix` as an argument.
+
+```tsx filename="app/docs/[[...segments]]/page.tsx" switcher tab="TypeScript" clone="jsx|JavaScript|app/docs/[[...segments]]/page.jsx"
+const staticParams = await getStaticParams("/docs");
+```
+
+Also in some situations you may need a different key for the parameter (the default and recommended is `segments`). In such situations, pass the name of the dynamic parameter as the second argument (`segmentsParamKey`):
+
+```tsx filename="app/docs/[[...segments]]/page.tsx" switcher tab="TypeScript" clone="jsx|JavaScript|app/docs/[[...segments]]/page.jsx"
+const staticParams = await getStaticParams("/docs", "path");
+```
diff --git a/docs/03-customization/04-search.md b/docs/03-customization/04-search.md
index 1cc94818..6ea75b65 100644
--- a/docs/03-customization/04-search.md
+++ b/docs/03-customization/04-search.md
@@ -7,7 +7,7 @@ You can configure search in two ways: by providing the path to the search API ro
To use an API route for search, pass the path to the search endpoint in the `searcher` prop of the [`Header`](./01-elements/header.md) component. The search API should return an array of results with the following keys:
- `title` - the title of the page (e.g., `Introduction`, `Search`);
-- `href` - the link to the page (e.g., `/docs/introduction`, `/docs/03-search`);
+- `href` - the link to the page (e.g., `/docs/introduction`, `/docs/04-search`);
- `description` - an optional additional field with search results related to the page content.
Here’s an example of how to configure the `Header` component with a search API route:
@@ -58,11 +58,11 @@ export const searcher = async (search, abortController) => {
## API Route Example
-If you use an API route, the server should handle the search requests. The following code demonstrates a simple search implementation using the `match-sorter` library and the utilities `getPages` and `getPageContent`:
+If you use an API route, the server should handle the search requests. The following code demonstrates a simple search implementation using the `match-sorter` library and the utilities `getStaticParams` and `getPageData`:
```ts filename="app/api/search/route.ts" switcher tab="TypeScript"
import { matchSorter } from "match-sorter";
-import { getPages, getPageContent } from "../docs/robindoc";
+import { getStaticParams, getPageData } from "../docs/robindoc";
export const GET = async (request: Request) => {
const url = new URL(request.url);
@@ -73,16 +73,17 @@ export const GET = async (request: Request) => {
if (!search) return new Response(JSON.stringify([]), { headers });
- const pages = await getPages();
- const docs: { href: string; content: string; title: string }[] = [];
+ const staticParams = await getStaticParams();
+ const docs: { href: string; raw: string; title: string }[] = [];
- for await (const page of pages) {
- const { content, title } = await getPageContent(page);
- docs.push({ href: page, content, title });
+ for await (const staticParam of staticParams) {
+ const pathname = `/${staticParam.segments.join("/")}`;
+ const { raw, title } = await getPageData(pathname);
+ docs.push({ href: pathname, raw, title });
}
const matchResults = matchSorter(docs, search, {
- keys: ["content", "title"],
+ keys: ["raw", "title"],
});
const searchResults = matchResults
.slice(0, 5)
@@ -94,7 +95,7 @@ export const GET = async (request: Request) => {
```js filename="app/api/search/route.js" switcher tab="JavaScript"
import { matchSorter } from "match-sorter";
-import { getPages, getPageContent } from "../docs/robindoc";
+import { getStaticParams, getPageData } from "../docs/robindoc";
export const GET = async (request) => {
const url = new URL(request.url);
@@ -105,16 +106,17 @@ export const GET = async (request) => {
if (!search) return new Response(JSON.stringify([]), { headers });
- const pages = await getPages();
+ const staticParams = await getStaticParams();
const docs = [];
- for await (const page of pages) {
- const { content, title } = await getPageContent(page);
- docs.push({ href: page, content, title });
+ for await (const staticParam of staticParams) {
+ const pathname = `/${staticParam.segments.join("/")}`;
+ const { raw, title } = await getPageData(pathname);
+ docs.push({ href: pathname, raw, title });
}
const matchResults = matchSorter(docs, search, {
- keys: ["content", "title"],
+ keys: ["raw", "title"],
});
const searchResults = matchResults
.slice(0, 5)
diff --git a/packages/robindoc/package.json b/packages/robindoc/package.json
index 1ab969d8..1b5f4e1f 100644
--- a/packages/robindoc/package.json
+++ b/packages/robindoc/package.json
@@ -1,6 +1,6 @@
{
"name": "robindoc",
- "version": "2.5.1",
+ "version": "3.0.0",
"description": "",
"main": "./lib/index.js",
"scripts": {
@@ -13,7 +13,13 @@
"assets"
],
"keywords": [
- "documentation"
+ "documentation",
+ "genearation",
+ "SSG",
+ "next.js",
+ "RSC",
+ "docs",
+ "markdown"
],
"repository": {
"type": "git",
diff --git a/packages/robindoc/src/components/blocks/contents/index.tsx b/packages/robindoc/src/components/blocks/contents/index.tsx
index eba5e62e..f9a7c0b9 100644
--- a/packages/robindoc/src/components/blocks/contents/index.tsx
+++ b/packages/robindoc/src/components/blocks/contents/index.tsx
@@ -3,7 +3,7 @@
import React, { useEffect, useRef } from "react";
import clsx from "clsx";
import { useHeadingIndex } from "@src/components/contexts/contents/use-heading-index";
-import { detectGitType } from "@src/core/utils/git-data";
+import { detectGitType } from "@src/core/utils/git-tools";
import "./contents.scss";
diff --git a/packages/robindoc/src/components/blocks/header-social/index.tsx b/packages/robindoc/src/components/blocks/header-social/index.tsx
index 696c8f51..d41d0724 100644
--- a/packages/robindoc/src/components/blocks/header-social/index.tsx
+++ b/packages/robindoc/src/components/blocks/header-social/index.tsx
@@ -1,6 +1,6 @@
import React from "react";
-import { detectGitType } from "@src/core/utils/git-data";
+import { detectGitType } from "@src/core/utils/git-tools";
import { GithubLogo, GitlabLogo, GitLogo } from "@src/components/ui/git-logos";
import "./header-social.scss";
diff --git a/packages/robindoc/src/components/elements/article/utils.ts b/packages/robindoc/src/components/elements/article/utils.ts
index 39cbed8d..fcf35dd8 100644
--- a/packages/robindoc/src/components/elements/article/utils.ts
+++ b/packages/robindoc/src/components/elements/article/utils.ts
@@ -4,6 +4,8 @@ import { lexer, type Tokens, type Token } from "marked";
import { dirname, join } from "path";
import { type BlockquoteType } from "@src/components/ui/blockquote";
+import { parseTokenText } from "@src/core/utils/content-tools";
+
import { type PagesType } from "./types";
export type AnchorData = {
@@ -13,20 +15,6 @@ export type AnchorData = {
token: Token;
};
-export const parseTokenText = (token: Token): string => {
- if (!token) return "";
-
- if ("tokens" in token) {
- return token.tokens?.map((el) => parseTokenText(el)).join("") || "";
- }
-
- if ("raw" in token) {
- return token.raw;
- }
-
- return "";
-};
-
export const parseMarkdown = (content: string) => {
const { content: matterContent } = matter(content);
const tokens = lexer(matterContent.trim());
diff --git a/packages/robindoc/src/components/ui/blockquote/index.tsx b/packages/robindoc/src/components/ui/blockquote/index.tsx
index ed7d3c5b..873dbe5e 100644
--- a/packages/robindoc/src/components/ui/blockquote/index.tsx
+++ b/packages/robindoc/src/components/ui/blockquote/index.tsx
@@ -13,7 +13,8 @@ interface BlockquoteProps {
}
export const Blockquote: React.FC> = ({ className, type, children }) => {
- const { icon: Icon, title } = type && type in TYPES_DATA ? TYPES_DATA[type] : {};
+ const { icon: Icon, title } =
+ type && type in TYPES_DATA ? TYPES_DATA[type] : ({} as { icon: undefined; title: undefined });
return (