@apify/docs-theme 1.0.91 → 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 +2 -2
- package/src/config.js +4 -6
- package/src/theme/SearchBar/index.js +39 -182
- package/src/theme/SearchPage/index.js +2 -2
- package/src/theme/custom.css +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/docs-theme",
|
|
3
|
-
"version": "1.0.
|
|
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
|
@@ -140,8 +140,8 @@ const themeConfig = ({
|
|
|
140
140
|
},
|
|
141
141
|
prism: {
|
|
142
142
|
defaultLanguage: 'typescript',
|
|
143
|
-
theme: require('prism-react-renderer
|
|
144
|
-
darkTheme: require('prism-react-renderer
|
|
143
|
+
theme: require('prism-react-renderer').themes.github,
|
|
144
|
+
darkTheme: require('prism-react-renderer').themes.dracula,
|
|
145
145
|
additionalLanguages: ['docker', 'log', 'php'],
|
|
146
146
|
},
|
|
147
147
|
// this needs to be absolute link otherwise it gets resolved wrongly in project docs
|
|
@@ -241,10 +241,8 @@ const themeConfig = ({
|
|
|
241
241
|
},
|
|
242
242
|
algolia: {
|
|
243
243
|
appId: 'N8EOCSBQGH',
|
|
244
|
-
apiKey: '
|
|
245
|
-
indexName: '
|
|
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
|
|
2
|
-
|
|
3
|
-
import
|
|
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 {
|
|
11
|
-
import
|
|
5
|
+
import { useLocation, useHistory } from '@docusaurus/router';
|
|
6
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
import RouterLink from '@docusaurus/Link';
|
|
14
9
|
|
|
15
|
-
|
|
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
|
|
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
|
-
|
|
32
|
-
|
|
29
|
+
|
|
30
|
+
if (matchesCurrentInstance(props.href, siteConfig.baseUrl)) {
|
|
31
|
+
return <RouterLink {...props}>
|
|
33
32
|
{props.children}
|
|
34
|
-
</
|
|
33
|
+
</RouterLink>;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
return <a {...props}>{props.children}</a>;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
function
|
|
41
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
<
|
|
165
|
-
{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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 {
|
|
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
|
-
<
|
|
389
|
+
<Link href={url} dangerouslySetInnerHTML={{ __html: title }}/>
|
|
390
390
|
</h2>
|
|
391
391
|
|
|
392
392
|
{breadcrumbs.length > 0 && (
|