@xrpl/ai-docusaurus-theme-search

0.16.0 • Public • Published

Markprompt Docusaurus plugin

A XRPL AI plugin for Docusaurus.

Installation

npm install @xrpl/ai-docusaurus-theme-search

Usage

Basic Usage

In your docusaurus.config.js, add @xrpl/ai-docusaurus-theme-search to themes. Configure markprompt in the themeConfig.

const config = {
  // …

  themes: [
    // …
    '@xrpl/ai-docusaurus-theme-search',
  ],

  themeConfig:
    /** @type {import('@xrpl/ai-docusaurus-theme-search').ThemeConfig} */ ({
      markprompt: {
        projectKey: 'YOUR-PROJECT-KEY',
        trigger: { floating: true },
      },
    }),
};

Now a search button will appear on your Docusaurus page.

Usage with another search plugin

If your Docusaurus project already has a search plugin, such as theme-search-algolia, you need to swizzle the current search plugin, and add Markprompt as a standalone component.

To swizzle your current search plugin, run:

npx docusaurus swizzle

Choose Wrap, and confirm. This will create a SearchBar wrapper component in /src/theme/SearchBar. Next, install the standalone Markprompt component and CSS:

npm install @xrpl/ai-react @xrpl/ai-css

Edit /src/theme/SearchBar/index.tsx to include Markprompt next to your existing search bar. Here is an example:

import type { WrapperProps } from '@docusaurus/types';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { type MarkpromptConfig } from '@xrpl/ai-docusaurus-theme-search';
import type SearchBarType from '@theme/SearchBar';
import SearchBar from '@theme-original/SearchBar';
import React, { lazy, Suspense } from 'react';

// import Markprompt lazily as Docusaurus does not currently support ESM
const Markprompt = lazy(() =>
  import('@xrpl/ai-react').then((mod) => ({ default: mod.Markprompt })),
);

import '@xrpl/ai-css';

type Props = WrapperProps<typeof SearchBarType>;

export default function SearchBarWrapper(props: Props): JSX.Element {
  const { siteConfig } = useDocusaurusContext();

  const { projectKey, ...config } = siteConfig.themeConfig
    .markprompt as MarkpromptConfig;

  return (
    <div style={{ display: 'flex', gap: '16px', alignItems: 'center' }}>
      {/* Docusaurus' version of `ReactDOMServer` doesn't support Suspense yet, so we can only render the component on the client. */}
      {typeof window !== 'undefined' && (
        <Suspense fallback={null}>
          <Markprompt projectKey={projectKey} {...config} />
        </Suspense>
      )}
      <SearchBar {...props} />
    </div>
  );
}

Examples

License

MIT © XRPL AI Devs

Readme

Keywords

none

Package Sidebar

Install

npm i @xrpl/ai-docusaurus-theme-search

Weekly Downloads

1

Version

0.16.0

License

MIT

Unpacked Size

12.7 kB

Total Files

12

Last publish

Collaborators

  • justinr1234
  • intelliot