@apify/docs-theme 1.0.93 → 1.0.95
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 +14 -0
- package/src/roa-loader/index.js +73 -0
- package/src/roa-loader/package.json +15 -0
- package/src/theme/MDXComponents/Code.js +42 -0
- package/src/theme/MDXComponents/Details.js +17 -0
- package/src/theme/MDXComponents/Head.js +16 -0
- package/src/theme/MDXComponents/Heading.js +6 -0
- package/src/theme/MDXComponents/Img/index.js +18 -0
- package/src/theme/MDXComponents/Img/styles.module.css +3 -0
- package/src/theme/MDXComponents/Pre.js +14 -0
- package/src/theme/MDXComponents/Ul/index.js +18 -0
- package/src/theme/MDXComponents/Ul/styles.module.css +7 -0
- package/src/theme/MDXComponents/index.js +32 -0
- package/src/theme/RunnableCodeBlock/RunnableCodeBlock.jsx +44 -0
- package/src/theme/RunnableCodeBlock/RunnableCodeBlock.module.css +33 -0
- package/src/theme/custom.css +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/docs-theme",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.95",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@apify/docs-search-modal": "^1.0.
|
|
22
|
+
"@apify/docs-search-modal": "^1.0.23",
|
|
23
23
|
"@docusaurus/theme-common": "^2.4.1",
|
|
24
24
|
"@stackql/docusaurus-plugin-hubspot": "^1.1.0",
|
|
25
25
|
"axios": "^1.4.0",
|
package/src/config.js
CHANGED
|
@@ -262,6 +262,20 @@ const plugins = [
|
|
|
262
262
|
},
|
|
263
263
|
],
|
|
264
264
|
'@stackql/docusaurus-plugin-hubspot',
|
|
265
|
+
async function runnableCodeBlock() {
|
|
266
|
+
return {
|
|
267
|
+
name: 'runnable-code-block',
|
|
268
|
+
configureWebpack() {
|
|
269
|
+
return {
|
|
270
|
+
resolveLoader: {
|
|
271
|
+
alias: {
|
|
272
|
+
'roa-loader': require.resolve(`${__dirname}/roa-loader/`),
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
},
|
|
265
279
|
];
|
|
266
280
|
|
|
267
281
|
module.exports = {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const { urlToRequest } = require('loader-utils');
|
|
2
|
+
const { inspect } = require('util');
|
|
3
|
+
|
|
4
|
+
const signingUrl = new URL('https://api.apify.com/v2/tools/encode-and-sign');
|
|
5
|
+
signingUrl.searchParams.set('token', process.env.APIFY_SIGNING_TOKEN);
|
|
6
|
+
const queue = [];
|
|
7
|
+
let working = false;
|
|
8
|
+
|
|
9
|
+
async function getHash(source) {
|
|
10
|
+
const memory = source.match(/playwright|puppeteer/i) ? 4096 : 1024;
|
|
11
|
+
const res = await (await fetch(signingUrl, {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
body: JSON.stringify({
|
|
14
|
+
input: JSON.stringify({ code: source }),
|
|
15
|
+
options: {
|
|
16
|
+
build: 'latest',
|
|
17
|
+
contentType: 'application/json; charset=utf-8',
|
|
18
|
+
memory,
|
|
19
|
+
timeout: 180,
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
24
|
+
},
|
|
25
|
+
})).json();
|
|
26
|
+
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
28
|
+
|
|
29
|
+
if (!res.data || !res.data.encoded) {
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.error(`Signing failed:' ${inspect(res.error) || 'Unknown error'}`, res);
|
|
32
|
+
return 'invalid-token';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return res.data.encoded;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function encodeAndSign(source) {
|
|
39
|
+
if (working) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
queue.push(() => {
|
|
42
|
+
return getHash(source).then(resolve, reject);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let res;
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
working = true;
|
|
51
|
+
res = await getHash(source);
|
|
52
|
+
|
|
53
|
+
while (queue.length) {
|
|
54
|
+
await queue.shift()();
|
|
55
|
+
}
|
|
56
|
+
} finally {
|
|
57
|
+
working = false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return res;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = async function (code) {
|
|
64
|
+
if (process.env.CRAWLEE_DOCS_FAST) {
|
|
65
|
+
return { code, hash: 'fast' };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.log(`Signing ${urlToRequest(this.resourcePath)}...`, { working, queue: queue.length });
|
|
70
|
+
const hash = await encodeAndSign(code);
|
|
71
|
+
|
|
72
|
+
return { code, hash };
|
|
73
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "roa-loader",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"loader-utils": "^3.2.1"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { isValidElement } from 'react';
|
|
2
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
3
|
+
|
|
4
|
+
export default function MDXCode(props) {
|
|
5
|
+
const inlineElements = [
|
|
6
|
+
'a',
|
|
7
|
+
'abbr',
|
|
8
|
+
'b',
|
|
9
|
+
'br',
|
|
10
|
+
'button',
|
|
11
|
+
'cite',
|
|
12
|
+
'code',
|
|
13
|
+
'del',
|
|
14
|
+
'dfn',
|
|
15
|
+
'em',
|
|
16
|
+
'i',
|
|
17
|
+
'img',
|
|
18
|
+
'input',
|
|
19
|
+
'ins',
|
|
20
|
+
'kbd',
|
|
21
|
+
'label',
|
|
22
|
+
'object',
|
|
23
|
+
'output',
|
|
24
|
+
'q',
|
|
25
|
+
'ruby',
|
|
26
|
+
's',
|
|
27
|
+
'small',
|
|
28
|
+
'span',
|
|
29
|
+
'strong',
|
|
30
|
+
'sub',
|
|
31
|
+
'sup',
|
|
32
|
+
'time',
|
|
33
|
+
'u',
|
|
34
|
+
'var',
|
|
35
|
+
'wbr',
|
|
36
|
+
];
|
|
37
|
+
const shouldBeInline = React.Children.toArray(props.children).every(
|
|
38
|
+
(el) => (typeof el === 'string' && !el.includes('\n'))
|
|
39
|
+
|| (isValidElement(el) && inlineElements.includes(el.props?.mdxType)),
|
|
40
|
+
);
|
|
41
|
+
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Details from '@theme/Details';
|
|
3
|
+
|
|
4
|
+
export default function MDXDetails(props) {
|
|
5
|
+
const items = React.Children.toArray(props.children);
|
|
6
|
+
// Split summary item from the rest to pass it as a separate prop to the
|
|
7
|
+
// Details theme component
|
|
8
|
+
const summary = items.find(
|
|
9
|
+
(item) => React.isValidElement(item) && item.props?.mdxType === 'summary',
|
|
10
|
+
);
|
|
11
|
+
const children = <>{items.filter((item) => item !== summary)}</>;
|
|
12
|
+
return (
|
|
13
|
+
<Details {...props} summary={summary}>
|
|
14
|
+
{children}
|
|
15
|
+
</Details>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Head from '@docusaurus/Head';
|
|
3
|
+
// MDX elements are wrapped through the MDX pragma. In some cases (notably usage
|
|
4
|
+
// with Head/Helmet) we need to unwrap those elements.
|
|
5
|
+
function unwrapMDXElement(element) {
|
|
6
|
+
if (element.props?.mdxType && element.props.originalType) {
|
|
7
|
+
const { mdxType, originalType, ...newProps } = element.props;
|
|
8
|
+
return React.createElement(element.props.originalType, newProps);
|
|
9
|
+
}
|
|
10
|
+
return element;
|
|
11
|
+
}
|
|
12
|
+
export default function MDXHead(props) {
|
|
13
|
+
const unwrappedChildren = React.Children.map(props.children, (child) => (React.isValidElement(child) ? unwrapMDXElement(child) : child),
|
|
14
|
+
);
|
|
15
|
+
return <Head {...props}>{unwrappedChildren}</Head>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import styles from './styles.module.css';
|
|
5
|
+
|
|
6
|
+
function transformImgClassName(className) {
|
|
7
|
+
return clsx(className, styles.img);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function MDXImg(props) {
|
|
11
|
+
return (
|
|
12
|
+
<img
|
|
13
|
+
loading="lazy"
|
|
14
|
+
{...props}
|
|
15
|
+
className={transformImgClassName(props.className)}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { isValidElement } from 'react';
|
|
2
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
3
|
+
|
|
4
|
+
export default function MDXPre(props) {
|
|
5
|
+
return (
|
|
6
|
+
<CodeBlock
|
|
7
|
+
// If this pre is created by a ``` fenced codeblock, unwrap the children
|
|
8
|
+
{...(isValidElement(props.children)
|
|
9
|
+
&& props.children.props?.originalType === 'code'
|
|
10
|
+
? props.children.props
|
|
11
|
+
: { ...props })}
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import styles from './styles.module.css';
|
|
5
|
+
|
|
6
|
+
function transformUlClassName(className) {
|
|
7
|
+
return clsx(
|
|
8
|
+
className,
|
|
9
|
+
// This class is set globally by GitHub/MDX. We keep the global class, and
|
|
10
|
+
// add another class to get a task list without the default ul styling
|
|
11
|
+
// See https://github.com/syntax-tree/mdast-util-to-hast/issues/28
|
|
12
|
+
className?.includes('contains-task-list') && styles.containsTaskList,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default function MDXUl(props) {
|
|
17
|
+
return <ul {...props} className={transformUlClassName(props.className)}/>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import MDXHead from '@theme/MDXComponents/Head';
|
|
3
|
+
import MDXCode from '@theme/MDXComponents/Code';
|
|
4
|
+
import MDXA from '@theme/MDXComponents/A';
|
|
5
|
+
import MDXPre from '@theme/MDXComponents/Pre';
|
|
6
|
+
import MDXDetails from '@theme/MDXComponents/Details';
|
|
7
|
+
import MDXHeading from '@theme/MDXComponents/Heading';
|
|
8
|
+
import MDXUl from '@theme/MDXComponents/Ul';
|
|
9
|
+
import MDXImg from '@theme/MDXComponents/Img';
|
|
10
|
+
import Admonition from '@theme/Admonition';
|
|
11
|
+
import Mermaid from '@theme/Mermaid';
|
|
12
|
+
import RunnableCodeBlock from '../RunnableCodeBlock/RunnableCodeBlock';
|
|
13
|
+
|
|
14
|
+
const MDXComponents = {
|
|
15
|
+
head: MDXHead,
|
|
16
|
+
code: MDXCode,
|
|
17
|
+
a: MDXA,
|
|
18
|
+
pre: MDXPre,
|
|
19
|
+
details: MDXDetails,
|
|
20
|
+
ul: MDXUl,
|
|
21
|
+
img: MDXImg,
|
|
22
|
+
h1: (props) => <MDXHeading as="h1" {...props} />,
|
|
23
|
+
h2: (props) => <MDXHeading as="h2" {...props} />,
|
|
24
|
+
h3: (props) => <MDXHeading as="h3" {...props} />,
|
|
25
|
+
h4: (props) => <MDXHeading as="h4" {...props} />,
|
|
26
|
+
h5: (props) => <MDXHeading as="h5" {...props} />,
|
|
27
|
+
h6: (props) => <MDXHeading as="h6" {...props} />,
|
|
28
|
+
admonition: Admonition,
|
|
29
|
+
mermaid: Mermaid,
|
|
30
|
+
RunnableCodeBlock,
|
|
31
|
+
};
|
|
32
|
+
export default MDXComponents;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
4
|
+
import Link from '@docusaurus/Link';
|
|
5
|
+
import styles from './RunnableCodeBlock.module.css';
|
|
6
|
+
|
|
7
|
+
const EXAMPLE_RUNNERS = {
|
|
8
|
+
playwright: '6i5QsHBMtm3hKph70',
|
|
9
|
+
puppeteer: '7tWSD8hrYzuc9Lte7',
|
|
10
|
+
cheerio: 'kk67IcZkKSSBTslXI',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const RunnableCodeBlock = ({ children, actor, hash, type, ...props }) => {
|
|
14
|
+
hash = hash ?? children.hash;
|
|
15
|
+
|
|
16
|
+
if (!children.code) {
|
|
17
|
+
throw new Error(`RunnableCodeBlock requires "code" and "hash" props
|
|
18
|
+
Make sure you are importing the code block contents with the roa-loader.`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!hash) {
|
|
22
|
+
return (
|
|
23
|
+
<CodeBlock {...props}>
|
|
24
|
+
{ children.code }
|
|
25
|
+
</CodeBlock>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const href = `https://console.apify.com/actors/${actor ?? EXAMPLE_RUNNERS[type ?? 'playwright']}?runConfig=${hash}&asrc=run_on_apify`;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className={clsx(styles.container, 'runnable-code-block')}>
|
|
33
|
+
<Link href={href} className={styles.button} rel="follow">
|
|
34
|
+
Run on
|
|
35
|
+
<svg width="91" height="25" viewBox="0 0 91 25" fill="none" xmlns="http://www.w3.org/2000/svg" className="apify-logo-light alignMiddle_src-theme-Footer-index-module"><path d="M3.135 2.85A3.409 3.409 0 0 0 .227 6.699l2.016 14.398 8.483-19.304-7.59 1.059Z" fill="#97D700"></path><path d="M23.604 14.847 22.811 3.78a3.414 3.414 0 0 0-3.64-3.154c-.077 0-.153.014-.228.025l-3.274.452 7.192 16.124c.54-.67.805-1.52.743-2.379Z" fill="#71C5E8"></path><path d="M5.336 24.595c.58.066 1.169-.02 1.706-.248l12.35-5.211L13.514 5.97 5.336 24.595Z" fill="#FF9013"></path><path d="M33.83 5.304h3.903l5.448 14.623h-3.494l-1.022-2.994h-5.877l-1.025 2.994h-3.384L33.83 5.304Zm-.177 9.032h4.14l-2-5.994h-.086l-2.054 5.994ZM58.842 5.304h3.302v14.623h-3.302V5.304ZM64.634 5.304h10.71v2.7h-7.4v4.101h5.962v2.632h-5.963v5.186h-3.309V5.303ZM82.116 14.38l-5.498-9.076h3.748l3.428 6.016h.085l3.599-6.016H91l-5.56 9.054v5.569h-3.324v-5.548ZM51.75 5.304h-7.292v14.623h3.3v-4.634h3.993a4.995 4.995 0 1 0 0-9.99Zm-.364 7.417h-3.628V7.875h3.627a2.423 2.423 0 0 1 0 4.846Z" className="apify-logo" fill="#000"></path></svg>
|
|
36
|
+
</Link>
|
|
37
|
+
<CodeBlock {...props} className={clsx(styles.codeBlock, 'code-block', props.title != null ? 'has-title' : 'no-title')}>
|
|
38
|
+
{ children.code }
|
|
39
|
+
</CodeBlock>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default RunnableCodeBlock;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.button {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
padding: 3px 10px;
|
|
4
|
+
position: absolute;
|
|
5
|
+
top: 9px;
|
|
6
|
+
right: 9px;
|
|
7
|
+
z-index: 1;
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
line-height: 28px;
|
|
10
|
+
background: var(--prism-background-color);
|
|
11
|
+
color: var(--prism-color);
|
|
12
|
+
border: 1px solid var(--ifm-color-emphasis-300);
|
|
13
|
+
border-radius: var(--ifm-global-radius);
|
|
14
|
+
opacity: 0.7;
|
|
15
|
+
font-weight: 600;
|
|
16
|
+
width: 155px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.button svg {
|
|
20
|
+
height: 20px;
|
|
21
|
+
position: absolute;
|
|
22
|
+
top: 7.5px;
|
|
23
|
+
right: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.button:hover {
|
|
27
|
+
opacity: 1;
|
|
28
|
+
color: var(--prism-color);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.container {
|
|
32
|
+
position: relative;
|
|
33
|
+
}
|
package/src/theme/custom.css
CHANGED
|
@@ -702,3 +702,22 @@ html[data-theme='dark'] .beta-chip {
|
|
|
702
702
|
a.tsd-anchor[href^="https://undefined"] {
|
|
703
703
|
display: none;
|
|
704
704
|
}
|
|
705
|
+
|
|
706
|
+
.runnable-code-block .code-block.no-title pre + div {
|
|
707
|
+
position: absolute;
|
|
708
|
+
right: 170px;
|
|
709
|
+
line-height: 28px;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
.runnable-code-block .code-block button {
|
|
713
|
+
height: 36px;
|
|
714
|
+
margin-top: 1px;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
.runnable-code-block:hover .code-block button {
|
|
718
|
+
opacity: 0.4;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
html[data-theme='dark'] .runnable-code-block svg .apify-logo {
|
|
722
|
+
fill: #fff;
|
|
723
|
+
}
|