Skip to content

Get Started with VitePress

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

Quickstart for New Project

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

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

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 VitePress 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 vue
npx @documate/documate init --framework vue

This command does the following:

  • Install @documate/documate and @documate/vue packages to your project
  • Create a documate.json
json
{
  "root": ".",
  "include": [ "**/*.md" ],
  "backend": ""
}
{
  "root": ".",
  "include": [ "**/*.md" ],
  "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

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

js
// .vitepress/theme/index.js
import { h } from 'vue'
import DefaultTheme from 'vitepress/theme'
import Documate from '@documate/vue'
import '@documate/vue/dist/style.css'

export default {
  ...DefaultTheme,
  Layout: h(DefaultTheme.Layout, null, {
    'nav-bar-content-before': () => h(Documate, {
      endpoint: '',
    }),
  }),
}
// .vitepress/theme/index.js
import { h } from 'vue'
import DefaultTheme from 'vitepress/theme'
import Documate from '@documate/vue'
import '@documate/vue/dist/style.css'

export default {
  ...DefaultTheme,
  Layout: h(DefaultTheme.Layout, null, {
    'nav-bar-content-before': () => h(Documate, {
      endpoint: '',
    }),
  }),
}

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 .vitepress/theme/index.js file to pass the endpoint to the Documate component as props.

js
// .vitepress/theme/index.js
import { h } from 'vue'
import DefaultTheme from 'vitepress/theme'
import Documate from '@documate/vue'
import '@documate/vue/dist/style.css'

export default {
  ...DefaultTheme,
  Layout: h(DefaultTheme.Layout, null, {
    'nav-bar-content-before': () => h(Documate, {
        // Replace the URL with your own one
        endpoint: 'https://test123.us.aircode.run/ask',
      },
    ),
  }),
}
// .vitepress/theme/index.js
import { h } from 'vue'
import DefaultTheme from 'vitepress/theme'
import Documate from '@documate/vue'
import '@documate/vue/dist/style.css'

export default {
  ...DefaultTheme,
  Layout: h(DefaultTheme.Layout, null, {
    'nav-bar-content-before': () => h(Documate, {
        // Replace the URL with your own one
        endpoint: 'https://test123.us.aircode.run/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 at the top left corner.

bash
npm run docs:dev
npm run docs:dev

Made with ❤️ by AirCode