feat(v2): contextual search, dynamic Algolia facetFilters ()

* POC of contextual search dynamic filters

* fix useSearchTags bugs

* contextual search should use preferred version  (persisted in storage)

* Contextual search: make system decoupled from algolia + wire proper meta tags and facet filters

* rework doc tag + minor refactorings

* update snapshots

* polish contextual search

* add Algolia validateThemeConfig tests
This commit is contained in:
Sébastien Lorber 2020-10-15 12:16:30 +02:00 committed by GitHub
parent d23940c9c3
commit 21264f5ed0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 468 additions and 138 deletions
packages/docusaurus-plugin-content-docs/src/theme/hooks

View file

@ -19,6 +19,7 @@ import {
getActiveDocContext,
getDocVersionSuggestions,
GetActivePluginOptions,
ActivePlugin,
} from '../../client/docsClientUtils';
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
@ -33,6 +34,23 @@ export const useActivePlugin = (options: GetActivePluginOptions = {}) => {
return getActivePlugin(data, pathname, options);
};
export const useActivePluginAndVersion = (
options: GetActivePluginOptions = {},
):
| undefined
| {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined} => {
const activePlugin = useActivePlugin(options);
const {pathname} = useLocation();
if (activePlugin) {
const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
return {
activePlugin,
activeVersion,
};
}
return undefined;
};
// versions are returned ordered (most recent first)
export const useVersions = (pluginId: string | undefined): GlobalVersion[] => {
const data = useDocsData(pluginId);