@apify/docs-theme 1.0.67 → 1.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/docs-theme",
3
- "version": "1.0.67",
3
+ "version": "1.0.69",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -8,6 +8,7 @@ import {
8
8
  useAlgoliaContextualFacetFilters,
9
9
  useSearchResultUrlProcessor,
10
10
  } from '@docusaurus/theme-search-algolia/client';
11
+ import { useActiveDocContext } from '@docusaurus/plugin-content-docs/client';
11
12
  import Translate from '@docusaurus/Translate';
12
13
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
13
14
  import { createPortal } from 'react-dom';
@@ -47,7 +48,7 @@ function mergeFacetFilters(f1, f2) {
47
48
  }
48
49
 
49
50
  function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
50
- const { siteMetadata } = useDocusaurusContext();
51
+ const { siteMetadata, siteConfig } = useDocusaurusContext();
51
52
  const processSearchResultUrl = useSearchResultUrlProcessor();
52
53
  const contextualSearchFacetFilters = useAlgoliaContextualFacetFilters();
53
54
  const configFacetFilters = props.searchParameters?.facetFilters ?? [];
@@ -56,6 +57,20 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
56
57
  mergeFacetFilters(contextualSearchFacetFilters, configFacetFilters)
57
58
  : // ... or use config facetFilters
58
59
  configFacetFilters;
60
+
61
+ const tags = facetFilters[facetFilters.length - 1];
62
+ const docsPluginId = siteConfig.presets[0][1].docs.id ?? 'default';
63
+ const activeDocContext = useActiveDocContext(docsPluginId);
64
+ let version = tags[tags.length - 1].match(/-([^-]+)$/)?.[1];
65
+
66
+ // normalize the latest version regardless of what number it has,
67
+ // so we can search across all "latest versions of the docs"
68
+ if (!version || !activeDocContext.activeVersion || activeDocContext.activeVersion.isLast) {
69
+ version = 'latest';
70
+ }
71
+
72
+ tags.push(`docusaurus_tag:default-${version}`);
73
+
59
74
  // We let user override default searchParameters if she wants to
60
75
  const searchParameters = {
61
76
  ...props.searchParameters,
@@ -105,7 +120,6 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
105
120
  window.location.href = itemUrl;
106
121
  },
107
122
  }).current;
108
- const { siteConfig } = useDocusaurusContext();
109
123
  const transformItems = useRef((items) => (props.transformItems
110
124
  ? // Custom transformItems
111
125
  props.transformItems(items)