@apify/docs-theme 1.0.92 → 1.0.93

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.92",
3
+ "version": "1.0.93",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -19,6 +19,7 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
+ "@apify/docs-search-modal": "^1.0.21",
22
23
  "@docusaurus/theme-common": "^2.4.1",
23
24
  "@stackql/docusaurus-plugin-hubspot": "^1.1.0",
24
25
  "axios": "^1.4.0",
@@ -27,7 +28,6 @@
27
28
  "prism-react-renderer": "^2.0.6"
28
29
  },
29
30
  "peerDependencies": {
30
- "@apify/docsearch-apify-docs": "^3.5.3",
31
31
  "react": "*",
32
32
  "react-dom": "*"
33
33
  }
package/src/config.js CHANGED
@@ -241,10 +241,8 @@ const themeConfig = ({
241
241
  },
242
242
  algolia: {
243
243
  appId: 'N8EOCSBQGH',
244
- apiKey: 'b43e67a96ed18c7f63f5fd965906a96d', // search only (public) API key
245
- indexName: 'apify_sdk',
246
- // apiKey: 'e97714a64e2b4b8b8fe0b01cd8592870', // search only (public) API key
247
- // indexName: 'crawler_dev_apify_sdk',
244
+ apiKey: 'e97714a64e2b4b8b8fe0b01cd8592870', // search only (public) API key
245
+ indexName: 'test_test_apify_sdk',
248
246
  algoliaOptions: {
249
247
  facetFilters: ['version:VERSION'],
250
248
  },
@@ -1,18 +1,16 @@
1
- import React, { useCallback, useMemo, useRef, useState } from 'react';
2
- import { DocSearchButton, useDocSearchKeyboardEvents } from '@apify/docsearch-apify-docs';
3
- import Head from '@docusaurus/Head';
4
- import Link from '@docusaurus/Link';
5
- import { useSearchLinkCreator } from '@docusaurus/theme-common/internal';
6
- import { useAlgoliaContextualFacetFilters } from '@docusaurus/theme-search-algolia/client';
7
- import { useActiveDocContext } from '@docusaurus/plugin-content-docs/client';
8
- import Translate from '@docusaurus/Translate';
1
+ import React, { useCallback } from 'react';
2
+
3
+ import { ApifySearch } from '@apify/docs-search-modal';
9
4
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
- import { createPortal } from 'react-dom';
11
- import translations from '@theme/SearchTranslations';
5
+ import { useLocation, useHistory } from '@docusaurus/router';
6
+ import BrowserOnly from '@docusaurus/BrowserOnly';
12
7
 
13
- let DocSearchModal = null;
8
+ import RouterLink from '@docusaurus/Link';
14
9
 
15
- function useLink(href, baseUrl) {
10
+ /**
11
+ * Tests whether the given href is pointing to the current docusaurus instance (so we can use the router link).
12
+ */
13
+ function matchesCurrentInstance(href, baseUrl) {
16
14
  if (baseUrl === '/') {
17
15
  return href.startsWith('/academy') || href.startsWith('/platform');
18
16
  }
@@ -20,7 +18,7 @@ function useLink(href, baseUrl) {
20
18
  return href.startsWith(baseUrl);
21
19
  }
22
20
 
23
- export function A(props) {
21
+ export function Link(props) {
24
22
  props = { ...props };
25
23
 
26
24
  if (props.href.startsWith('https://docs.apify.com')) {
@@ -28,186 +26,45 @@ export function A(props) {
28
26
  }
29
27
 
30
28
  const { siteConfig } = useDocusaurusContext();
31
- if (useLink(props.href, siteConfig.baseUrl)) {
32
- return <Link {...props}>
29
+
30
+ if (matchesCurrentInstance(props.href, siteConfig.baseUrl)) {
31
+ return <RouterLink {...props}>
33
32
  {props.children}
34
- </Link>;
33
+ </RouterLink>;
35
34
  }
36
35
 
37
36
  return <a {...props}>{props.children}</a>;
38
37
  }
39
38
 
40
- function Hit({ hit, children }) {
41
- return <A href={hit.url}>{children}</A>;
42
- }
43
-
44
- function ResultsFooter({ state, onClose }) {
45
- const generateSearchPageLink = useSearchLinkCreator();
46
- return (
47
- <A href={generateSearchPageLink(state.query)} onClick={onClose}>
48
- <Translate
49
- id="theme.SearchBar.seeAll"
50
- values={{ count: state.context.nbHits }}>
51
- {'See all {count} results'}
52
- </Translate>
53
- </A>
54
- );
55
- }
56
-
57
- function mergeFacetFilters(f1, f2) {
58
- const normalize = (f) => (typeof f === 'string' ? [f] : f);
59
- return [...normalize(f1), ...normalize(f2)];
60
- }
39
+ export default function SearchBar() {
40
+ const { siteConfig } = useDocusaurusContext();
41
+ const location = useLocation();
42
+ const history = useHistory();
61
43
 
62
- function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
63
- const { siteMetadata, siteConfig } = useDocusaurusContext();
64
- const contextualSearchFacetFilters = useAlgoliaContextualFacetFilters();
65
- const configFacetFilters = props.searchParameters?.facetFilters ?? [];
66
- const facetFilters = contextualSearch
67
- // Merge contextual search filters with config filters
68
- ? mergeFacetFilters(contextualSearchFacetFilters, configFacetFilters)
69
- // ... or use config facetFilters
70
- : configFacetFilters;
44
+ const navigate = useCallback((href) => {
45
+ const shortHref = href.substring('https://docs.apify.com'.length);
71
46
 
72
- const tags = facetFilters[facetFilters.length - 1];
73
- const docsPluginId = siteConfig.presets[0][1].docs.id ?? 'default';
74
- const activeDocContext = useActiveDocContext(docsPluginId);
75
- let version = tags[tags.length - 1].match(/-([^-]+)$/)?.[1];
47
+ if (matchesCurrentInstance(shortHref, siteConfig.baseUrl)) {
48
+ return history.push(shortHref);
49
+ }
50
+ return window.location.assign(href);
51
+ }, [history, siteConfig.baseUrl]);
76
52
 
77
- // normalize the latest version regardless of what number it has,
78
- // so we can search across all "latest versions of the docs"
79
- if (!version || !activeDocContext.activeVersion || activeDocContext.activeVersion.isLast) {
80
- version = 'latest';
81
- }
53
+ const getVersion = useCallback(() => {
54
+ const match = location.pathname.match(/\/(\d+\.\d+|next)/);
82
55
 
83
- tags.push(`docusaurus_tag:default-${version}`);
56
+ return match ? match[1] : 'latest';
57
+ }, [location]);
84
58
 
85
- // We let user override default searchParameters if she wants to
86
- const searchParameters = {
87
- ...props.searchParameters,
88
- facetFilters,
89
- };
90
- const searchContainer = useRef(null);
91
- const searchButtonRef = useRef(null);
92
- const [isOpen, setIsOpen] = useState(false);
93
- const [initialQuery, setInitialQuery] = useState(undefined);
94
- const importDocSearchModalIfNeeded = useCallback(() => {
95
- if (DocSearchModal) {
96
- return Promise.resolve();
97
- }
98
- return Promise.all([
99
- import('@apify/docsearch-apify-docs/modal'),
100
- import('@apify/docsearch-apify-docs/style'),
101
- import('./styles.css'),
102
- ]).then(([{ DocSearchModal: Modal }]) => {
103
- DocSearchModal = Modal;
104
- });
105
- }, []);
106
- const onOpen = useCallback(() => {
107
- importDocSearchModalIfNeeded().then(() => {
108
- searchContainer.current = document.createElement('div');
109
- document.body.insertBefore(
110
- searchContainer.current,
111
- document.body.firstChild,
112
- );
113
- setIsOpen(true);
114
- });
115
- }, [importDocSearchModalIfNeeded, setIsOpen]);
116
- const onClose = useCallback(() => {
117
- setIsOpen(false);
118
- searchContainer.current?.remove();
119
- }, [setIsOpen]);
120
- const onInput = useCallback(
121
- (event) => {
122
- importDocSearchModalIfNeeded().then(() => {
123
- setIsOpen(true);
124
- setInitialQuery(event.key);
125
- });
126
- },
127
- [importDocSearchModalIfNeeded, setIsOpen, setInitialQuery],
128
- );
129
- const navigator = useRef({
130
- navigate({ itemUrl }) {
131
- window.location.href = itemUrl;
132
- },
133
- }).current;
134
- const transformItems = useRef((items) => (items.map((item) => {
135
- if (item.url.startsWith(siteConfig.url)) {
136
- return { ...item, url: item.url.substring(siteConfig.url.length) };
137
- }
138
- return item;
139
- }))).current;
140
- const resultsFooterComponent = useMemo(
141
- // eslint-disable-next-line react/display-name
142
- () => (footerProps) => <ResultsFooter {...footerProps} onClose={onClose}/>,
143
- [onClose],
144
- );
145
- const transformSearchClient = useCallback(
146
- (searchClient) => {
147
- searchClient.addAlgoliaAgent(
148
- 'docusaurus',
149
- siteMetadata.docusaurusVersion,
150
- );
151
- return searchClient;
152
- },
153
- [siteMetadata.docusaurusVersion],
154
- );
155
- useDocSearchKeyboardEvents({
156
- isOpen,
157
- onOpen,
158
- onClose,
159
- onInput,
160
- searchButtonRef,
161
- });
162
59
  return (
163
- <>
164
- <Head>
165
- {/* This hints the browser that the website will load data from Algolia,
166
- and allows it to preconnect to the DocSearch cluster. It makes the first
167
- query faster, especially on mobile. */}
168
- <link
169
- rel="preconnect"
170
- href={`https://${props.appId}-dsn.algolia.net`}
171
- crossOrigin="anonymous"
172
- />
173
- </Head>
174
-
175
- <DocSearchButton
176
- onTouchStart={importDocSearchModalIfNeeded}
177
- onFocus={importDocSearchModalIfNeeded}
178
- onMouseOver={importDocSearchModalIfNeeded}
179
- onClick={onOpen}
180
- ref={searchButtonRef}
181
- translations={translations.button}
182
- />
183
-
184
- {isOpen
185
- && DocSearchModal
186
- && searchContainer.current
187
- && createPortal(
188
- <DocSearchModal
189
- onClose={onClose}
190
- initialScrollY={window.scrollY}
191
- initialQuery={initialQuery}
192
- navigator={navigator}
193
- transformItems={transformItems}
194
- hitComponent={Hit}
195
- transformSearchClient={transformSearchClient}
196
- {...(props.searchPagePath && {
197
- resultsFooterComponent,
198
- })}
199
- {...props}
200
- searchParameters={searchParameters}
201
- placeholder={translations.placeholder}
202
- translations={translations.modal}
203
- />,
204
- searchContainer.current,
205
- )}
206
- </>
60
+ <BrowserOnly>
61
+ {() => <ApifySearch
62
+ algoliaAppId={siteConfig.themeConfig.algolia.appId}
63
+ algoliaIndexName='test_test_apify_sdk'
64
+ algoliaKey={siteConfig.themeConfig.algolia.apiKey}
65
+ filters={`version:${getVersion()}`}
66
+ navigate={navigate}
67
+ />}
68
+ </BrowserOnly>
207
69
  );
208
70
  }
209
-
210
- export default function SearchBar() {
211
- const { siteConfig } = useDocusaurusContext();
212
- return <DocSearch {...siteConfig.themeConfig.algolia} />;
213
- }
@@ -22,7 +22,7 @@ import {
22
22
  useSearchResultUrlProcessor,
23
23
  } from '@docusaurus/theme-search-algolia/client';
24
24
  import Layout from '@theme/Layout';
25
- import { A } from '../SearchBar';
25
+ import { Link } from '../SearchBar';
26
26
  import styles from './styles.module.css';
27
27
 
28
28
  // Very simple pluralization: probably good enough for now
@@ -386,7 +386,7 @@ function SearchPageContent() {
386
386
  ({ title, url, summary, breadcrumbs }, i) => (
387
387
  <article key={i} className={styles.searchResultItem}>
388
388
  <h2 className={styles.searchResultItemHeading}>
389
- <A href={url} dangerouslySetInnerHTML={{ __html: title }}/>
389
+ <Link href={url} dangerouslySetInnerHTML={{ __html: title }}/>
390
390
  </h2>
391
391
 
392
392
  {breadcrumbs.length > 0 && (
@@ -702,5 +702,3 @@ html[data-theme='dark'] .beta-chip {
702
702
  a.tsd-anchor[href^="https://undefined"] {
703
703
  display: none;
704
704
  }
705
-
706
- /* dummy comment to trigger theme publishing */