mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 16:47:26 +02:00
feat(v2): contextual search, dynamic Algolia facetFilters (#3550)
* 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:
parent
d23940c9c3
commit
21264f5ed0
21 changed files with 468 additions and 138 deletions
|
@ -302,6 +302,7 @@ Object {
|
|||
\\"version\\": \\"current\\"
|
||||
}",
|
||||
"version-current-metadata-prop-751.json": "{
|
||||
\\"pluginId\\": \\"default\\",
|
||||
\\"version\\": \\"current\\",
|
||||
\\"label\\": \\"Next\\",
|
||||
\\"isLast\\": true,
|
||||
|
@ -640,6 +641,7 @@ Object {
|
|||
\\"sidebar\\": \\"version-1.0.0/community\\"
|
||||
}",
|
||||
"version-1-0-0-metadata-prop-608.json": "{
|
||||
\\"pluginId\\": \\"community\\",
|
||||
\\"version\\": \\"1.0.0\\",
|
||||
\\"label\\": \\"1.0.0\\",
|
||||
\\"isLast\\": true,
|
||||
|
@ -657,6 +659,7 @@ Object {
|
|||
}
|
||||
}",
|
||||
"version-current-metadata-prop-751.json": "{
|
||||
\\"pluginId\\": \\"community\\",
|
||||
\\"version\\": \\"current\\",
|
||||
\\"label\\": \\"Next\\",
|
||||
\\"isLast\\": false,
|
||||
|
@ -1102,6 +1105,7 @@ Object {
|
|||
\\"version\\": \\"withSlugs\\"
|
||||
}",
|
||||
"version-1-0-0-metadata-prop-608.json": "{
|
||||
\\"pluginId\\": \\"default\\",
|
||||
\\"version\\": \\"1.0.0\\",
|
||||
\\"label\\": \\"1.0.0\\",
|
||||
\\"isLast\\": false,
|
||||
|
@ -1145,6 +1149,7 @@ Object {
|
|||
}
|
||||
}",
|
||||
"version-1-0-1-metadata-prop-e87.json": "{
|
||||
\\"pluginId\\": \\"default\\",
|
||||
\\"version\\": \\"1.0.1\\",
|
||||
\\"label\\": \\"1.0.1\\",
|
||||
\\"isLast\\": true,
|
||||
|
@ -1182,6 +1187,7 @@ Object {
|
|||
}
|
||||
}",
|
||||
"version-current-metadata-prop-751.json": "{
|
||||
\\"pluginId\\": \\"default\\",
|
||||
\\"version\\": \\"current\\",
|
||||
\\"label\\": \\"Next\\",
|
||||
\\"isLast\\": false,
|
||||
|
@ -1219,6 +1225,7 @@ Object {
|
|||
}
|
||||
}",
|
||||
"version-with-slugs-metadata-prop-2bf.json": "{
|
||||
\\"pluginId\\": \\"default\\",
|
||||
\\"version\\": \\"withSlugs\\",
|
||||
\\"label\\": \\"withSlugs\\",
|
||||
\\"isLast\\": false,
|
||||
|
|
|
@ -267,7 +267,11 @@ export default function pluginContentDocs(
|
|||
`${docuHash(
|
||||
`version-${loadedVersion.versionName}-metadata-prop`,
|
||||
)}.json`,
|
||||
JSON.stringify(toVersionMetadataProp(loadedVersion), null, 2),
|
||||
JSON.stringify(
|
||||
toVersionMetadataProp(pluginId, loadedVersion),
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
|
||||
addRoute({
|
||||
|
|
|
@ -13,6 +13,7 @@ declare module '@docusaurus/plugin-content-docs-types' {
|
|||
};
|
||||
|
||||
export type PropVersionMetadata = {
|
||||
pluginId: string;
|
||||
version: string;
|
||||
label: string;
|
||||
isLast: boolean;
|
||||
|
|
|
@ -62,9 +62,11 @@ Available document ids=
|
|||
}
|
||||
|
||||
export function toVersionMetadataProp(
|
||||
pluginId: string,
|
||||
loadedVersion: LoadedVersion,
|
||||
): PropVersionMetadata {
|
||||
return {
|
||||
pluginId,
|
||||
version: loadedVersion.versionName,
|
||||
label: loadedVersion.versionLabel,
|
||||
isLast: loadedVersion.isLast,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue