@apify/docs-theme 1.0.39 → 1.0.41

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.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/theme.js +33 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/docs-theme",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
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
  }
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,34 @@ ${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.writeFileSync(`${p}/changelog.md`, markdown);
47
+ });
48
+ }
49
+
50
+ function copyChangelogFromRoot(paths) {
51
+ const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
52
+
53
+ for (const docsPath of paths) {
54
+ if (fs.existsSync(path.join(docsPath, 'changelog.md')) && fs.statSync(
55
+ path.join(docsPath, 'changelog.md')).mtime >= fs.statSync(changelogPath).mtime) continue;
56
+ fs.copyFileSync(changelogPath, path.join(docsPath, 'changelog.md'));
57
+ updateChangelog(path.join(docsPath, 'changelog.md'));
58
+ }
59
+ }
60
+
32
61
  function theme(
33
62
  context,
34
63
  options,
@@ -46,9 +75,7 @@ function theme(
46
75
  },
47
76
  async loadContent() {
48
77
  try {
49
- const changelogPath = findPathInParentOrThrow('CHANGELOG.md');
50
78
  const versioned = findPathInParent('website/versioned_docs');
51
-
52
79
  const pathsToCopyChangelog = [
53
80
  findPathInParentOrThrow('docs'),
54
81
  ...(versioned
@@ -57,12 +84,10 @@ function theme(
57
84
  ),
58
85
  ];
59
86
 
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'));
87
+ if (options.changelogFromRoot) {
88
+ copyChangelogFromRoot(pathsToCopyChangelog);
89
+ } else {
90
+ await copyChangelogFromReleases(pathsToCopyChangelog, `${context.siteConfig.organizationName}/${context.siteConfig.projectName}`);
66
91
  }
67
92
  } catch (e) {
68
93
  console.warn(`Changelog page could not be initialized: ${e.message}`);