Skip to content

Commit

Permalink
feat: add search to the new documentation website (#7878)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkajtoch authored Jul 15, 2024
1 parent e39a488 commit d405f1a
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/docusaurus-theme/src/theme/MDXContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const MDXContent = (props: Props): JSX.Element => {
const styles = useEuiMemoizedStyles(getStyles);

return (
<EuiText size="m" css={styles.text}>
<EuiText size="m" css={styles.text} data-search-children>
<OriginalMDXContent {...props} />
</EuiText>
);
Expand Down
21 changes: 21 additions & 0 deletions packages/website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,29 @@ This step is usually unnecessary to run locally unless you're testing production
yarn build
```

You can serve the built static files for local testing by running

```shell
yarn serve
```

### Running type checks

```shell
yarn typecheck
```

## Documentation search

We use [lunr.js](https://github.com/olivernn/lunr.js) for local search
on our documentation site. Lunr generates search indexes when the
site is being built that we later fetch as JSON objects in runtime
to provide users with accurate search results. This approach allows us
to have version-specific search experience without the need to run
a search server.

Because the search index is generated in build time, it means that
searching is not possible when running the development sever.
Please refer to the [Building the website](#building-the-website) section
to learn how to build the documentation site locally
and serve it to use local search.
6 changes: 6 additions & 0 deletions packages/website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const config: Config = {
],
],

plugins: [
['docusaurus-lunr-search', {
disableVersioning: true, // We don't use docusaurus docs versioning
}]
],

themeConfig: {
navbar: {
title: 'Elastic UI',
Expand Down
2 changes: 2 additions & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"@emotion/react": "^11.11.4",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"docusaurus-lunr-search": "^3.4.0",
"hast-util-is-element": "1.1.0",
"moment": "^2.30.1",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
Expand Down
Loading

0 comments on commit d405f1a

Please sign in to comment.