0.23.2 • Published 1 day ago

@markprompt/docusaurus-theme-search v0.23.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 day ago

Markprompt Docusaurus Plugin

A Markprompt plugin for Docusaurus.

Installation

npm install @markprompt/docusaurus-theme-search

Usage

Basic Usage

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

const config = {
  // …

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

  themeConfig:
    /** @type {import('@markprompt/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 @markprompt/react @markprompt/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 '@markprompt/docusaurus-theme-search';
import type SearchBarType from '@theme/SearchBar';
import SearchBar from '@theme-original/SearchBar';
import { lazy, Suspense } from 'react';

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

import '@markprompt/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>
  );
}

Documentation

The full documentation for the package can be found on the Markprompt docs.

Examples

Community

Authors

This library is created by the team behind Markprompt (@markprompt).

License

MIT © Markprompt

0.23.2

1 day ago

0.23.1

6 days ago

0.23.0

16 days ago

0.22.0

17 days ago

0.21.0

22 days ago

0.20.7

1 month ago

0.20.6

1 month ago

0.20.5

2 months ago

0.20.4

2 months ago

0.20.3

2 months ago

0.20.1

2 months ago

0.20.2

2 months ago

0.20.0

2 months ago

0.19.0

2 months ago

0.18.4

2 months ago

0.18.3

3 months ago

0.18.2

3 months ago

0.18.1

3 months ago

0.17.0

3 months ago

0.18.0

3 months ago

0.16.4

3 months ago

0.16.5

3 months ago

0.16.6

3 months ago

0.16.3

3 months ago

0.16.1

3 months ago

0.16.2

3 months ago

0.16.0

3 months ago

0.15.0

4 months ago

0.14.6

4 months ago

0.14.5

4 months ago

0.14.4

4 months ago

0.14.3

5 months ago

0.14.1

5 months ago

0.14.2

5 months ago

0.14.0

5 months ago

0.13.15

5 months ago

0.5.10

11 months ago

0.5.11

11 months ago

0.5.12

10 months ago

0.13.6

7 months ago

0.13.7

7 months ago

0.13.8

7 months ago

0.13.9

7 months ago

0.11.0

8 months ago

0.13.0

8 months ago

0.13.1

8 months ago

0.13.2

8 months ago

0.13.3

8 months ago

0.13.4

7 months ago

0.13.5

7 months ago

0.13.12

7 months ago

0.13.11

7 months ago

0.13.10

7 months ago

0.9.0

9 months ago

0.7.2

10 months ago

0.5.4

11 months ago

0.7.1

10 months ago

0.5.3

11 months ago

0.13.14

6 months ago

0.7.4

10 months ago

0.5.6

11 months ago

0.13.13

7 months ago

0.7.3

10 months ago

0.5.5

11 months ago

0.7.0

10 months ago

0.5.2

11 months ago

0.5.1

11 months ago

0.7.11

10 months ago

0.7.10

10 months ago

0.7.9

10 months ago

0.7.6

10 months ago

0.5.8

11 months ago

0.7.5

10 months ago

0.5.7

11 months ago

0.7.8

10 months ago

0.7.7

10 months ago

0.5.9

11 months ago

0.12.0

8 months ago

0.12.1

8 months ago

0.12.2

8 months ago

0.10.0

8 months ago

0.8.1

10 months ago

0.8.0

10 months ago

0.6.0

10 months ago

0.5.0

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.3.0

11 months ago

0.2.1

11 months ago

0.2.0

12 months ago