@apify/docs-theme 1.0.146 → 1.0.148
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 +6 -2
- package/src/markdown.js +118 -19
- package/src/theme/custom.css +40 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/docs-theme",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.148",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,11 @@
|
|
|
26
26
|
"babel-loader": "^9.1.3",
|
|
27
27
|
"docusaurus-gtm-plugin": "^0.0.2",
|
|
28
28
|
"postcss-preset-env": "^9.3.0",
|
|
29
|
-
"prism-react-renderer": "^2.0.6"
|
|
29
|
+
"prism-react-renderer": "^2.0.6",
|
|
30
|
+
"remark-parse": "^11.0.0",
|
|
31
|
+
"remark-stringify": "^11.0.0",
|
|
32
|
+
"unified": "^11.0.5",
|
|
33
|
+
"unist-util-visit-parents": "^3.1.1"
|
|
30
34
|
},
|
|
31
35
|
"peerDependencies": {
|
|
32
36
|
"clsx": "*",
|
package/src/markdown.js
CHANGED
|
@@ -1,33 +1,132 @@
|
|
|
1
|
+
const remarkParse = require('remark-parse');
|
|
2
|
+
const remarkStringify = require('remark-stringify');
|
|
3
|
+
const { unified } = require('unified');
|
|
4
|
+
const visitParents = require('unist-util-visit-parents');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Updates the markdown content for better UX and compatibility with Docusaurus v3.
|
|
8
|
+
* @param {string} changelog The markdown content.
|
|
9
|
+
* @returns {string} The updated markdown content.
|
|
10
|
+
*/
|
|
1
11
|
function updateChangelog(changelog) {
|
|
12
|
+
const pipeline = unified()
|
|
13
|
+
.use(remarkParse)
|
|
14
|
+
.use(incrementHeadingLevels)
|
|
15
|
+
.use(prettifyPRLinks)
|
|
16
|
+
.use(linkifyUserTags)
|
|
17
|
+
.use(remarkStringify);
|
|
18
|
+
|
|
19
|
+
changelog = pipeline.processSync(changelog).toString();
|
|
2
20
|
changelog = addFrontmatter(changelog);
|
|
3
|
-
changelog = pushHeadings(changelog);
|
|
4
|
-
changelog = fixUserLinks(changelog);
|
|
5
|
-
changelog = fixPRLinks(changelog);
|
|
6
21
|
changelog = escapeMDXCharacters(changelog);
|
|
7
22
|
return changelog;
|
|
8
23
|
}
|
|
9
24
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Bumps the headings levels in the markdown content. This function increases the depth
|
|
27
|
+
* of all headings in the content by 1. This is useful when the content is included in
|
|
28
|
+
* another markdown file with a higher-level heading.
|
|
29
|
+
* @param {*} tree Remark AST tree.
|
|
30
|
+
* @returns {void} Nothing. This function modifies the tree in place.
|
|
31
|
+
*/
|
|
32
|
+
const incrementHeadingLevels = () => (tree) => {
|
|
33
|
+
visitParents(tree, 'heading', (node) => {
|
|
34
|
+
node.depth += 1;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
18
37
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Links user tags in the markdown content. This function replaces the user tags
|
|
40
|
+
* (e.g. `@username`) with a link to the user's GitHub profile (just like GitHub's UI).
|
|
41
|
+
* @param {*} tree Remark AST tree.
|
|
42
|
+
* @returns {void} Nothing. This function modifies the tree in place.
|
|
43
|
+
*/
|
|
44
|
+
const linkifyUserTags = () => (tree) => {
|
|
45
|
+
visitParents(tree, 'text', (node, parents) => {
|
|
46
|
+
const userTagRegex = /@([a-zA-Z0-9-]+)(\s|$)/g;
|
|
47
|
+
const match = userTagRegex.exec(node.value);
|
|
22
48
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
if (!match) return;
|
|
50
|
+
|
|
51
|
+
const directParent = parents[parents.length - 1];
|
|
52
|
+
const nodeIndexInParent = directParent.children.findIndex((x) => x === node);
|
|
53
|
+
|
|
54
|
+
const username = match[1];
|
|
55
|
+
const ending = match[2] === ' ' ? ' ' : '';
|
|
56
|
+
const before = node.value.slice(0, match.index);
|
|
57
|
+
const after = node.value.slice(userTagRegex.lastIndex);
|
|
26
58
|
|
|
27
|
-
|
|
28
|
-
|
|
59
|
+
const link = {
|
|
60
|
+
type: 'link',
|
|
61
|
+
url: `https://github.com/${username}`,
|
|
62
|
+
children: [{ type: 'text', value: `@${username}` }],
|
|
63
|
+
};
|
|
64
|
+
node.value = before;
|
|
65
|
+
directParent.children.splice(nodeIndexInParent + 1, 0, link);
|
|
66
|
+
|
|
67
|
+
if (!after) return nodeIndexInParent + 2;
|
|
68
|
+
|
|
69
|
+
directParent.children.splice(nodeIndexInParent + 2, 0, { type: 'text', value: `${ending}${after}` });
|
|
70
|
+
return nodeIndexInParent + 3;
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Prettifies PR links in the markdown content. Just like GitHub's UI, this function
|
|
76
|
+
* replaces the full PR URL with a link represented by the PR number (prefixed by a hashtag).
|
|
77
|
+
* @param {*} tree Remark AST tree.
|
|
78
|
+
* @returns {void} Nothing. This function modifies the tree in place.
|
|
79
|
+
*/
|
|
80
|
+
const prettifyPRLinks = () => (tree) => {
|
|
81
|
+
visitParents(tree, 'text', (node, parents) => {
|
|
82
|
+
const prLinkRegex = /https:\/\/github.com\/[^\s]+\/pull\/(\d+)/g;
|
|
83
|
+
const match = prLinkRegex.exec(node.value);
|
|
84
|
+
|
|
85
|
+
if (!match) return;
|
|
86
|
+
|
|
87
|
+
const directParent = parents[parents.length - 1];
|
|
88
|
+
const nodeIndexInParent = directParent.children.findIndex((x) => x === node);
|
|
89
|
+
|
|
90
|
+
const prNumber = match[1];
|
|
91
|
+
const before = node.value.slice(0, match.index);
|
|
92
|
+
const after = node.value.slice(prLinkRegex.lastIndex);
|
|
93
|
+
|
|
94
|
+
const link = {
|
|
95
|
+
type: 'link',
|
|
96
|
+
url: match[0],
|
|
97
|
+
children: [{ type: 'text', value: `#${prNumber}` }],
|
|
98
|
+
};
|
|
99
|
+
node.value = before;
|
|
100
|
+
|
|
101
|
+
directParent.children.splice(nodeIndexInParent + 1, 0, link);
|
|
102
|
+
if (!after) return nodeIndexInParent + 1;
|
|
103
|
+
|
|
104
|
+
directParent.children.splice(nodeIndexInParent + 2, 0, { type: 'text', value: after });
|
|
105
|
+
return nodeIndexInParent + 2;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Adds frontmatter to the markdown content.
|
|
111
|
+
* @param {string} changelog The markdown content.
|
|
112
|
+
* @param {string} title The frontmatter title.
|
|
113
|
+
* @returns {string} The markdown content with frontmatter.
|
|
114
|
+
*/
|
|
115
|
+
function addFrontmatter(changelog, title = 'Changelog') {
|
|
116
|
+
return `---
|
|
117
|
+
title: ${title}
|
|
118
|
+
sidebar_label: ${title}
|
|
119
|
+
toc_max_heading_level: 3
|
|
120
|
+
---
|
|
121
|
+
${changelog}`;
|
|
29
122
|
}
|
|
30
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Escapes the MDX-related characters in the markdown content.
|
|
126
|
+
* This is required by Docusaurus v3 and its dependencies (see the v3 [migration guide](https://docusaurus.io/docs/migration/v3#common-mdx-problems)).
|
|
127
|
+
* @param {string} changelog The markdown content.
|
|
128
|
+
* @returns {string} The markdown content with escaped MDX characters.
|
|
129
|
+
*/
|
|
31
130
|
function escapeMDXCharacters(changelog) {
|
|
32
131
|
return changelog.replaceAll(/<|>/g, (match) => {
|
|
33
132
|
return match === '<' ? '<' : '>';
|
package/src/theme/custom.css
CHANGED
|
@@ -1709,15 +1709,29 @@ iframe[src*="youtube"] {
|
|
|
1709
1709
|
top: -1.5px;
|
|
1710
1710
|
}
|
|
1711
1711
|
|
|
1712
|
-
.
|
|
1713
|
-
|
|
1712
|
+
.theme-api-markdown .openapi__method-endpoint .badge {
|
|
1713
|
+
border-inline-start-width: 5px;
|
|
1714
|
+
padding: 3px 5px 3px 4px;
|
|
1715
|
+
margin-right: 5px;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
.get > .menu__link::before,
|
|
1719
|
+
.theme-api-markdown .openapi__method-endpoint .badge--primary {
|
|
1714
1720
|
background-color: var(--ifm-color-info-contrast-background);
|
|
1715
1721
|
color: var(--ifm-color-info-contrast-foreground);
|
|
1716
1722
|
border-color: var(--ifm-color-info-dark);
|
|
1717
1723
|
}
|
|
1718
1724
|
|
|
1725
|
+
.get > .menu__link::before {
|
|
1726
|
+
content: 'get';
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1719
1729
|
.post > .menu__link::before {
|
|
1720
1730
|
content: 'post';
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
.post > .menu__link::before,
|
|
1734
|
+
.theme-api-markdown .openapi__method-endpoint .badge--success {
|
|
1721
1735
|
background-color: var(--ifm-color-success-contrast-background);
|
|
1722
1736
|
color: var(--ifm-color-success-contrast-foreground);
|
|
1723
1737
|
border-color: var(--ifm-color-success-dark);
|
|
@@ -1725,6 +1739,10 @@ iframe[src*="youtube"] {
|
|
|
1725
1739
|
|
|
1726
1740
|
.delete > .menu__link::before {
|
|
1727
1741
|
content: 'del';
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
.delete > .menu__link::before,
|
|
1745
|
+
.theme-api-markdown .openapi__method-endpoint .badge--danger {
|
|
1728
1746
|
background-color: var(--ifm-color-danger-contrast-background);
|
|
1729
1747
|
color: var(--ifm-color-danger-contrast-foreground);
|
|
1730
1748
|
border-color: var(--ifm-color-danger-dark);
|
|
@@ -1732,6 +1750,10 @@ iframe[src*="youtube"] {
|
|
|
1732
1750
|
|
|
1733
1751
|
.put > .menu__link::before {
|
|
1734
1752
|
content: 'put';
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
.put > .menu__link::before,
|
|
1756
|
+
.theme-api-markdown .openapi__method-endpoint .badge--info {
|
|
1735
1757
|
background-color: var(--ifm-color-warning-contrast-background);
|
|
1736
1758
|
color: var(--ifm-color-warning-contrast-foreground);
|
|
1737
1759
|
border-color: var(--ifm-color-warning-dark);
|
|
@@ -1739,6 +1761,10 @@ iframe[src*="youtube"] {
|
|
|
1739
1761
|
|
|
1740
1762
|
.patch > .menu__link::before {
|
|
1741
1763
|
content: 'patch';
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
.patch > .menu__link::before,
|
|
1767
|
+
.theme-api-markdown .openapi__method-endpoint .badge--warning {
|
|
1742
1768
|
background-color: var(--ifm-color-success-contrast-background);
|
|
1743
1769
|
color: var(--ifm-color-success-contrast-foreground);
|
|
1744
1770
|
border-color: var(--ifm-color-success-dark);
|
|
@@ -1746,6 +1772,12 @@ iframe[src*="youtube"] {
|
|
|
1746
1772
|
|
|
1747
1773
|
.head > .menu__link::before {
|
|
1748
1774
|
content: 'head';
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
.head > .menu__link::before,
|
|
1778
|
+
.event > .menu__link::before,
|
|
1779
|
+
.schema > .menu__link::before,
|
|
1780
|
+
.theme-api-markdown .openapi__method-endpoint .badge--secondary {
|
|
1749
1781
|
background-color: var(--ifm-color-secondary-contrast-background);
|
|
1750
1782
|
color: var(--ifm-color-secondary-contrast-foreground);
|
|
1751
1783
|
border-color: var(--ifm-color-secondary-dark);
|
|
@@ -1753,13 +1785,10 @@ iframe[src*="youtube"] {
|
|
|
1753
1785
|
|
|
1754
1786
|
.event > .menu__link::before {
|
|
1755
1787
|
content: 'event';
|
|
1756
|
-
background-color: var(--ifm-color-secondary-contrast-background);
|
|
1757
|
-
color: var(--ifm-color-secondary-contrast-foreground);
|
|
1758
|
-
border-color: var(--ifm-color-secondary-dark);
|
|
1759
1788
|
}
|
|
1760
1789
|
|
|
1761
|
-
.
|
|
1762
|
-
|
|
1790
|
+
.event > .menu__link::before,
|
|
1791
|
+
.theme-api-markdown .openapi__method-endpoint .badge--secondary {
|
|
1763
1792
|
background-color: var(--ifm-color-secondary-contrast-background);
|
|
1764
1793
|
color: var(--ifm-color-secondary-contrast-foreground);
|
|
1765
1794
|
border-color: var(--ifm-color-secondary-dark);
|
|
@@ -1770,6 +1799,10 @@ iframe[src*="youtube"] {
|
|
|
1770
1799
|
margin-bottom: calc(var(--ifm-h1-vertical-rhythm-bottom)* var(--ifm-leading)) !important;
|
|
1771
1800
|
}
|
|
1772
1801
|
|
|
1802
|
+
.theme-doc-markdown .openapi-tabs__code-container .openapi-tabs__code-item span {
|
|
1803
|
+
text-transform: none;
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1773
1806
|
@media (max-width: 996px) {
|
|
1774
1807
|
div[class^="navbarSearchContainer"] {
|
|
1775
1808
|
position: static;
|