@apify/docs-theme 1.0.19 → 1.0.20

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.19",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -17,7 +17,13 @@
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
19
  "@docusaurus/theme-common": "^2.2.0",
20
+ "@vcarl/remark-headings": "^0.1.0",
20
21
  "babel-loader": "^9.1.0",
21
- "prism-react-renderer": "^1.3.5"
22
+ "prism-react-renderer": "^1.3.5",
23
+ "react-markdown": "^8.0.4",
24
+ "remark-parse": "^10.0.1",
25
+ "remark-slug": "^7.0.1",
26
+ "remark-stringify": "^10.0.2",
27
+ "unified": "^10.1.2"
22
28
  }
23
29
  }
@@ -0,0 +1,90 @@
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
+
15
+ export default function ChangelogPage({ changelog }) {
16
+ const windowSize = useWindowSize();
17
+
18
+ const { data: { headings: tocRaw } } = unified()
19
+ .use(remarkParse)
20
+ .use(remarkStringify)
21
+ .use(remarkSlug)
22
+ .use(remarkHeadings)
23
+ .processSync(changelog);
24
+
25
+ const toc = tocRaw.map((x) => ({
26
+ value: x.value,
27
+ level: x.depth,
28
+ id: x.data.id,
29
+ }));
30
+
31
+ return (windowSize === 'desktop' || windowSize === 'ssr') ? (
32
+ <ChangelogPageDesktop {...{ changelog, toc }} />
33
+ ) : <ChangelogPageMobile {...{ changelog, toc }}/>;
34
+ }
35
+
36
+ function ChangelogPageDesktop({ changelog, toc }) {
37
+ const { siteConfig } = useDocusaurusContext();
38
+
39
+ return (
40
+ <Layout
41
+ title={`Changelog · ${siteConfig.tagline}`}
42
+ description={siteConfig.tagline}
43
+ >
44
+ <div className='col apiItemCol' style={{ margin: 'auto', display: 'flex', flexDirection: 'row' }}>
45
+ <div style={{ flexDirection: 'column' }} className='theme-doc-markdown markdown'>
46
+ <ReactMarkdown
47
+ remarkPlugins={[remarkSlug]}
48
+ >
49
+ {changelog}
50
+ </ReactMarkdown>
51
+ </div>
52
+ <div style={{ width: '50%' }}>
53
+ <TOC
54
+ {...{
55
+ toc,
56
+ minHeadingLevel: 1,
57
+ }}
58
+ />
59
+ </div>
60
+ </div>
61
+ </Layout>
62
+ );
63
+ }
64
+
65
+ function ChangelogPageMobile({ changelog, toc }) {
66
+ const { siteConfig } = useDocusaurusContext();
67
+
68
+ return (
69
+ <Layout
70
+ title={`Changelog · ${siteConfig.tagline}`}
71
+ description={siteConfig.tagline}
72
+ >
73
+ <div className='col apiItemCol' style={{ margin: 'auto' }}>
74
+ <TOCCollapsible
75
+ {...{
76
+ toc,
77
+ minHeadingLevel: 1,
78
+ }}
79
+ />
80
+ <div style={{ flexDirection: 'column' }} className='theme-doc-markdown markdown'>
81
+ <ReactMarkdown
82
+ remarkPlugins={[remarkSlug]}
83
+ >
84
+ {changelog}
85
+ </ReactMarkdown>
86
+ </div>
87
+ </div>
88
+ </Layout>
89
+ );
90
+ }
package/src/theme.js CHANGED
@@ -1,6 +1,22 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+ function findChangelogPath() {
5
+ let changelogPath = __dirname;
6
+ while (changelogPath !== path.join(changelogPath, '..')) {
7
+ const filePath = path.join(changelogPath, 'CHANGELOG.md');
8
+ if (fs.existsSync(filePath)) return filePath;
9
+ changelogPath = path.join(changelogPath, '..');
10
+ }
11
+ const filePath = path.join(changelogPath, 'CHANGELOG.md');
12
+ if (fs.existsSync(filePath)) return filePath;
13
+
14
+ throw new Error('Could not find CHANGELOG.md in any parent directory');
15
+ }
16
+
1
17
  function theme(
2
- context,
3
- options
18
+ context,
19
+ options,
4
20
  ) {
5
21
  return {
6
22
  name: '@apify/docs-theme',
@@ -10,11 +26,30 @@ function theme(
10
26
  getTypeScriptThemePath() {
11
27
  return '../src/theme';
12
28
  },
13
- contentLoaded({ actions }) {
29
+ async contentLoaded({ actions }) {
14
30
  const { setGlobalData } = actions;
15
31
  setGlobalData({
16
32
  options,
17
33
  });
34
+
35
+ try {
36
+ const changelog = fs.readFileSync(findChangelogPath(), 'utf8');
37
+ const dataPath = await actions.createData(
38
+ 'changelog.json',
39
+ JSON.stringify(changelog),
40
+ );
41
+
42
+ actions.addRoute({
43
+ path: path.join(context.baseUrl, 'changelog'),
44
+ component: require.resolve('./pages/ChangelogPage.jsx'),
45
+ exact: true,
46
+ modules: {
47
+ changelog: dataPath,
48
+ },
49
+ });
50
+ } catch (e) {
51
+ console.warn(`Changelog page could not be initialized: ${e.message}`);
52
+ }
18
53
  },
19
54
  getClientModules() {
20
55
  return [
@@ -26,7 +61,7 @@ function theme(
26
61
  module: {
27
62
  rules: [
28
63
  {
29
- test: /(@apify\/|apify-)docs-theme\/src\/theme\/.*?\.jsx?$/,
64
+ test: /(@apify\/|apify-)docs-theme\/src\/(theme|pages)\/.*?\.jsx?$/,
30
65
  use: {
31
66
  loader: 'babel-loader',
32
67
  },