Skip to content

Get Started with Rspress

There are two ways you can integrate Documate with Rspress. Both are convinient and can be done in a few minutes.

Quickstart for New Project

To create a new Rspress site with Documate, use the following command:

bash
npm create documate@latest --template rspress
npm create documate@latest --template rspress

Then follow the prompts.

After the project is created, please follow the instructions to connect it to a backend.

Mannually Add to Existing Project

If you already have a Rspress site, you can add Documate to it by following these steps:

1. Initialize Documate

In the root of your project, run the following command:

bash
npx @documate/documate init --framework react
npx @documate/documate init --framework react

This command does the following:

  • Install @documate/documate and @documate/react packages to your project
  • Create a documate.json
json
{
  "root": ".",
  "include": [ "**/*.md", "**/*.mdx" ],
  "backend": ""
}
{
  "root": ".",
  "include": [ "**/*.md", "**/*.mdx" ],
  "backend": ""
}
  • Add a script to your package.json
json
{
  "scripts": {
    ...
    "documate:upload": "documate upload"
  }
}
{
  "scripts": {
    ...
    "documate:upload": "documate upload"
  }
}

2. Add Documate UI to Your Project

Rspress allows you to customize the project by extending the default theme. In the theme/index.tsx file (You need to create one if it doesn't exist), add the following code:

js
// theme/index.tsx
import Theme from 'rspress/theme'
import { NoSSR } from 'rspress/runtime'
import { Documate } from '@documate/react'
import '@documate/react/dist/style.css'

const Layout = () => (
  <Theme.Layout
    afterNavTitle={
      <NoSSR>
        <Documate endpoint="" />
      </NoSSR>
    }
  />
)

export default {
  ...Theme,
  Layout,
}

export * from 'rspress/theme'
// theme/index.tsx
import Theme from 'rspress/theme'
import { NoSSR } from 'rspress/runtime'
import { Documate } from '@documate/react'
import '@documate/react/dist/style.css'

const Layout = () => (
  <Theme.Layout
    afterNavTitle={
      <NoSSR>
        <Documate endpoint="" />
      </NoSSR>
    }
  />
)

export default {
  ...Theme,
  Layout,
}

export * from 'rspress/theme'

Connect to Backend

Now you are all set with the frontend. The last step is to connect it to the backend.

Prerequisite

Before continue, please make sure you have built and deployed the backend. Follow Build the Backend Guide if you haven't done so. It only takes 5 minutes.

1. Add the Backend URL to documate.json

Open your backend App in the AirCode dashboard, select the deployed upload.js file, and copy the backend URL. It's located under the function's name.

Then add it to the documate.json file:

json
{
  "root": ".",
  "include": [ "**/*.md", "**/*.mdx" ],
  "backend": "https://test123.us.aircode.run/upload"
}
{
  "root": ".",
  "include": [ "**/*.md", "**/*.mdx" ],
  "backend": "https://test123.us.aircode.run/upload"
}

Remember to replace https://test123.us.aircode.run/upload with your own one.

2. Add the ask Endpoint to Component

Find the ask endpoint (Which is the URL for ask.js), and click to copy it.

Then you can pass the endpoint prop to the Documate component.

js
<Documate endpoint="YOUR_DOMAIN/ask" />
<Documate endpoint="YOUR_DOMAIN/ask" />

Run the Project

Now you're all set with Documate. Run the following command to upload your content to backend and generate the knowledge base:

bash
npm run documate:upload
npm run documate:upload

After the command finishes, you can start the dev server and find the Ask AI button in the top left corner.

bash
npm run dev
npm run dev

Made with ❤️ by AirCode