@apify/docs-theme 1.0.22 → 1.0.24

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.22",
3
+ "version": "1.0.24",
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,19 +1,28 @@
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 findPathToParent(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
14
  throw new Error('Could not find CHANGELOG.md in any parent directory');
15
15
  }
16
16
 
17
+ function updateChangelog(changelogPath) {
18
+ const changelog = fs.readFileSync(changelogPath, 'utf-8');
19
+ const updated = `---
20
+ title: Changelog
21
+ ---
22
+ ${changelog.replaceAll(/\n#[^#]/g, '\n## ')}`;
23
+ fs.writeFileSync(changelogPath, updated, 'utf-8');
24
+ }
25
+
17
26
  function theme(
18
27
  context,
19
28
  options,
@@ -29,30 +38,24 @@ function theme(
29
38
  getTypeScriptThemePath() {
30
39
  return '../src/theme';
31
40
  },
41
+ async loadContent() {
42
+ try {
43
+ const docsPath = findPathToParent('docs');
44
+ const changelogPath = findPathToParent('CHANGELOG.md');
45
+ if (fs.existsSync(path.join(docsPath, 'changelog.md') || fs.statSync(
46
+ path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime,
47
+ )) return;
48
+ fs.copyFileSync(changelogPath, path.join(docsPath, 'changelog.md'));
49
+ updateChangelog(path.join(docsPath, 'changelog.md'));
50
+ } catch (e) {
51
+ console.warn(`Changelog page could not be initialized: ${e.message}`);
52
+ }
53
+ },
32
54
  async contentLoaded({ actions }) {
33
55
  const { setGlobalData } = actions;
34
56
  setGlobalData({
35
57
  options,
36
58
  });
37
-
38
- try {
39
- const changelog = fs.readFileSync(findChangelogPath(), 'utf8');
40
- const dataPath = await actions.createData(
41
- 'changelog.json',
42
- JSON.stringify(changelog),
43
- );
44
-
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
- });
53
- } catch (e) {
54
- console.warn(`Changelog page could not be initialized: ${e.message}`);
55
- }
56
59
  },
57
60
  getClientModules() {
58
61
  return [
@@ -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' }}>
48
- <div style={{ flexDirection: 'column' }} 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 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' style={{ margin: 'auto' }}>
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
- }