@apify/docs-theme 1.0.23 → 1.0.25

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.23",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -17,15 +17,7 @@
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
19
  "@docusaurus/theme-common": "^2.2.0",
20
- "@vcarl/remark-headings": "^0.1.0",
21
20
  "babel-loader": "^9.1.0",
22
- "highlight.js": "^11.7.0",
23
- "prism-react-renderer": "^1.3.5",
24
- "react-markdown": "^8.0.4",
25
- "rehype-highlight": "^6.0.0",
26
- "remark-parse": "^10.0.1",
27
- "remark-slug": "^7.0.1",
28
- "remark-stringify": "^10.0.2",
29
- "unified": "^10.1.2"
21
+ "prism-react-renderer": "^1.3.5"
30
22
  }
31
23
  }
package/src/theme.js CHANGED
@@ -1,17 +1,32 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
 
4
- function findChangelogPath() {
5
- let changelogPath = __dirname;
6
- while (changelogPath !== path.join(changelogPath, '..')) {
7
- const filePath = path.join(changelogPath, 'CHANGELOG.md');
4
+ function findPathInParent(endPath) {
5
+ let parentPath = __dirname;
6
+ while (parentPath !== path.join(parentPath, '..')) {
7
+ const filePath = path.join(parentPath, endPath);
8
8
  if (fs.existsSync(filePath)) return filePath;
9
- changelogPath = path.join(changelogPath, '..');
9
+ parentPath = path.join(parentPath, '..');
10
10
  }
11
- const filePath = path.join(changelogPath, 'CHANGELOG.md');
11
+ const filePath = path.join(parentPath, endPath);
12
12
  if (fs.existsSync(filePath)) return filePath;
13
13
 
14
- throw new Error('Could not find CHANGELOG.md in any parent directory');
14
+ return false;
15
+ }
16
+
17
+ function findPathInParentOrThrow(endPath) {
18
+ const filePath = findPathInParent(endPath);
19
+ if (!filePath) throw new Error(`Could not find ${endPath} in any parent directory`);
20
+ return filePath;
21
+ }
22
+
23
+ function updateChangelog(changelogPath) {
24
+ const changelog = fs.readFileSync(changelogPath, 'utf-8');
25
+ const updated = `---
26
+ title: Changelog
27
+ ---
28
+ ${changelog.replaceAll(/\n#[^#]/g, '\n## ')}`;
29
+ fs.writeFileSync(changelogPath, updated, 'utf-8');
15
30
  }
16
31
 
17
32
  function theme(
@@ -29,31 +44,36 @@ function theme(
29
44
  getTypeScriptThemePath() {
30
45
  return '../src/theme';
31
46
  },
32
- async contentLoaded({ actions }) {
33
- const { setGlobalData } = actions;
34
- setGlobalData({
35
- options,
36
- });
37
-
47
+ async loadContent() {
38
48
  try {
39
- const changelog = fs.readFileSync(findChangelogPath(), 'utf8');
40
- const dataPath = await actions.createData(
41
- 'changelog.json',
42
- JSON.stringify(changelog),
43
- );
49
+ const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
50
+ const versioned = findPathInParent('website/versioned_docs');
51
+
52
+ const pathsToCopyChangelog = [
53
+ findPathInParentOrThrow('docs'),
54
+ ...(versioned
55
+ ? fs.readdirSync(versioned).map((version) => path.join(versioned, version))
56
+ : []
57
+ ),
58
+ ];
44
59
 
45
- actions.addRoute({
46
- path: path.join(context.baseUrl, 'changelog'),
47
- component: require.resolve('./pages/ChangelogPage.jsx'),
48
- exact: true,
49
- modules: {
50
- changelog: dataPath,
51
- },
52
- });
60
+ for (const docsPath of pathsToCopyChangelog) {
61
+ if (fs.existsSync(path.join(docsPath, 'changelog.md')) && fs.statSync(
62
+ path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime) continue;
63
+ fs.copyFileSync(changelogPath, path.join(docsPath, 'changelog.md'));
64
+ console.log(`copied ${changelogPath} to ${path.join(docsPath, 'changelog.md')}`);
65
+ updateChangelog(path.join(docsPath, 'changelog.md'));
66
+ }
53
67
  } catch (e) {
54
68
  console.warn(`Changelog page could not be initialized: ${e.message}`);
55
69
  }
56
70
  },
71
+ async contentLoaded({ actions }) {
72
+ const { setGlobalData } = actions;
73
+ setGlobalData({
74
+ options,
75
+ });
76
+ },
57
77
  getClientModules() {
58
78
  return [
59
79
  require.resolve('./theme/custom.css'),
@@ -1,101 +0,0 @@
1
- import React from 'react';
2
- import Layout from '@theme/Layout';
3
- import ReactMarkdown from 'react-markdown';
4
- import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
5
- import TOC from '@theme/TOC';
6
- import TOCCollapsible from '@theme/TOCCollapsible';
7
- import { useWindowSize } from '@docusaurus/theme-common';
8
-
9
- import { unified } from 'unified';
10
- import remarkSlug from 'remark-slug';
11
- import remarkParse from 'remark-parse';
12
- import remarkStringify from 'remark-stringify';
13
- import remarkHeadings from '@vcarl/remark-headings';
14
- import rehypeHighlight from 'rehype-highlight';
15
- import dockerfile from 'highlight.js/lib/languages/dockerfile';
16
-
17
- export default function ChangelogPage({ changelog }) {
18
- const windowSize = useWindowSize();
19
-
20
- const { data: { headings: tocRaw } } = unified()
21
- .use(remarkParse)
22
- .use(remarkStringify)
23
- .use(remarkSlug)
24
- .use(remarkHeadings)
25
- .processSync(changelog);
26
-
27
- const toc = tocRaw.map((x) => ({
28
- value: x.value,
29
- level: x.depth,
30
- id: x.data.id,
31
- }));
32
-
33
- return (windowSize === 'desktop' || windowSize === 'ssr') ? (
34
- <ChangelogPageDesktop {...{ changelog, toc }} />
35
- ) : <ChangelogPageMobile {...{ changelog, toc }}/>;
36
- }
37
-
38
- function ChangelogPageDesktop({ changelog, toc }) {
39
- const { siteConfig } = useDocusaurusContext();
40
-
41
- return (
42
- <Layout
43
- title={`Changelog · ${siteConfig.tagline}`}
44
- description={siteConfig.tagline}
45
- >
46
- <div className='docPage docMainContainer' style={{ margin: 'auto' }}>
47
- <div className="row" style={{ flexWrap: 'nowrap', margin: '10px' }}>
48
- <div style={{ flexDirection: 'column', flex: 3 }} className='theme-doc-markdown markdown col--9'>
49
- <ReactMarkdown
50
- remarkPlugins={[remarkSlug]}
51
- rehypePlugins={[
52
- [rehypeHighlight,
53
- {
54
- languages: { dockerfile },
55
- ignoreMissing: true,
56
- },
57
- ]]}
58
- >
59
- {changelog}
60
- </ReactMarkdown>
61
- </div>
62
- <div style={{ flex: 1 }} className="col--3">
63
- <TOC
64
- {...{
65
- toc,
66
- minHeadingLevel: 1,
67
- }}
68
- />
69
- </div>
70
- </div>
71
- </div>
72
- </Layout>
73
- );
74
- }
75
-
76
- function ChangelogPageMobile({ changelog, toc }) {
77
- const { siteConfig } = useDocusaurusContext();
78
-
79
- return (
80
- <Layout
81
- title={`Changelog · ${siteConfig.tagline}`}
82
- description={siteConfig.tagline}
83
- >
84
- <div className='col apiItemCol' >
85
- <TOCCollapsible
86
- {...{
87
- toc,
88
- minHeadingLevel: 1,
89
- }}
90
- />
91
- <div style={{ flexDirection: 'column' }} className='theme-doc-markdown markdown'>
92
- <ReactMarkdown
93
- remarkPlugins={[remarkSlug]}
94
- >
95
- {changelog}
96
- </ReactMarkdown>
97
- </div>
98
- </div>
99
- </Layout>
100
- );
101
- }