@apify/docs-theme 1.0.68 → 1.0.70

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.68",
3
+ "version": "1.0.70",
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,9 +57,20 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
56
57
  mergeFacetFilters(contextualSearchFacetFilters, configFacetFilters)
57
58
  : // ... or use config facetFilters
58
59
  configFacetFilters;
60
+
59
61
  const tags = facetFilters[facetFilters.length - 1];
60
- const version = tags[tags.length - 1].match(/-([^-]+)$/)?.[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
+
61
72
  tags.push(`docusaurus_tag:default-${version}`);
73
+
62
74
  // We let user override default searchParameters if she wants to
63
75
  const searchParameters = {
64
76
  ...props.searchParameters,
@@ -108,7 +120,6 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
108
120
  window.location.href = itemUrl;
109
121
  },
110
122
  }).current;
111
- const { siteConfig } = useDocusaurusContext();
112
123
  const transformItems = useRef((items) => (props.transformItems
113
124
  ? // Custom transformItems
114
125
  props.transformItems(items)
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import Head from '@docusaurus/Head';
3
3
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
4
- import { useActiveDocContext } from '@docusaurus/plugin-content-docs/client';
4
+ import { useThemeConfig } from '@docusaurus/theme-common';
5
5
 
6
6
  export default function SearchMetadata({ locale, version, tag }) {
7
7
  const { siteConfig } = useDocusaurusContext();
@@ -10,12 +10,11 @@ export default function SearchMetadata({ locale, version, tag }) {
10
10
  // keep the tag on same value for all the content, and add a new section + section tag
11
11
  const section = siteConfig.projectName;
12
12
  const sectionTag = tag;
13
- const docsPluginId = siteConfig.presets[0][1].docs.id ?? 'default';
14
- const activeDocContext = useActiveDocContext(docsPluginId);
13
+ const { versions } = useThemeConfig();
15
14
 
16
15
  // normalize the latest version regardless of what number it has,
17
16
  // so we can search across all "latest versions of the docs"
18
- if (!version || !activeDocContext.activeVersion || activeDocContext.activeVersion.isLast) {
17
+ if (!version || !versions || version === versions[0]) {
19
18
  version = 'latest';
20
19
  }
21
20