@apify/docs-theme 1.0.38 → 1.0.40

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.38",
3
+ "version": "1.0.40",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -17,6 +17,7 @@
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
19
  "@docusaurus/theme-common": "^2.2.0",
20
+ "axios": "^1.3.1",
20
21
  "babel-loader": "^9.1.0",
21
22
  "prism-react-renderer": "^1.3.5"
22
23
  }
@@ -667,7 +667,16 @@ aside li.section-header > div > .menu__link {
667
667
  opacity: 0.8;
668
668
  font-size: 1em;
669
669
  font-weight: 700;
670
- margin: 5px 0;
670
+ margin: 0;
671
+ }
672
+
673
+ aside li.section-header.menu__list-item {
674
+ margin-top: 15px;
675
+ margin-bottom: 5px;
676
+ }
677
+
678
+ aside li.section-header.menu__list-item:nth-child(2) {
679
+ margin-top: 5px;
671
680
  }
672
681
 
673
682
  aside li.section-header > .menu__list {
package/src/theme.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
+ const axios = require('axios');
3
4
 
4
5
  function findPathInParent(endPath) {
5
6
  let parentPath = __dirname;
@@ -29,6 +30,36 @@ ${changelog.replaceAll(/\n#[^#]/g, '\n## ')}`;
29
30
  fs.writeFileSync(changelogPath, updated, 'utf-8');
30
31
  }
31
32
 
33
+ async function copyChangelogFromReleases(paths, repo) {
34
+ const response = await axios.get(`https://api.github.com/repos/${repo}/releases`);
35
+ const releases = response.data;
36
+
37
+ let markdown = '';
38
+ releases.forEach((release, i, a) => {
39
+ markdown += release.tag_name && a[i + 1]?.tag_name
40
+ ? `## [${release.name}](https://github.com/${repo}/compare/${a[i + 1].tag_name}...${release.tag_name})\n`
41
+ : `## ${release.name}\n`;
42
+ markdown += `${release.body.replaceAll(/(^#|\n#)/g, '##')}\n`;
43
+ });
44
+
45
+ paths.forEach((p) => {
46
+ fs.writeFile(`${p}/changelog.md`, markdown, (err) => {
47
+ if (err) throw err;
48
+ });
49
+ });
50
+ }
51
+
52
+ function copyChangelogFromRoot(paths) {
53
+ const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
54
+
55
+ for (const docsPath of paths) {
56
+ if (fs.existsSync(path.join(docsPath, 'changelog.md')) && fs.statSync(
57
+ path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime) continue;
58
+ fs.copyFileSync(changelogPath, path.join(docsPath, 'changelog.md'));
59
+ updateChangelog(path.join(docsPath, 'changelog.md'));
60
+ }
61
+ }
62
+
32
63
  function theme(
33
64
  context,
34
65
  options,
@@ -46,9 +77,7 @@ function theme(
46
77
  },
47
78
  async loadContent() {
48
79
  try {
49
- const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
50
80
  const versioned = findPathInParent('website/versioned_docs');
51
-
52
81
  const pathsToCopyChangelog = [
53
82
  findPathInParentOrThrow('docs'),
54
83
  ...(versioned
@@ -57,12 +86,10 @@ function theme(
57
86
  ),
58
87
  ];
59
88
 
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'));
89
+ if (options.changelogFromRoot) {
90
+ copyChangelogFromRoot(pathsToCopyChangelog);
91
+ } else {
92
+ await copyChangelogFromReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
66
93
  }
67
94
  } catch (e) {
68
95
  console.warn(`Changelog page could not be initialized: ${e.message}`);