Skip to content

Get Started with Nextra

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

Quickstart for New Project

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

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

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 Nextra 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

Nextra allows you to customize the theme by editing the theme.config.tsx file. Add the following code to the theme.config.tsx file:

tsx
import { Documate } from '@documate/react'
import '@documate/react/dist/style.css'

const config: DocsThemeConfig = {
  ...
  navbar: {
    extraContent: <Documate endpoint="" />,
  },
  ...
}

export default config
import { Documate } from '@documate/react'
import '@documate/react/dist/style.css'

const config: DocsThemeConfig = {
  ...
  navbar: {
    extraContent: <Documate endpoint="" />,
  },
  ...
}

export default config

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.

Modify the theme.config.tsx file to pass the endpoint to the Documate component as props.

tsx
import { Documate } from '@documate/react'
import '@documate/react/dist/style.css'

const config: DocsThemeConfig = {
  ...
  navbar: {
    // Replace the URL with your own one
    extraContent: <Documate endpoint="https://test123.us.aircode.run/ask" />,
  },
  ...
}

export default config
import { Documate } from '@documate/react'
import '@documate/react/dist/style.css'

const config: DocsThemeConfig = {
  ...
  navbar: {
    // Replace the URL with your own one
    extraContent: <Documate endpoint="https://test123.us.aircode.run/ask" />,
  },
  ...
}

export default config

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 at the top right corner.

bash
npm run dev
npm run dev

Made with ❤️ by AirCode